The Cortex-M1 processor from ARM can be debugged using a JTAG (Joint Test Action Group) debugger. JTAG provides a standard way to connect debugging tools to the processor and gain visibility into the running code. A JTAG debugger is an invaluable tool for firmware engineers working with Cortex-M1 as it allows stepping through code, setting breakpoints, and examining memory and registers.
Understanding JTAG Interface
The Cortex-M1 processor includes an embedded trace macrocell (ETM) which implements a JTAG interface. This provides a 4-pin TAP (Test Access Port) interface for connecting a JTAG debugger. The pins are:
- TCK – Test Clock
- TMS – Test Mode Select
- TDI – Test Data In
- TDO – Test Data Out
These pins provide the basic serial interface for communicating between the debugger and the processor. The ETM includes instruction trace buffers and export capabilities over this JTAG interface to enable advanced debugging.
Connecting JTAG Hardware
To connect a JTAG debugger to your Cortex-M1 hardware, you will need:
- Cortex-M1 development board or target hardware
- JTAG debugger device with 20-pin connector
- 20-pin adapter or cable to connect debugger to target
The JTAG connector on the target hardware should bring out the 4 TAP pins plus power, ground, and reset signals. The adapter or cable connects between this target JTAG header and the debugger device. It maps the debugger connector pins to the corresponding pins on the target.
Common JTAG debuggers like Segger J-Link include a 20-pin connector. Adapters are available to convert this to various target connectors. For example, you may need a 20-pin to 10-pin adapter to interface with a Cortex-M1 development board.
Configuring JTAG Software
With the hardware connected, the JTAG debugger software also needs to be set up and configured. This involves:
- Installing debugger software (e.g. J-Link) on your host computer
- Connecting and identifying the JTAG debugger hardware
- Selecting the Cortex-M1 target processor
- Configuring target interface speed
The JTAG speed is an important setting, and should match the maximum TCK frequency supported by the target Cortex-M1 chip and hardware design. For the Cortex-M1 this is typically between 1 MHz and 10 MHz.
Connecting with Debugger Software
With hardware set up and software configured, the next step is connecting them together. The basic steps are:
- Power up JTAG debugger and connect to host computer
- Power up target Cortex-M1 board
- Connect from debugger software to debugger hardware
- The debugger should now detect and connect to the target processor
This process establishes the physical JTAG connections and enables communication between the debugger and processor.
Debugging Capabilities
Once connected, the JTAG debugger unlocks a number of powerful debugging capabilities including:
- Registers – View and modify core and peripheral registers
- Memory – Read and write data and variables in memory
- Breakpoints – Pause execution at specific lines of code
- Stepping – Step through code line-by-line
- Watchpoints – Pause when memory addresses are accessed
- Trace – Capture execution trace for offline analysis
This provides extensive visibility into program execution and makes debugging issues much easier compared to using printf-style debugging alone.
Debugging Code
With JTAG set up, you can start interacting with live code on the target Cortex-M1. Useful techniques include:
- Stepping through initialization code to identify issues
- Setting breakpoints in key functions and examining variables
- Watching peripheral registers to see hardware interactions
- Checking stack pointer to identify overflow issues
- Tracing through interrupt handlers to analyze latency
JTAG debugging provides a powerful window into program execution that can quickly shed light on bugs. It’s an essential tool for firmware engineers working with Cortex-M1 or other ARM chips.
Going Further with JTAG
The core JTAG functionality provides enormous benefits for debugging Cortex-M1 code. Additional features can further augment its capabilities:
- RTOS Awareness – Debuggers with OS awareness make multithreading bugs easier to spot.
- Profiling – Performance profiling shows how much time is spent in each function.
- Power Measurements – Built-in power data reveals power consumption issues.
- Trace Buffer – On-chip trace buffers capture extensive execution traces.
Upgrading to an advanced JTAG debugger unlocks these additional capabilities for Cortex-M1 and provides even deeper insight into program behavior.
Conclusion
Connecting a JTAG debugger provides invaluable visibility and control when working with Cortex-M1 processors. Following the steps to set up hardware, configure software, and connect provides access to a wide range of debugging features unavailable otherwise. JTAG is a game-changer for firmware engineers developing with Cortex-M1 that enables finding and fixing bugs much faster.