cancel
Showing results for 
Search instead for 
Did you mean: 

Declaring variables in External SRAM

Jim Kaz
Associate II
Posted on September 23, 2016 at 18:33

Hi everyone!  I'm having some difficulty getting variables to be declared in external SRAM.  I'm using a STM32L4.  If I do address casting like the FMC example project for the eval board in the library code I can access the SRAM, but I can't seem to declare a variable to be always there.

Here are the changes I've made to the default STM32L476G linker file:

/* Specify the memory areas */

MEMORY

{

FLASH (rx)      : ORIGIN = 0x8000000, LENGTH = 1024K

RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 96K

SRAM (xrw) : ORIGIN = 0x60000000, LENGTH = 128K

}

And at the end:

/* Add section for external RAM */

  .bssext :

  {

    _sbssext = .;         /* define a global symbol at bssext start */

    __bssext_start__ = _sbssext;

*(.bssext)

    *(.bssext*)    

    

. = ALIGN(4);

_ebssext = .;         /* define a global symbol at bssext end */

    __bssext_end__ = _ebssext;

  } >SRAM AT> RAM

  /* Remove information from the standard libraries */

 /* Unchanged, but included to show where it is in the linker file */

  /DISCARD/ :

  {

    libc.a ( * )

    libm.a ( * )

    libgcc.a ( * )

  }

At the top of one of my files I'm declaring a variable as such:

__attribute__((section(''.bssext''))) uint8_t pExtMemoryTest[32];

This should be putting it into the .bssext section, which should be in SRAM, but the map file says it's still in regular ram.

 .bss._ZL13gs_mainBuffer

                0x20002368      0x200 Debug/CdcRxForwardTask.o

 .bssext        0x20002568       0x20 Debug/DpmBootTask.o

 

                0x20002568                pExtMemoryTest

 .bss._ZN6HwInit14m_nResetReasonE

                0x20002588        0x4 Debug/DpmHwInit.o

                0x20002588                _ZN6HwInit14m_nResetReasonE

It's right in the middle of the .bss section and is clearly in internal RAM.

What am I missing?  Any help would be greatly appreciated, thanks!
1 REPLY 1
Jim Kaz
Associate II
Posted on September 23, 2016 at 18:58

Ok, shockingly easy solution.  Changed it from bssext to extbss and all is well with the world.