From a68ef65bc4f260678a53ba3992d041abdab780fb Mon Sep 17 00:00:00 2001 From: Audun Korneliussen Date: Tue, 14 Jan 2020 15:34:34 +0100 Subject: [PATCH] drivers: uart: Enable rx byte counting timer only in active power state Nrfx_uarte uses a hardware timer/counter to count received bytes. Keeping this timer enabled increases power consumption for some SoCs. This change disables the timer when an inactive power state is set. Signed-off-by: Audun Korneliussen --- drivers/serial/uart_nrfx_uarte.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index ab7dce2ec51..78b72c828e5 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -1266,6 +1266,9 @@ static void uarte_nrfx_set_power_state(struct device *dev, u32_t new_state) uarte_nrfx_pins_enable(dev, true); nrf_uarte_enable(uarte); #ifdef CONFIG_UART_ASYNC_API + if (hw_rx_counting_enabled(get_dev_data(dev))) { + nrfx_timer_enable(&get_dev_config(dev)->timer); + } if (get_dev_data(dev)->async) { return; } @@ -1287,6 +1290,9 @@ static void uarte_nrfx_set_power_state(struct device *dev, u32_t new_state) * only sent after each RX if async UART API is used. */ #ifdef CONFIG_UART_ASYNC_API + if (hw_rx_counting_enabled(get_dev_data(dev))) { + nrfx_timer_disable(&get_dev_config(dev)->timer); + } if (get_dev_data(dev)->async) { nrf_uarte_disable(uarte); uarte_nrfx_pins_enable(dev, false);