Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

nrf_libuarte_async: Safe to call nrf_libuarte_async_tx from TX_COMPLETE callback?

nRF52840, SDK17.0.2, SD140 v7.2.0

We're migrating from RTT to UARTE for our device-to-host logging, and I'm using nrf_libuarte_async.

When an asynchronous TX completes, my callback is called from an IRQ context with the value NRF_LIBUARTE_ASYNC_EVT_TX_DONE.

Is it safe to call nrf_libuarte_async_tx to send the next chunk of data, immediately from inside this IRQ callback? Or do I have to use something like app_sched to schedule the TX when the MCU is back in thread mode, after the ISR has returned?

Thanks,

Charles

  • Hi Charles,

    When an asynchronous TX completes, my callback is called from an IRQ context with the value NRF_LIBUARTE_ASYNC_EVT_TX_DONE.

    I understand that here you are describing how the libUARTE library works, and not your own implementation, is that right?
    I will answer with this assumption.

    As you can see through examining the implementation of nrf_libuarte_async_tx(), it is essentially non-blocking, simply setup the buffer, the necessary tasks and events, PPI for EasyDMA, and then return.
    Thus, it could be safe to call nrf_libuarte_async_tx() from your nrf_libuarte_async_evt_handler_t.

    However, I still recommend you defer the call to the application context, whether in the main() while loop via a flag, or in an event via the app scheduler. I believe this is generally the safer approach, when you don't have any strict timing requirements.

    Best regards,

    Hieu

Related