Debugging on-chip flash and RAM can be challenging for developers working with Cortex-M1 chips. The ULINK2 debug adapter from Keil provides an effective solution. By connecting ULINK2 to the Cortex-M1 target, developers can access the on-chip flash and RAM for debugging purposes.
Introduction to Cortex-M1 and ULINK2
The Cortex-M1 processor from ARM is a 32-bit RISC CPU optimized for microcontroller applications. It has an efficient 3-stage pipeline and includes features like SysTick timer, NVIC, and debug support. The Cortex-M1 on-chip flash and RAM provide program storage and data memory needed for embedded applications.
ULINK2 is a versatile JTAG/SWD debug adapter from Keil. It connects to the Cortex-M1 JTAG/SWD port and provides a bridge to the host computer running Keil MDK toolkit. ULINK2 supports JTAG and serial wire debugging modes along with flash programming, power measurement, and other advanced features.
Accessing On-Chip Flash Memory
The Cortex-M1 processor includes embedded flash memory for storing code. The size of the on-chip flash varies based on the specific microcontroller model, but is typically in the range of 32KB to 256KB.
ULINK2 provides access to this flash memory using the JTAG or SWD interface. Once connected, the on-chip flash can be read and written by the debugger. Developers can download code to flash, read back flash contents, erase flash sectors, and program flash.
When halted at a breakpoint, the debugger can read flash values. This helps trace code execution. The flash can also be written for testing and firmware updates. Having debug access to flash memory accelerates the development process.
Flash Programming
The ULINK2 adapter facilitates programming of the Cortex-M1 on-chip flash memory. Using the Flash Programming feature in Keil MDK, the flash can be erased and programmed with new code.
The programming process begins by connecting ULINK2 to the target board and launching the Flash Programming dialog. The target flash size and sectors are auto-detected. Code files can then be loaded for programming.
The flash sectors are automatically erased before programming. Finally, the code files are programmed into flash memory. Verification occurs to ensure correct programming. In some cases, flash memory may need to be secured before deployment.
Reading Flash Contents
While debugging Cortex-M1 applications, developers may want to read the current flash values. The debugger memory windows make this easy.
With ULINK2 connected, simply halt the processor at a breakpoint. Open a memory window for the flash memory region. The window will read out the flash contents. Developers can examine the flash values to better understand code execution.
Reading flash contents helps trace problems. For example, determining how code reached a certain function, or identifying where a variable was written. ULINK2 debug access accelerates the process of reading flash memory.
Debugging On-Chip RAM
In addition to flash memory, Cortex-M1 microcontrollers include embedded SRAM for data storage. Typical on-chip SRAM sizes range from 4KB to 64KB for storing variables, stacks, and heap memory.
ULINK2 enables real-time viewing and modification of RAM contents while debugging. This is invaluable for understanding dynamic program behavior and fixing bugs.
Viewing RAM Contents
To view RAM contents, the Cortex-M1 target is halted and a memory window is opened for the RAM region. ULINK2 will read out the current RAM values through the JTAG/SWD interface.
Developers can browse RAM to check variable values, view stack usage, analyze heap allocation, and generally observe how code utilizes memory.Updating RAM Variables
In addition to viewing RAM, ULINK2 allows real-time editing of RAM contents. With the target halted, any RAM variable can be modified through the memory window.
Having the ability to update variables is extremely useful for testing different conditions. Developers can try out edge cases by forcing variable values. They can also initialize data to known states for debugging. Updating RAM accelerates troubleshooting of memory corruption issues.
Monitoring RAM Usage
Excessive stack and heap usage are common sources of embedded bugs. ULINK2 debugging provides insight into memory usage by examining RAM contents.
Stack overflow can be identified by viewing unused stack values or analyzing the stack pointer. Heap fragmentation and leaks are found by looking at heap allocation patterns. Having a real-time view of RAM usage helps optimize memory and prevent crashes.
Advanced Debugging with ULINK2
In addition to basic flash and RAM access, ULINK2 includes advanced tools to aid Cortex-M1 debugging.
Code Trace
The trace capability lets developers record program execution history. After running code, the exact code path and functions called can be reconstructed. Trace is useful for analyzing crashes, hangs, and unexpected code flow.
Logic Analyzer
ULINK2 contains an integrated logic analyzer to monitor Cortex-M1 signals. Any processor pin can be mapped to the logic analyzer for analyzing timing, signals, and peripherals.
Performance Analysis
The ULINK2 adapter can profile code execution to identify performance bottlenecks. Statistics such as function timing and call counts help optimize Cortex-M1 applications.
These advanced tools, combined with flash and RAM access, enable thorough debugging of Cortex-M1 designs using the ULINK2 interface.
Setup and Connection
Using ULINK2 for Cortex-M1 debugging requires just a few simple steps:
- Connect ULINK2 adapter to host computer with USB cable.
- Connect 20-pin JTAG/SWD cable from ULINK2 to Cortex-M1 target board.
- Launch Keil MDK and open project for Cortex-M1 application.
- Select ULINK2 as debug adapter in project options.
- Start debug session – ULINK2 will initialize connection to target.
- Halt CPU and access on-chip flash, RAM in debug views.
ULINK2 automatically handles the target interface configuration. The adapter provides LEDs to indicate status and comes equipped with Keil firmware.
Summary
ULINK2 provides an invaluable window into Cortex-M1 on-chip flash and RAM while debugging. Developers can read/write flash, view RAM contents, program flash memory, and leverage advanced trace tools. By accessing internal Cortex-M1 memory over JTAG/SWD, ULINK2 accelerates debug, testing, and optimization using the Keil MDK toolkit.