From 5a41aa2614afe57e023b1c058021791f5544394a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 8 Apr 2024 17:21:42 +0200 Subject: [PATCH] drivers: serial: uart_nrfx_uarte2: Prevent TX in suspend mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not transmit if the device is in suspend mode. Signed-off-by: Krzysztof Chruściński --- drivers/serial/uart_nrfx_uarte2.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/serial/uart_nrfx_uarte2.c b/drivers/serial/uart_nrfx_uarte2.c index f052c1fb742..c76e2e05af3 100644 --- a/drivers/serial/uart_nrfx_uarte2.c +++ b/drivers/serial/uart_nrfx_uarte2.c @@ -385,6 +385,15 @@ static int api_tx(const struct device *dev, const uint8_t *buf, size_t len, int3 nrfx_err_t err; bool hwfc; +#if CONFIG_PM_DEVICE + enum pm_device_state state; + + (void)pm_device_state_get(dev, &state); + if (state != PM_DEVICE_STATE_ACTIVE) { + return -ECANCELED; + } +#endif + #if CONFIG_UART_USE_RUNTIME_CONFIGURE hwfc = data->uart_config.flow_ctrl == UART_CFG_FLOW_CTRL_RTS_CTS; #else @@ -575,6 +584,15 @@ static void api_poll_out(const struct device *dev, unsigned char out_char) const nrfx_uarte_t *nrfx_dev = get_nrfx_dev(dev); nrfx_err_t err; +#if CONFIG_PM_DEVICE + enum pm_device_state state; + + (void)pm_device_state_get(dev, &state); + if (state != PM_DEVICE_STATE_ACTIVE) { + return; + } +#endif + do { /* When runtime PM is used we cannot use early return because then * we have no information when UART is actually done with the