From 282bc783b1178ac1a0471984db02f71fc09adc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Tue, 23 Apr 2024 11:43:00 +0200 Subject: [PATCH] drivers: serial: uart_nrfx_uarte: Fix interrupt driven TX only mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When interrupt driven instance is using only TX then low power mode is automatically enabled and then TXSTOPPED interrupt is disabled in idle so uarte_nrfx_irq_tx_ready_complete() was returning wrong value. Adding a dedicate flag which holds information is user enabled TX interrupt. Signed-off-by: Krzysztof Chruściński --- drivers/serial/uart_nrfx_uarte.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/serial/uart_nrfx_uarte.c b/drivers/serial/uart_nrfx_uarte.c index 315b7f6a916..b53d55479b9 100644 --- a/drivers/serial/uart_nrfx_uarte.c +++ b/drivers/serial/uart_nrfx_uarte.c @@ -143,6 +143,7 @@ struct uarte_nrfx_int_driven { uint8_t *tx_buffer; uint16_t tx_buff_size; volatile bool disable_tx_irq; + bool tx_irq_enabled; #ifdef CONFIG_PM_DEVICE bool rx_irq_enabled; #endif @@ -1593,6 +1594,7 @@ static void uarte_nrfx_irq_tx_enable(const struct device *dev) unsigned int key = irq_lock(); data->int_driven->disable_tx_irq = false; + data->int_driven->tx_irq_enabled = true; nrf_uarte_int_enable(uarte, NRF_UARTE_INT_TXSTOPPED_MASK); irq_unlock(key); @@ -1604,6 +1606,7 @@ static void uarte_nrfx_irq_tx_disable(const struct device *dev) struct uarte_nrfx_data *data = dev->data; /* TX IRQ will be disabled after current transmission is finished */ data->int_driven->disable_tx_irq = true; + data->int_driven->tx_irq_enabled = false; } /** Interrupt driven transfer ready function */ @@ -1617,10 +1620,8 @@ static int uarte_nrfx_irq_tx_ready_complete(const struct device *dev) * enabled, otherwise this function would always return true no matter * what would be the source of interrupt. */ - bool ready = !data->int_driven->disable_tx_irq && - nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED) && - nrf_uarte_int_enable_check(uarte, - NRF_UARTE_INT_TXSTOPPED_MASK); + bool ready = data->int_driven->tx_irq_enabled && + nrf_uarte_event_check(uarte, NRF_UARTE_EVENT_TXSTOPPED); if (ready) { data->int_driven->fifo_fill_lock = 0;