cancel
Showing results for 
Search instead for 
Did you mean: 

Backup registers are cleared on reset - STM32G474

Martin294
Associate III

Hi all,

I have a STM32G474 and data in backup registers (eg. LL_RTC_BKP_DR0) are cleared after reset or power cycle (3.3 V battery is present!).

Code is generated by CubeMX with LL drivers. I enabled RTC and disabled all tampers.

In the main code, I can write to the registers (and readback or check via debugger/SFR view).

However, if I restart the debugger, press the reset button (with or without debugger connected) or switch of VCC (with VBAT present from a CR2032 battery), backup registers are all 0.

As I understand it, this could be caused by a RTC domain reset or a tamper event. I have neither, as far as I can tell. What could be wrong? Is there an example for this?

Regards, Martin

5 REPLIES 5

> As I understand it, this could be caused by a RTC domain reset [....] I have neither,

But you've said:

> Code is generated by CubeMX with LL drivers.

So, isn't there a RTC domain reset in the generated code?

In debugger, try to place a data breakpoint on the respective register in RCC through which the RTC domain is reset.

JW

Martin294
Associate III

Nice idea... tried to put an SWV trace on the BKP_DR0 register (0x40002500), but this does not work. Setting a data trace comparator to an SRAM variable works though.

However, you have a good point. I stepped through the init and the generated SystemClock_config contains

 LL_PWR_EnableBkUpAccess();

 LL_RCC_ForceBackupDomainReset();

 LL_RCC_ReleaseBackupDomainReset();

So here is the backup domain reset as you suspected.

Why would they do this? It's the whole point of the backup domain of preserving data... How can I turn this off? I have not found a setting for this in the code generator.

Of course I can delete the reset from the generated code, but each time I regenerate it via CubeMX, this gets overwritten.

Thanks! Martin

Martin294
Associate III

It seems I am not the only one falling into this trap:

https://community.st.com/s/question/0D50X00009XkX3P/bug-rtc-cannot-be-used-when-code-for-rcc-is-generated-using-ll?t=1587464385508

A google search on "LL_RCC_ForceBackupDomainReset" finds other occurences.

It seems this is a CubeMX bug? Should I report this (where)?

Hi @Community member​ ,

This issue has been already detected and reported internally for fix. I'll keep you posted with the updates.

Sorry for the inconvenience.

Linked here the same problem with a workaround preposition. It may work for you.

Thanks for you patience.

Khouloud.

Martin294
Associate III

Thanks for the clarification! Let's hope this is fixed soon.

- Martin