Skip to main content
Evan .1
Associate III
Apr 29, 2020 12:20 PM UTC
Question

low lever driver backup sram example

Is there an LL example to enable the backup ram.

This doesn't work:

   // Enable PWR clock

   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);

   // Enable Backup ram clock

   LL_APB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_BKPSRAM);

   LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_RTCAPB);

   // Enable backup ram regulator

   LL_PWR_EnableBkUpAccess();

   LL_PWR_EnableBkUpRegulator();

   while (LL_PWR_IsActiveFlag_BRR() == 0);

   *(__IO uint32_t *) (BKPSRAM_BASE ) = 0x5A5A5A5A;

I can't find in the documentation what I forgot.

Thanks.

This topic has been closed for replies.

26 replies

berendi
Principal
Apr 29, 2020 12:45 PM UTC

It depends on the STM32 series.

Evan .1
Evan .1Author
Associate III
Apr 29, 2020 12:46 PM UTC

STM32F7

waclawek.jan
Super User
Apr 29, 2020 9:58 PM UTC

Read out the related registers and check the related bits, to find out whether your code does what you think it does.

JW

berendi
Principal
Apr 30, 2020 6:19 AM UTC

It does not look right:

LL_APB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_BKPSRAM);

Always check the actual registers against the reference manual.

waclawek.jan
Super User
Apr 30, 2020 1:00 PM UTC

Nice catch!

:dolphin:

JW

Evan .1
Evan .1Author
Associate III
Apr 30, 2020 6:47 AM UTC

Ok thanks. This solve the problem.

Evan .1
Evan .1Author
Associate III
Apr 30, 2020 7:51 AM UTC

unfortunately the data is lost after a power cycle.

When unplugged I got 3V at the capacitor at Vbat. So Vbat has power.

Do I have to configure my ld file or something?

Thanks.

edit: Reading RTC registers works correctly after a power cycle but backup sram works not.

berendi
Principal
Apr 30, 2020 12:27 PM UTC

Check the Battery backup domain section in the reference manual. The order of initialization in your code looks like somewhat different from the one recommended in the reference manual.

Consider replacing the LL function calls with CMSIS style register accesses, e.g.

// instead of LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
RCC->APB1ENR |= RCC_APB1ENR_PWREN;

so that it becomes easier to follow what your code exactly does.

waclawek.jan
Super User
Apr 30, 2020 1:02 PM UTC

... and check the registers again...

Also, if you use some prechewed startup code, check if that does not explicitly clear the backup memory.

You don't have cache switched on on the backup memory area, do you?

Run LSE/RTC and check if after powerdown it's running.

Measure VBAT *directly* on the pin, against VDDA *pin* (I am aiming at incorrect layout and/or soldering/bad joints problems).

JW

Adam Santamaria
Visitor II
Apr 30, 2020 2:57 PM UTC

Hello,

I don't know which product you are using precisely.

But the STM32CubeF7 package proposes the Example RTC_Tamper with the following purpose: "Configuration of the RTC HAL API to write/read data to/from RTC Backup registers."

You can download the package here:

https://my.st.com/content/my_st_com/en/products/embedded-software/mcu-mpu-embedded-software/stm32-embedded-software/stm32cube-mcu-mpu-packages/stm32cubef7.html

It is available for the boards STM32756G_EVAL, STM32F769I_EVAL, STM32F746ZG-Nucleo but there should be no problem to adapt it for your F7.

The example path is for example STM32Cube_FW_F7_V1.16.0\Projects\STM32756G_EVAL\Examples\RTC\RTC_Tamper

Hope it will help.

Adam S.

Evan .1
Evan .1Author
Associate III
May 1, 2020 7:30 AM UTC

I'm using the Nucleo-F676ZI

                          LL_PWR_EnableBkUpAccess();

                          LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR1, 10);

Power Cycle:

uint32_t data1 = LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);

works fine. So this that is not the problem and the backup supply and regulator works correctly.

   LL_PWR_EnableBkUpAccess();

   for(i=0;i<10;i++)

   {

      *(__IO uint8_t *) (BKPSRAM_BASE+ i) = i;

   }

   SCB_CleanDCache_by_Addr ((uint32_t *)BKPSRAM_BASE, BKPSRAM_SIZE);

In memory browser I see the memory is correctly written. After a reset cycle I can read the data correct back.

Only after a power cycle all the data is lost.

I excluded CPU_CACHE_Enable from my program. I use the default LL driver STM32F767ZITX_FLASH.ld and initialization functions.

So some detailed information how to use the Backup ram or a backup ram example should be nice.

Thanks!

waclawek.jan
Super User
May 1, 2020 8:30 AM UTC

> In memory browser I see the memory is correctly written.

On what address?

JW

> I'm using the Nucleo-F676ZI

A new model, yummy! ;)