The Cortex-M1 processor from ARM is a popular 32-bit RISC CPU that is widely used in embedded systems. It combines microcontroller features with DSP capabilities, making it well-suited for real-time applications. To aid in development and debugging of Cortex-M1 based systems, Segger Microcontroller offers the ULINK2 debugger.
Using the ULINK2 debugger with the Cortex-M1 processor enables halting code execution, stepping through code line-by-line, setting breakpoints, and examining variable values and memory contents. This helps significantly in identifying bugs, troubleshooting crashes, and optimizing performance. The ULINK2 connects to the Cortex-M1 via its built-in debug interface and JTAG/SWD protocols.
Required Hardware
To debug Cortex-M1 with ULINK2, you will need:
- Cortex-M1 development board or target system
- ULINK2 debugger probe
- 10-pin Cortex debug connector on target board
- USB cable to connect ULINK2 to host PC
The target Cortex-M1 system requires a standard 10-pin debug connector exposed, which provides access to the SWD and JTAG interface signals. The ULINK2 connects to this debug connector via its 20-pin adapter. Ensure the target system and ULINK2 are powered on and connected to the PC via USB.
Configuring Debug Interface
Upon connecting the ULINK2 you may need to configure it for the appropriate debug interface – JTAG or SWD. The Cortex-M1 supports both options. This is done in the debugger config settings. JTAG provides more debug capability compared to SWD but requires more pins. SWD uses only 2 pins but has some limitations in halting debug modes.
To configure the ULINK2 debugger interface:
- Open the ULINK2 Control Panel on the host PC
- Go to the Connection tab
- Select the appropriate Target Device eg. Cortex-M1
- Choose the Debug Port (SWD or JTAG)
- Click OK to save settings
The ULINK2 firmware and target interface drivers will be set up. The ULINK2 LED should now indicate it is ready to connect.
Connecting with Debug Software
To actually control debugging via ULINK2, dedicated software is required on the PC side. Segger provides the Ozone Debugger and J-Link GDB Server applications for this purpose. Ozone provides a full GUI environment while the GDB Server enables using GDB for debugging.
Once the ULINK2 is configured, connect to it via Ozone or GDB Server. Ozone will automatically detect and connect to the debugging probe. For GDB Server, the connection command is: $JLinkGDBServer -IF SWD -device Cortex-M1
This enables GDB to connect and interface with the ULINK2 probe. The debugging software is now ready to start debugging the target Cortex-M1 system.
Halting and Resuming Code Execution
The primary debugging task is being able to halt program execution on the target device so you can examine the current device state. ULINK2 provides multiple ways to halt execution:
- Halt Button – Click the Halt button in the debug GUI
- Pause Button – Click the Pause button to halt at next instruction
- Breakpoints – Set a breakpoint in code to halt at that line
- Watchpoints – Halt when watchpoint variable value changes
To resume execution after halting, use the corresponding Resume or Continue button in the debugger UI. Execution will restart until the next breakpoint or manual halt.
Stepping Through Code
Once halted, you can step through code line-by-line using Step Into, Over and Out commands in the debugger. This is useful for analyzing program flow and debugging specific sections of code. ULINK2 supports:
- Step In – Step into function calls
- Step Over – Skip over functions
- Step Out – Step out of current function
Click the corresponding buttons in the debugger GUI to perform these steps. You can also step using GDB commands like step, next, finish etc.
Setting Breakpoints
Breakpoints allow halting execution at specific lines of code without having to manually halt and single-step through each line. This saves a lot of time when debugging longer code. To set a breakpoint using ULINK2:
- Navigate to the desired line in the code window
- Right click and select Set Breakpoint
- Or click the Breakpoint button in the GUI
When the program counter reaches this line, execution will halt. Breakpoints can be removed by right clicking on them and selecting Remove Breakpoint.
Watching Variables
Examining variable values during debugging provides insight into program operation. With ULINK2 you can watch variables to track their values in real-time.
- Right click on the variable and choose Add to Watch
- Or click the Add Watch button and enter variable name
The variable will be added to the Watch window. Its value will be displayed and updated at each breakpoint.
Memory Viewing and Modification
The ULINK2 debugger allows viewing and modifying target device memory through its GUI windows. This allows examining memory contents during code execution.
- The Memory tab shows target memory contents
- You can edit values by double clicking and entering new value
- Use caution when modifying memory as it can crash the system
This enables inspecting variables without requiring source code changes or recompilation.
Loading Code to Target
Newly compiled code can be loaded directly to the target device through the debugger. This avoids having to rerun any flashing/programming steps.
- Click the Download button in the debugger UI
- Select the new binary file
- The code will be loaded to the target system memory
This enables quickly testing code changes without reflashing chips. Ensure the target has enough memory for the new code.
Debugging from IDEs
The ULINK2 debugger can also be used directly from IDEs like Eclipse, IAR, uVision, etc. This allows debugging code within the IDE environment. To use with IDEs:
- Install ULINK2 plugin/extensions in the IDE
- Configure the project debug settings for ULINK2
- Connect ULINK2 probe to the target system
- Build, load and debug project from IDE itself
Using ULINK2 from the IDE provides a streamlined debugging experience with quick access to all variables, breakpoints and memory views.
Debugging RTOS Based Systems
For real-time OS based systems using Cortex-M1, ULINK2 provides RTOS-aware debugging. This enables viewing RTOS specific debug information like:
- Task list with states
- Task stack usage
- Kernel object values
- Interrupt debugging
To enable this, configure RTOS awareness in ULINK2 debugger settings and select the appropriate RTOS. This will decode RTOS API calls and provide additional visibility.
Troubleshooting Issues
Some common issues faced while debugging Cortex-M1 with ULINK2:
- Ensure ULINK2 firmware is up to date using ULINK2 Control Panel
- Double check target debug interface configuration is set correctly
- Check connections from ULINK2 to target board and to host PC
- Try restarting debug session or power cycling devices
- Verify sufficient power to target board
ULINK2 LEDs also provide helpful clues on debugger state. Refer to its user manual for troubleshooting steps.
Conclusion
The ULINK2 debugger provides comprehensive and intuitive debugging capabilities for Cortex-M1 processors. Its support for breakpoints, step execution, variable watching, memory access, IDE integration and RTOS debugging enable accelerated development and trouble-free debugging. Proper configuration is key to utilizing its full capabilities.