This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

device lockup by serial write in critical region

Hi,

 In my project, there is a device lock up and I found the problematic point that a debug log using nrf_serial_write() in critical region.

I think it is not a good idea to use debug log in critical region and I suspected if the previous critical region enter disabled irqs and nrf_serial_write would wait for timer forever or trying enter another critical region in nrf_queue_in before exit critical region.

However, I am not sure what exactly causes the lock up.

Could someone explain this?

Thank you.

Parents
  • Hi,

    When you enter a critical region, all peripheral interrupts will be disabled/masked. Most likely, the nrf_serial_write does a blocking wait for some event (transfer completed, timeout, error, etc). If you call this inside the critical region, the interrupts will never fire and the function will never complete.

    If you need to use logging inside the critical region, you may use the NRF_LOG library in deferred mode. This will add the logs to a buffer, and you need to process the buffer in the main loop to send the actual logs on UART.

    Best regards,
    Jørgen

Reply
  • Hi,

    When you enter a critical region, all peripheral interrupts will be disabled/masked. Most likely, the nrf_serial_write does a blocking wait for some event (transfer completed, timeout, error, etc). If you call this inside the critical region, the interrupts will never fire and the function will never complete.

    If you need to use logging inside the critical region, you may use the NRF_LOG library in deferred mode. This will add the logs to a buffer, and you need to process the buffer in the main loop to send the actual logs on UART.

    Best regards,
    Jørgen

Children
No Data
Related