Running a gdb session on nRF51, it is difficult to debug the code beyond the SoftDevice initialization. Then, I have to step through with (gdb)ni, but this is not convenient, and on top of that, system events don't seem to fire up.
I know this question has been raised many times, and I was working my way around it each time, but today, I am faced with stack overflow issues, and not being able to dump the RAM at specific breakpoints is a major pain.
Plus, it makes me look very bad, as my colleague, who is developing the master-side on iOS has no such kind of problem :)
I am aware that gdb is not officially supported by Nordic, so if there is a solution on Keil, just let me know.
Hi, It's not possible to single step while the softdevice is in use as you may know already. That is, you can do it to some extent as explained in this thread. What you can do is to set breakpoints and see if the are reached during program execution. E.g., place a breakpoint in app_error.c->app_error_handler() to see if any of the calls to the softdevice has returned an error code. You can also use trace to log debug data over UART or Segger RTT.
Some suggestions if you suspect stack overflow:
Thanks for the hint. The "RAM painting + breakpoints" seems a valid approach. However, the crux of my problem is I cannot take gdb beyond the SoftDevice init, so I am not able to break, halt, step, etc. Unfortunately, setting PRIMASK doesn't help either.
Does the softdevice init ever return to main context? It will hang in an endless loop within the SD if you've chosen selected the NRF_CLOCK_LFCLKSRC_XTAL_x_PPM enum as the SD will wait for the crystal to start up. LF clock source).
If you are able to share your .out/.elf file with debug symbols I can try to debug it as well and see if I can find some clues (code must work on the nRF51 DK kit).
Indeed the softdevice was initialized with NRF_CLOCK_LFCLKSRC_XTAL_50_PPM. However, changing to other values doesn't make a difference. Breakpoints beyond softdevice_handler_init are not reached. Attached ELF for reference (compiled for a nRF51 board, GPIO are remapped). Which refdesign are you using ?
What is your level of code optimisation? If it is different than 0, try turning it off (to 0). I am also using gdb - it is hard to debug during connections etc, but not impossible.