EmbDev.net

Forum: ARM programming with GCC/GNU tools how can i debug code in ram ?

Author: Max Chen (maxchen)
Posted on:
Attached files:

Hi,I try to debug my code in ram.but after searching on the web for a
long time,I still can't figure it out.I use Sourcery G++ Lite Edition
,openocd and  jlink on ubuntu 10.04.for the flash run,it work well.the
MCU is STM32F103VE

I download the start up code and link script from the web.I modify the
link script to something like this:

    .isr_vector :
    {
    . = ALIGN(4);
        KEEP(*(.isr_vector))            /* Startup code */
    . = ALIGN(4);
    } >RAM

    /* for some STRx devices, the beginning of the startup code is
stored in the .flashtext section, which goes to FLASH */
    .flashtext :
    {
    . = ALIGN(4);
        *(.flashtext)            /* Startup code */
    . = ALIGN(4);
    } >RAM

    /* the program code is stored in the .text section, which goes to
Flash */
    .text :
    {
      . = ALIGN(4);

        *(.text .text.* .gnu.linkonce.t.*)
      *(.plt)
      *(.gnu.warning)
      *(.glue_7t) *(.glue_7) *(.vfp11_veneer)

      *(.ARM.extab* .gnu.linkonce.armextab.*)
      *(.gcc_except_table)

    } >RAM

please help.

and sorry for my poor English.
Author: Martin Thomas (mthomas) (Moderator)
Posted on:

So far I have not tested "RAM-debugging" with STM32 controllers so these
are just some hints which might be helpful:

- In the Makefile there is a variable RUN_MODE which is set to FLASH_RUN
in the file in the archiv. Set it to RAM_RUN. The stetting is later used
to select the linker-script. Look into the output of make all and verify
that the *_RAM linker-script is used. The content of RUN_MODE is also
passed as a preprocessor definition so #ifdef RAM_RUN or #ifdef
FLASH_RUN can be used in the source-code.

- SystemInit_ExtMemCtl() is called in the reset handler, usually
SystemInit should do. Initialisation of the external memory interface
can be enabled by a preprocessor define (see system_stm32*.c). Since
initialization of the external memory interface can be enabled in
SystemInit() it might be better to call SystemInit in the reset-handler.
This may not cause a problem but it might be better to use the method
intended by the STM library-developers until everything starts up as
expected.

- I did not check every line in the linker-script for RAM but it looks
o.k.

- Since the .data output-section is already at the correct location it
is o.k. to wrap the first for-loop (copy data seg initializers...) with
#ifdef FLASH_RUN/#endif

- MSP is already set in the reset-handler-function so there should be no
need to add something for this.

- Since the interrupt-vector-table is also in RAM and not at the default
location the the beginning of the flash-memory area the location has do
be configured in SCB's VTOR register before any interrupt is enabled.
See function NVIC_SetVectorTable in misc.c. Call could be done in the
reset-handler.

- Since the core should start run the code in RAM, the
debuggering-software should set the program-counter (PC) to the
reset-handler's address. This can be done with OpenOCD just before a
"resume".
Author: Max Chen (maxchen)
Posted on:

Thank you very much for you reply
I will try it later and report what I get.

Thanks again.
Author: Max Chen (maxchen)
Posted on:

Thank you Martin

By following you instruction ,I finaly made it work !

1.Modify the link script to put all the sections in ram

2.Set RUN_MODE to RAM_RUN in Makefile and make sure the linker link with
the ram-run-link-script

3.Change the Reset_Handler to:

void Reset_Handler(void)
{
/* SCB's VTOR register to the correct interrupt-vector-table address in ram */
    #ifdef RAM_RUN
    NVIC_SetVectorTable(NVIC_VectTab_RAM,0X0);
    #endif

/* FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is 
  required, then adjust the Register Addresses */
  SystemInit_ExtMemCtl();

  /* restore original stack pointer */
  asm(" LDR r0, =_estack");
  asm(" MSR msp, r0");
  
  /* Initialize data and bss */
   __Init_Data(); 

  /* Call the application's entry point.*/
  main();
}

4.Change __Init_Data to:
void __Init_Data(void)
{
  unsigned long *pulSrc, *pulDest;

  #ifdef FLASH_RUN
  /* Copy the data segment initializers from flash to SRAM */
  pulSrc = &_sidata;

  for(pulDest = &_sdata; pulDest < &_edata; )
  {
    *(pulDest++) = *(pulSrc++);
  }
  #endif

  /* Zero fill the bss segment. */
  for(pulDest = &_sbss; pulDest < &_ebss; )
  {
    *(pulDest++) = 0;
  }
}

5.Use the following openocd command:
reset
halt
load_image PATH_TO_IMAGE 0x0 TYPE_OF_IMAGE
reg pc 0x20000004
resume

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.


webmaster@embdev.netContactAdvertising on EmbDev.net