Default values for variable stored in SRAM

1

We are having some troubles with variables stored in SRAM and default values.

We are working with a STM32F745ZE micro. We had to define a section for SRAM:

/* Specify the memory areas */
MEMORY
{
ITCM_RAM (rx)  : ORIGIN = 0x00000000, LENGTH = 16K   /* +MW+ */
/*RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 319K*/
RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = 64K   /* +MW+ DTCM RAM */
RAM_GEN (xrw)  : ORIGIN = 0x20010000, LENGTH = 255K  /* +MW+ SRAM1 + SRAM2 */

TRACER (xrw)   : ORIGIN = 0x2004FC00, LENGTH = 1K    /* +MW+ TRACER memory space */
FLASH (rx)     : ORIGIN =  0x8000000, LENGTH = 512K
}

(...)

  /* Uninitialized data section */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss secion */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

  /* +MW+ SRAM data section */
  .ram_gen :
  {
    . = ALIGN(4);
    _sram_gen = .;     /* create a global symbol at data start */
    *(.ram_gen)        /* .data sections */
    *(.ram_gen*)       /* .data* sections */

    . = ALIGN(4);
    _eram_gen = .;     /* define a global symbol at data end */
  } >RAM_GEN

We want to assign default values to some varieables. It works fine for variables not stored in SRAM, but it doesn't work for varaibles stored in SRAM:. Example

static Test_Ram_t testRam = { .value = 1 };
static Test_Ram_Value_t testRamValue __attribute__((section(".ram_gen"))) = { .value = 1 };

static void Test_Ram_Task1(void const *pvParameters)
{
    Test_Ram_Printf("Test Ram: START -----------------------------------------------");
    Test_Ram_Printf("Test Ram: Pre value: %d %d", testRam.value, testRamValue.value);

    testRam.value += 10;
    testRamValue.value += 10;

    Test_Ram_Printf("Test Ram: Post value: %d %d", testRam.value, testRamValue.value);

    osDelay(osWaitForever);
}

If we reboot the application 3 times the application output is:

[10:30:25.002]
[10:30:25.004] Test Ram: START -----------------------------------------------
[10:30:25.005] Test Ram: Pre value: 1 1
[10:30:25.005] Test Ram: Post value: 11 11
[10:30:27.599]
[10:30:27.601] Test Ram: START -----------------------------------------------
[10:30:27.603] Test Ram: Pre value: 1 11
[10:30:27.604] Test Ram: Post value: 11 21
[10:30:29.497]
[10:30:29.500] Test Ram: START -----------------------------------------------
[10:30:29.502] Test Ram: Pre value: 1 21
[10:30:29.503] Test Ram: Post value: 11 31

Varaible testRam, stored in RAM, is assigned the default value in every restart, but varaible testRamValue, stored in SRAM, the value is keeped between reboots.

Does anyone know how to force to assign the default value on every reboot?

c
stm32
sections
asked on Stack Overflow Aug 28, 2018 by JMA • edited Aug 28, 2018 by Marco A.

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0