From 0c3fbaa8822f63eab9cd1ad97e82ee726fd63348 Mon Sep 17 00:00:00 2001 From: Ismael Fillonneau Date: Tue, 17 Dec 2019 11:40:32 +0100 Subject: [PATCH] drivers: nrf: avoid UARTE pm infinite loop calling UARTE power management with DEVICE_PM_SUSPEND_STATE then DEVICE_PM_OFF_STATE causes a deadlock in while loop. It waits for an event witch never comes Signed-off-by: Ismael Fillonneau --- drivers/serial/uart_nrfx_uarte.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 5ae9728adb3..ab7dce2ec51 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -1260,6 +1260,7 @@ static void uarte_nrfx_pins_enable(struct device *dev, bool enable) static void uarte_nrfx_set_power_state(struct device *dev, u32_t new_state) { NRF_UARTE_Type *uarte = get_uarte_instance(dev); + struct uarte_nrfx_data *data = get_dev_data(dev); if (new_state == DEVICE_PM_ACTIVE_STATE) { uarte_nrfx_pins_enable(dev, true); @@ -1275,6 +1276,13 @@ static void uarte_nrfx_set_power_state(struct device *dev, u32_t new_state) new_state == DEVICE_PM_SUSPEND_STATE || new_state == DEVICE_PM_OFF_STATE); + /* if pm is already not active, driver will stay indefinitely + * in while loop waiting for event NRF_UARTE_EVENT_RXTO + */ + if (data->pm_state != DEVICE_PM_ACTIVE_STATE) { + return; + } + /* Disabling UART requires stopping RX, but stop RX event is * only sent after each RX if async UART API is used. */