This tutorial will take less than 15 minutes.
Never lose a BLE connection when debugging your applications again! This technique will also be useful for any application using the PWM peripheral and many others as well!
Monitor mode debugging can only be done on nRF52 series devices. It will not work with nRF51 series devices as Cortex-M0 doesn't support this feature.
In the last blog post https://devzone.nordicsemi.com/blogs/825/segger-embedded-studio-cross-platform-ide-w-no-cod/ we introduced you to SEGGER Embedded Studio (SES). Please at least skim through that post if you haven't already.
In this post we will explore SES more and experiment with Monitor Mode Debugging (MMD) https://www.segger.com/monitor-mode-debugging.html. MMD allows you to halt the CPU while debugging (breakpoints, pausing execution) but still service interrupts with priority. Some use cases of this are: a BLE application can maintain its connection, a PWM can continue to operate a motor, a sensor can be read and its interrupt cleared so it can continue collecting data, etc... while the CPU is halted in debugging. There are many use cases, but at least most of us have experienced losing BLE connections while debugging and ending up in a hardfault/error handler when we continue code execution.
If you haven't already installed SES please look at the blog linked in the beginning of this post and follow the simple instructions to get it up and running.
Download this zip file, extract it, and open the SES project file. nRF5x-MMD-led-btn-example.zip
Only some very slight modifications are needed to run this example.
This is what your project should look like.
Now under the "Build" tab at the top of the screen select "Build and Debug." Or you can just press the green play button "Start."
Now run the example. Press Button 1 and LED1 will toggle on your board. At the top of main.c you may have to change the pins the led & button are assigned to based on the board you are using. Now pause the execution. Press Button 1 and LED1 will still be toggled! Or set a break point in the while loop and notice the LED still toggles.
Monitor Mode Debugging is supported in SEGGER Embedded Studio, Keil uVision and IAR. A different JLINK_MONITOR_ISR_xxx.s file is needed for Keil and IAR.
We would like to know what you think about monitor mode debugging. Please let us know in the comments and how you would like to use it. A tutorial on using MMD with a BLE application is planned and in the works.
More blog posts on the Toolchain are coming your way. What would you like to see? Some planned posts include: