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

Pause peripherals when hitting a breakpoint?

Is there a way to pause all peripherals when hitting a breakpoint? In particular, I would like to freeze the RTCs when I hit a breakpoint. My app wakes up once a second, and I pause the code for too long, interrupt on RTC0 never fires when the counter gets around to the set wakeup interval.

  • Not that I know of. If you are trying to find a bug, just check the variables/registers at the breakpoint, and keep moving your breakpoint farther along. You might also explore watchpoints, you can break on a change to a particular memory location. Finally, use assert() liberally.

  • Yes you can do it, but it may be cumbersome, at least it was when I tried to do it in Keil uVision.

    You can stop the RTC by writing to the memory address corresponding to the stop task. For RTC0 this is 0x4000B004 (see here), so you stop RTC0 by writing a '1' to this address. The debugger lets you halt execution, resume execution and write to memory addresses. You can make uVision execute functions when a breakpoint is hit, see here. The debugger will not stop when you execute the function so you have to stop it manually in the function. You do this by setting the system variable _break_ to non-zero. The execution will halt after the function is called. The stop function may look something like this:

    FUNC void stop_rtc0(void)
    {
        _WBYTE(0x4000B004,1);   //stop RTC0
        _break_=1;              //halt debugger
    }
    

    You can also skip using a function and just type this in the command field (see here for more info about debug commands):

    E CHAR 0x4000B004=1, _break_=1
    

    I assume you want to start RTC0 again when you resume code execution. As it seems that the halt command (_break_=1) is executed after the other breakpoint commands, you will have to add a new breakpoint right after where you stopped. In this breakpoint, execute command for starting RTC0 again:

    E CHAR 0x4000B000=1
    

    This is my experience when I tried it using uVision. If someone has a better way of doing it, please comment. If someone know how to do this in other IDEs, please add an answer.

    Monitor mode debugging
    Your problem may also be solved by using Monitor mode debugging. This will allow interrupts with higher priority than the one you specify to run even you stop code execution in the debugger. See this great tutorial (blog) about Monitor Mode debugging.

  • I'm using VisualGDB, but this gives me some ideas on how to about it. Other micros give you the option of freezing or continuing to run peripherals when a breakpoint is hit. That would be nice to have on future NRF5 micros.

Related