cancel
Showing results for 
Search instead for 
Did you mean: 

How to write to the SRAM2 memory on STM32L476?

anio1491
Associate II
Posted on March 10, 2017 at 09:54

Hello, How do I write a variable to the SRAM2 on an STM32L476 ? I am putting the uC in the Standby mode and I am preserving the SRAM2 memory, but I cannot manage to write to it. I am trying like this:

&sharpdefine VAR_LOC ((volatile uint8_t *)(0x10000000))

volatile uint8_t *pVar = VAR_LOC;

(*pVar)++;

Do I need to active some clock for the SRAM2 memory?

Thanks! Any information is helpful.

#stm32l4 #sram2 #standbymode
3 REPLIES 3
S.Ma
Principal
Posted on March 10, 2017 at 10:25

In your project file there is a linker file which describe the various memory sections.

Find which name is for SRAM2 and then dig in the #pragma of your compiler to tell at compile time that the following variables are to be put in the corresponding section.

This is toolchain dependent.

If there is a Cube example, then it should be easy.

Here for illustrative purpose, an IAR linker configuration file: (icf file)

/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile='$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml' */

/*-Specials-*/

define symbol __ICFEDIT_intvec_start__ = 0x08000000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;

define symbol __ICFEDIT_region_ROM_end__ = 0x080FFFFF;

define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;

define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF;

define symbol __ICFEDIT_region_CCMRAM_start__ = 0x10000000;

define symbol __ICFEDIT_region_CCMRAM_end__ = 0x1000FFFF;

/*-Sizes-*/

define symbol __ICFEDIT_size_cstack__ = 0x800;

define symbol __ICFEDIT_size_heap__ = 0x400;

/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;

define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__];

define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__];

define region CCMRAM_region = mem:[from __ICFEDIT_region_CCMRAM_start__ to __ICFEDIT_region_CCMRAM_end__];

define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { };

define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { };

initialize by copy { readwrite };

do not initialize { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place in ROM_region { readonly };

place in RAM_region { readwrite,

block CSTACK, block HEAP };
Posted on March 10, 2017 at 10:32

https://community.st.com/0D70X000006SVVLSA4

 
anio1491
Associate II
Posted on March 16, 2017 at 16:16

Thanks for all the answers!

I will answer my own question:

No, you do not need to manually start any clock for the SRAM. I was just reading back the variable in the wrong way.