Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF serial abstraction layer clarification

Can someone please explain the below line mentioned in NRF5 Serial port abstraction layer documentation.

Do not use synchronous API (timeout_ms parameter > 0) in IRQ context. It may lead to a deadlock because the timeout interrupt cannot preempt the current IRQ context.

Link: infocenter.nordicsemi.com/index.jsp

Parents
  • Hi,

    This warning say that you should not use the serial library functions in blocking mode from IRQ context (interrupt handlers), as it can cause deadlocks.

    This functions refered by this warning is nrf_serial_write(), nrf_serial_read(), and nrf_serial_flush(). From the API documentation you can see the description of the timeout_ms parameter:

    timeout_ms Operation timeout, in milliseconds. Pass 0 to operate in non blocking mode.

    The timeout is implemented as a timer and a while loop waiting for the timer to expire or a flag to be set. If the blocking call is made from an interrupt context with higher priority than the serial/timer library, the flag can never be updated, leaving you in a deadlock. It is therefore not recommended to call the blocking functions from IRQ context.

    Best regards,

    Jørgen

Reply
  • Hi,

    This warning say that you should not use the serial library functions in blocking mode from IRQ context (interrupt handlers), as it can cause deadlocks.

    This functions refered by this warning is nrf_serial_write(), nrf_serial_read(), and nrf_serial_flush(). From the API documentation you can see the description of the timeout_ms parameter:

    timeout_ms Operation timeout, in milliseconds. Pass 0 to operate in non blocking mode.

    The timeout is implemented as a timer and a while loop waiting for the timer to expire or a flag to be set. If the blocking call is made from an interrupt context with higher priority than the serial/timer library, the flag can never be updated, leaving you in a deadlock. It is therefore not recommended to call the blocking functions from IRQ context.

    Best regards,

    Jørgen

Children
Related