AnsweredAssumed Answered

Initialized data in both internal and external RAM

Question asked by Carlo Bramini on Oct 14, 2019
Latest reply on Oct 16, 2019 by Con Verse

Hello,

I'm using an LPC1788 with an SDRAM connected to the external bus and it works fine.

However, I'm facing a problem with initialized data at compile time.

 

Let's think on a piece of code like this one:

 

int a = 1; /* This will be allocated into the internal RAM */
int b = 2 __attribute__((section(".ext_ram"))); /* This will be allocated into the external RAM */

 

 

The two variables 'a' and 'b' are allocated properly, but I have some troubles to find the right way for initializing their values when the firmware starts. Usually, initialized data is set when the entry point is executed, by using a for() cycle, like this piece of code from lpcopen:

 

    /*
     * Copy the initialized data of the ".data" segment
     * from the flash to the are in the ram.
     */

    pSrc  = &_etext;
    pDest = &_data;
    while(pDest < &_edata)
    {
        *pDest++ = *pSrc++;
    }

 

I think that I should duplicate this code also for external memory, but until now I did not get success.

This is my linker script:

 

/*-----  Stack(s) size / heap size are defined here  ---------*/

   stack_size = 2048;

/*------------------------------------------------------------------------*/
             /* LPC1788 */
MEMORY
{
   FLASH (rx)   : ORIGIN = 0x00000000, LENGTH = 0x00080000
   RAM (rw)     : ORIGIN = 0x10000100, LENGTH = 0x00010000 - 0x100 - 32
   USB_RAM (rw) : ORIGIN = 0x20000000, LENGTH = 0x00004000
   ETH_RAM (rw) : ORIGIN = 0x20004000, LENGTH = 0x00004000
   EXT_RAM (rw) : ORIGIN = 0x80000000, LENGTH = 0x00800000
}

ENTRY(ResetHandler)

SECTIONS
{
   .usb_ram (NOLOAD):
   {
     *(.usb_ram)
   } > USB_RAM

   .eth_ram (NOLOAD):
   {
     *(.eth_ram)
   } > ETH_RAM

   .ext_ram :
   {
     *(.ext_ram)
   } > EXT_RAM

   .text :
   {
     _stext = . ;
     *(.reset)                  /* Startup code */
     *(.text)                  /* remaining code */
     *(.rodata)                 /* read-only data (constants) */
     *(.rodata*)
     *(.glue_7)
     *(.glue_7t)
   } > FLASH

   .ARM.exidx : {
     __exidx_start = .;
      *(.ARM.exidx* .gnu.linkonce.armexidx.*)
     __exidx_end = .;
   } > FLASH

   . = ALIGN(4);
   _etext = . ;
   PROVIDE (etext = .);

   /* .data section which is used for initialized data */
   .data : AT (_etext)
   {
     _data = .;
     *(.data)
   } > RAM

   . = ALIGN(4);
   _edata = . ;
   PROVIDE (edata = .);

   /* .bss section which is used for uninitialized data */
   .bss (NOLOAD) :
   {
     __bss_start = . ;
     __bss_start__ = . ;
     *(.bss)
     *(COMMON)
     . = ALIGN(4);
   } > RAM

   . = ALIGN(4);
   __bss_end__ = . ;
   PROVIDE (__bss_end = .);

   .stack_bottom  ALIGN(__bss_end__ , 4) (NOLOAD) :
   {
      __stack__bottom__ = .;
      *(.stack)
   }
   __stack_bottom_end__ = __stack__bottom__  + stack_size ;
   ._estack  ALIGN(__stack_bottom_end__ , 4) (NOLOAD) :
   {
      _estack = .;
      *(.stack)
   }

  _end = . ;
  PROVIDE (end = .);

  /* Stabs debugging sections.  */
  .stab          0 : { *(.stab) }
  .stabstr       0 : { *(.stabstr) }
  .stab.excl     0 : { *(.stab.excl) }
  .stab.exclstr  0 : { *(.stab.exclstr) }
  .stab.index    0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment       0 : { *(.comment) }
  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */

  /* DWARF 1 */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  /* SGI/MIPS DWARF 2 extensions */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
}

 

 

 

I added an .ext_ram section but this surely needs more information added.

Thank you very much for your time.

 

Sincerely.

Outcomes