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

main thread no longer running

Hi,Nordic and all great guys,

I am a new developer for NRF51822, and quite unfortunately ,we have a complex application to develop. We need to run code in the main thread ,and we don`t even find examples about it in the SDK(there only have sd_app_evt_wait() at the end of main with a while(1) loop). We now meet a problem, under certain conditions ,the main thread is no longer running,while all interrupts seem work fine.

In order to pinpoint the bug, we simplified our program ,which only ran with main thread(lowest priority level), BLE interrupt(interrupt priority level 0 or level 2), APP timer with SWI0 and RTC1 interrupt(we change them to level 3), and UART prints(without interrupt).

The main flow is like this:

  1. there is a global(static) message queue , the timer will send a message to it every 500ms.

  2. there is a while(1) loop in the main thread, scanning the message queue, if valid message is in the queue, process it and loop back to the beginning of while(1).

  3. We added UART prints to show process of the message, so everytime of the loop ,there will be a lot of print output to show different status. and it also means the UART print would run very frequently because the loop time is tiny.

  4. We also have timer to check whether the while(1) loop is still running (main is not freezed),if not ,we will turn on the buzzer to indicate that, and we also can see that there is no more prints about the message queue showing up.

  5. We use softdevice_handler.c to handle the BLE connection events, we also add UART prints in the SWI2_IRQHandler() and intern_softdevice_events_execute().

Now weird thing comes, if we connect to the MCU while the main thread is scanning the message queue, producing large amount of UART print, then the UART print in SWI2_IRQHandler() will have large chance to break the print in main thread, if that happened, the main thread is no longer running ,even the BLE interrupt is finished and returned. After that we still can have BLE connection , app timer still run normally, which means all interrupts are good to trigger, but the main thread is just no longer running. if we remove all UART prints or just remove the UART prints in the BLE interrupt, this would not happen, the buzzer indicating the main thread not running is not triggered .We actually don`t know what cause this ,just can suspect the UART useage before and after the BLE interrupt may cause some kind of conflict. We are stuck here for several days ,it becomes a big problem for us since we have to use main thread to achieve our application, so any help will be appreciated. By the way ,we are using S110 V7.0, SDK V6.1. If any further information is needed or anything unclear, please also let me know. Thanx in advance.

Related