ARM Technical Support Knowledge Articles


Applies to: ULINK USB-JTAG Debugger


Information in this article applies to:


The memory window of ┬ÁVision3 shows wrong values for the Flash memory when I start debugging with ULINK on Atmel AT91SAM7A2 (or other Atmel devices with REMAP feature).


The ARM core cannot stop the CPU exactly at reset. Some Atmel devices have an extended reset logic that allows this, but it is not the case on the Atmel AT91SAM7A2. When ULINK gets control over the CPU, the PC value is set to 0 (to simulate a REMAP) however the REMAP cannot be undone.

The REMAP feature on Atmel devices exchanges RAM and Flash areas. When the remapping is done before ULINK can stop the device, you will see swapped memory areas in the debugger and the CPU may not behave correctly.


The solution to this problem is a small modification in the STARTUP.S file that waits until the debugger is connected. This can be done by adding the instructions in the conditional assembly section DEBUG_STOP to the startup file SAM7x.S:

// Copy Exception Vectors to Internal RAM and Remap Memory
//  (when Interrupt Vectors are in RAM)
                MC_BASE EQU  0xFFFFFF00  /* MC Base Address */
                MC_RCR  EQU  0x00        /* MC_RCR Offset */

; add these instructions

                MOV     R0,#1
WAIT4DEBUG:     CMP     R0,#0
                BNE     WAIT4DEBUG
; end

                ADR     R8, Vectors         ; Source
                LDR     R9, =RAM_BASE       ; Destination

These instructions are enabled under Project - Options - Asm with Set: DEBUG_STOP. When you now run this program it waits at WAIT4DEBUG until register R0 is set manually to 0 using a debug command. Under uVision you may enter:

R0 = 0

This allows you to debug the REMAP sequence on the Amtel devices.

Automate Debugger Startup

The uVision Debugger startup can be automated by adding the following commands to a Debugger Initialization file (specify it under Options for Target -> Debug).

func void CPUReset (void)  {
  exec ("Reset");           // Reset CPU
  exec ("_sleep_ (100)");   // Wait 100ms until stopped
  exec ("G, WAIT4DEBUG");   // Run just before REMAP
  exec ("_sleep_ (100)");   // Wait 100ms until stopped
  exec ("R0 = 0");          // Clear CPU Register R0
  exec ("G, main");         // Run til main

// Toolbox button for CPU reset
define button "Reset CPU", "CPUReset ()"

_sleep_ (100)
R0 = 0
_sleep_ (100)
G, main

This Debugger Initialization file adds even a Toolbox button that allows you to reset the CPU and run until the main function.


Article last edited on: 2010-03-24 13:06:28

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential