Keil Logo


Information in this article applies to:

  • Keil Development Suite for ARM any Version


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 µVision you may enter:

R0 = 0

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

Automate Debugger Startup

The µVision 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.



The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, March 24, 2010

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.