AnsweredAssumed Answered

Copy data to SDRAM at startup

Question asked by hoevener.jan on Oct 3, 2016
Latest reply on Oct 8, 2016 by Clive One
Hello,
I am using the STM32F746 Discovery Board with STM32 System Workbench IDE. I know SDRAM is a volatile memory but I want copy a picture to the external SDRAM at startup because it's too big for the internal Flash.
What I did fist is to initialize the SystemClock and the SDRAM in the SystemInit(). I checked it an it's working fine because I can use it without any more initialisation in the main().
My next step was to define an additional memory block in the LinkerScript.

MEMORY
{
FLASH (rx)        : ORIGIN = 0x8000000, LENGTH = 1024K
RAM (xrw)        : ORIGIN = 0x20000000, LENGTH = 320K
SDRAM (xrw)        : ORIGIN = 0xC0000000, LENGTH = 8M
}

after this I added a section as followed. I copied that idea from the .data section which is copied from the Flash in the internal RAM.

SECTIONS
{
...
/* used by the startup to initialize data */
  _sidata_sdram = LOADADDR(.sdram_data);
 
  /* Initialized data sections goes into RAM, load LMA copy after code */
  .sdram_data :
  {
    . = ALIGN(4);
    _sdata_sdram = .;  /* create a global symbol at data start */
    *(.sdram_data)     /* .sdram_data sections */
    *(.sdram_data*)    /* .sdram_data* sections */

    . = ALIGN(4);
    _edata_sdram = .;  /* define a global symbol at data end */
  } >SDRAM AT> FLASH
...
}

In the assembly written startup file I added .words for the defined addresses in the LinkerScript and a copy routine like for the .data. The routine I added after the SystemInit() that the SysClk and SDRAM are already initialized.

/* Call the clock system initialization function.*/
  bl  SystemInit

/* Copy the data segment initializers from flash to SRAM */
  movs  r1, #0
  b  LoopCopyDataSdram

CopyDataSdram:
  ldr  r3, =_sidata_sdram
  ldr  r3, [r3, r1]
  str  r3, [r0, r1]
  adds  r1, r1, #4

LoopCopyDataSdram:
  ldr  r0, =_sdata_sdram
  ldr  r3, =_edata_sdram
  adds  r2, r0, r1
  cmp  r2, r3
  bcc  CopyDataSdram

If I now define a global variable as followed I can't see that it's working.

__attribute__((__section__(".sdram_data"))) uint8_t picture1[] = {
       ...
        0x00, 0xFF, 0xFF,
       ...
};

Does anybody know what I am making wrong? I try to find a solution since a week but nothing is working. :( Or does anyboy have a small programm wich is doing that correctly?

Outcomes