Monitor-mode debugging
Monitor-mode debugging describes the capability of the CPU to maintain essential functionality while being debugged.
Overview
Monitor-mode debugging describes the ability of a CPU to maintain essential functionality while being debugged. This is particularly important in systems where hardware components such as motors must continue running or communication links need to remain active.
For most common CPUs, the default approach is halt-mode debugging. In this mode, the CPU halts on a debug request, causing the user application and, depending on the architecture, also peripheral components to stop executing.
In certain applications and environments, however, it is necessary for parts of the application to continue running while the CPU is in debug mode and another part of the software is being debugged.
This is where monitor-mode debugging provides a significant improvement.
Use cases
There are several scenarios in which monitor-mode debugging is the only viable way to debug an application.

Motor control with PWM
In applications that include motor control using pulse width modulation, halting the CPU also stops the PWM units. This can leave the motor control logic in an undefined or potentially unsafe state. Monitor-mode debugging allows the PWM-related code to continue running while the rest of the application is halted and debugged.

Bluetooth communication
In applications that rely on Bluetooth communication, halting the entire application would cause the connection to drop. Monitor-mode debugging allows Bluetooth keep-alive interrupts to continue running, maintaining low-level communication while the remainder of the application is halted and debugged.

Ethernet networking
In Ethernet-based applications, halting the CPU can cause the IP stack to become unresponsive, preventing packets from being received, including keep-alive traffic. Monitor-mode debugging enables developers to analyze such systems while maintaining essential network functionality.

CAN bus communication
In applications that use CAN bus communication, halting the CPU would result in lost messages. When using monitor-mode debugging, the CPU can continue to handle incoming CAN messages while the main application remains halted.
How monitor-mode debugging works
In contrast to halt-mode debugging, in monitor-mode debugging the target CPU does not halt on a debug request but takes a debug interrupt instead and jumps to a specific debug interrupt handler which then handles the communication with J-Link and also some low-level application maintenance that may be needed to be done while the application is halted. So technically, the CPU is still running and executing the code while the application itself is halted, allowing it to still handle some interrupts as well as some synchronous maintenance operation that can be done within the monitor code.
The monitor code consists of the following parts:
- A generic monitor that handles communication with J-Link. This part is delivered by SEGGER and should not be modified by the user.
- A custom monitor part providing some functions that can be filled in by the user. SEGGER delivers a template for this part.
The custom monitor part provides the following functions where the user can add functionality/maintenance which needs to be done in debug mode:
- JLINK_MONITOR_OnExit(): Called once just before leaving the monitor and restarting the target application.
- JLINK_MONITOR_OnEnter(): Called once just before entering the monitor. Target application is already stopped at this point.
- JLINK_MONITOR_OnPoll(): Called periodically while the CPU is in debug mode.
The monitor modules simply need to be compiled, linked, and downloaded with the application. For limitations on what can be done in the different functions of the custom monitor part, please refer to the J-Link User Guide.
Supported CPUs
Whether monitor-mode debugging can be supported for a specific device depends on whether the CPU architecture defines monitor-mode support or not. In case of doubt if a specific CPU is or can be supported, please get in touch with support@segger.com. Currently, the following CPUs are supported for monitor-mode debugging:
- Cortex-M3
- Cortex-M4
- Cortex-M7
- Cortex-M23
- Cortex-M33
- Cortex-M55
- Cortex-M85
The debugger / IDE side
On the debugger / IDE side, no changes are required to support monitor-mode debugging. The IDE will recognize no difference between traditional halt-mode debugging and monitor-mode debugging.
For the best debug experience, we recommend using Embedded Studio or Ozone.
Considerations/limitations
There are certain considerations and limitations to be aware of when using monitor mode debugging. For example, the monitor itself and the periodic actions it performs cannot be debugged. A detailed description of all considerations and limitations can be found in the J-Link User Guide.
Monitor for other IDEs
Since the monitor code runs directly on the target and is implemented in assembly language, it differs slightly between compiler environments. The monitor has been ported to the following compilers and IDEs so far:
- SEGGER Embedded Studio (GCC)
- Any GCC based environment (GCC)
- IAR EWARM (IAR ARM compiler)
- Keil MDK-ARM (ARM compiler)
In SEGGER Embedded Studio, monitor mode is available through the sample project linked below. Monitor ports for compilers and IDEs other than SEGGER Embedded Studio are available on request via the J-Link download page.
Example project
In the following, a example project for SEGGER Embedded Studio can be downloaded that demonstrates:
- How to use monitor mode in Embedded Studio
- How to have a specific interrupt keep firing while the main application is halted and the monitor is active
For more detailed explanations how to bring the project up and running on a specific hardware, please refer to the readme that comes with the project.
FAQ
I am using SEGGER RTT. Can it be used together with monitor-mode debugging?
Yes. SEGGER RTT works seamlessly with monitor mode debugging. No changes are required on either the debugger or the application side.
I am using a CPU with a specific core. Can monitor-mode debugging be supported?
If the CPU core is not listed above, please contact support@segger.com to check if monitor-mode debugging support can be added for this CPU.
Do all J-Links support monitor-mode debugging?
Monitor-mode debugging is available on all current J-Links, including J-Link PLUS, J-Link Ultra, and J-Link Pro, and is also supported by J-Trace. J-Link BASE and on-board J-Links support monitor mode in evaluation mode only.
