How to debug from RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to debug from RAM

305 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by roger_lu on Thu May 05 18:01:10 MST 2011
I'm using LPC-Link and MCB1700 board.
With Keil MDK, i know how to debug on RAM or download to FLASH.
But for lpcxpresso, as a beginner, 
how to debug on RAM (load image to RAM without progromming to flash)?
Is there some sample projects which has two targets, one is for debug
on RAM, another is for programming to flash?
Where to set the RO and RW base address?
What's the main difference between debug and release target in the existing sample project?
thanks
0 Kudos
1 Reply

265 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri May 06 04:17:13 MST 2011
Roger,

the main difference between debug and release is that in debug there is no code optimization (-O0) being done while the release does use code optimization (-O2). Optimization may save a lot of memory space, my current application is 28 kB in debug and 13 kB in the release configuration
And there are also the defines "DEBUG" and "NDEBUG" that are defined for debug or release config.

If you want to debug from RAM then you have to make sure that both your code and variables fit in RAM so you are limited in the size of the application you can test (on an LPC1343 you have 8 kB RAM available, you may want to use a larger device to debug from RAM).

You can manage your own linker script.
In your project propertiesm go to the C/C++ Build -> Settings section. In the right pane click on MCU Linker -> Target and place a untick the box near "Manage linker script". You can copy or rename the script provided by the LPCXpresso environment - strongly suggested!!! Do not just change the existing scripts but rename them; the LPCXpresso environment may overwrite them ...

The existing linker script contains something like:
SECTIONS
{

    /* MAIN TEXT SECTION */    
    .text : ALIGN(4)
    {
        ...
        ...
    } > MFlash32

    /* MAIN DATA SECTION */

    .data : ALIGN(4)
    {
        ...
        ...
    } > RamLoc8 AT>MFlash32

}
There is a separate file (called something like Project_Release_mem.ld) containing:
MEMORY
{
  /* Define each memory region */
  MFlash32 (rx) : ORIGIN = 0x0, LENGTH = 0x8000 /* 32k */
  RamLoc8 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x2000 /* 8k */

}
  /* Define a symbol for the top of each memory region */
  __top_MFlash32 = 0x0 + 0x8000;
  __top_RamLoc8 = 0x10000000 + 0x2000;


This combination will place all .text sections of your program in the memory region called MFlash32 and all .data sections in RamLoc8.
You can just move all sections (there are more than just the .text sections in the linker file) to RAM but I'm not sure if the startup code is using the __top_MFlash32 or __top_RamLoc8 for some stuff.

To optimize your memory a bit you could remove the need for your .data sections to be copied (normally pre-initialized data is stored both in Flash and in RAM and copied by the startup code) but then you have to reload on every debug run. I'd prefer not to use pre-initialized data if possible at all.

You also have to change the startup code. Your vectors need to be fetched from RAM, not Flash, and maybe some more stuff.

Rob
0 Kudos