application debug with softdevice


After searching in forum, I understood that we cannot debug application with softdevice unless PRIMASK bit is set.

But in my application there is a requirement that to transmit data received from uart to connected devices using RADIO. If I set PRIMASK bit I will not get BLE interrupts. How can I debug my complete application ?

Does anyone have tried to debug application with softdevice?

Regards, Sowmya

  • You are right, when the softdevice is enabled and there is BLE activity then it gets difficult to debug your application. This is because softdevice interrupts are highest priority and when your application somehow masks servicing softdevice interrupt immediately, then when softdevice ISR gets to be serviced (when you unhalt the CPU), softdevice realizes that its real-time requirements have been broken by the breakpoint you set in your application, it will assert immediately and this is unrecoverable fault unless you reset chip.

    I am not sure if there is a better way to do it but this is how i debug code with softdevice. I put a breakpoint in the application and run the debugger until the breakpoint is hit. It is important that you set the PRIMASK to 1 quickly here. Once that is done, you can step debug your application code until you hit a softdevice function (say sd_softdevice_disable). From here debugger wont help you to step. Then you have remove your old breakpoint and set a new breakpoint to the line next to sd_softdevice_disable. and restart the whole procedure again.

    All this pain is not to let the softdevice know that we have halted the CPU. Hope this helps.


    For nRF52, it gets better when you can use the onboard ETM. Read the post here

  • Thanks for the information Aryan. Right now I am doing the same way how you have tested. But I also want to know the functionality of PRIMASK bit. Because after hitting the breakpoint I am setting primask bit and complete ble functionality is stopped.

    Is this how it works or not? As per my understanding, PRIMASK will not allow BLE interrupts, so the advertising will stop. Is this correct?

    Edit: One more thing, if I put a breakpoint in application, and after hitting breakpoint the application is restarting!! Why is this behaviour?

    Regards, Sowmya

  • Setting PRIMASK register to 1 will mask all user configurable interrupts. That means that all BLE activity will stop as softdevice interrupts are user configurable and are stopped from triggering.

    Are you seeing that the device resets as soon as the breakpoint hits? or when you are trying to step(F10 or F11 key for uVision) through your code after the breakpoint hits? It should not reset, it will most probably hardfault and end of in hardfault handler in arm_startup_nrf51.s, and this will happen if you have set the PRIMASK register too late and the softdevice figured out that something went wrong :)

  • I have not set the PRIMASK bit after hitting the breakpoint and for F10 and F5 it is getting reset. I can confirm you that it is not hardfault. I have written an irq handler for hardfault and it is not coming there.

  • Yes if we set PRIMASK bit immediate after hitting breakpoint, application will run smoothly but we cannot debug BLE application. This is a drawback.