How to place an array in backup ram on STM32F4 MCUs?

Hi,

I am trying to place an array in the backup ram so its contents can survive system reboot caused by watchdog.

typedef struct {
    //
} Foo;

Foo foos[40];  

What is the proper way to make sure foos is pointed to BKPSRAM_BASE ?

Thanks in advance.

Hello Li,

The following code should compile. But I have never tried to use the backup SRAM. So I’m curious whether it will work:

    typedef struct
    {
        int i;
        //
    } Foo;

    Foo* foos = (Foo*)BKPSRAM_BASE;

    foos[0].i = 100;

This works, and I will use it.

Another method by editing link script seems reasonable and should work, but I could not get it to work. Compiled bin file will be super bloated and doesn’t fit into flash on MCU.

Here is an example of adding CCM (Core Coupled Memory) for the STM32F407VE (Arch Max) which worked for me. Try to replace CCM/ccm with BKPSRAM/bkpsram and modify the address and length according to the BKPSRAM data. If your target is different then use the corresponding .ld file and add the BKPSRAM related sections.