2022-08-21 04:25 AM
I need the RTC module to be enabled in order to write to & read from backup registers on STM32F401 using these functions:
void HAL_RTCEx_BKUPWrite(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister, uint32_t Data)
uint32_t HAL_RTCEx_BKUPRead(RTC_HandleTypeDef *hrtc, uint32_t BackupRegister)
However, the datasheet states that the lowest backup battery drain current (IDD_VBAT, typ. 0.1uA) can be achieved when RTC and LSE are off.
So is there a way to use the backup registers as a general memory while RTC is off?
Solved! Go to Solution.
2022-08-31 05:49 AM
Hi Kaouthar,
> The BackUp Registers are part of the RTC peripheral so we will need to enable the RTC to be able to access them.
I don't know what do you exactly mean by "enable the RTC" in terms of peripheral registers' content, but generally I disagree. Here's my take, please correct me if I am wrong:
This all can be very easily checked, no program needed, just using the debugger. I don't have an 'F401 at hand and tested on 'F407, but I see nothing in the RM to indicate different behaviour.
Enabling RTC clock by setting nonzero RCC_BDCR.RTCSEL and setting RCC_BDCR.RTCEN indeed increases current consumption on VBAT pin, and is not needed for using RTC_BKPxR alone.
In some STM32, there is an extra bit, RCC_APBxENR.RTCAPBEN, which enables/disables APB clock for RTC. In 'F401, there is no such bit so it's of no concern here.
JW
@KDJEM.1
2022-08-31 03:35 AM
Hi @Community member and welcome to the Community :),
The BackUp Registers are part of the RTC peripheral so we will need to enable the RTC to be able to access them.
For that, I advise you to take a look at this article “How to use the STM32’s backup registers�?
The main purpose VBAT is to be used as power supply for RTC, external clock 32 kHz oscillator and backup registers (through power switch) when VDD is not present.
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-08-31 05:49 AM
Hi Kaouthar,
> The BackUp Registers are part of the RTC peripheral so we will need to enable the RTC to be able to access them.
I don't know what do you exactly mean by "enable the RTC" in terms of peripheral registers' content, but generally I disagree. Here's my take, please correct me if I am wrong:
This all can be very easily checked, no program needed, just using the debugger. I don't have an 'F401 at hand and tested on 'F407, but I see nothing in the RM to indicate different behaviour.
Enabling RTC clock by setting nonzero RCC_BDCR.RTCSEL and setting RCC_BDCR.RTCEN indeed increases current consumption on VBAT pin, and is not needed for using RTC_BKPxR alone.
In some STM32, there is an extra bit, RCC_APBxENR.RTCAPBEN, which enables/disables APB clock for RTC. In 'F401, there is no such bit so it's of no concern here.
JW
@KDJEM.1
2022-09-01 01:31 PM
Hi Jan & Kaouthar, thanks for your feedback,
I tend to agree with Jan. Here's what I've made:
#define ADDR_BKP_REG_0 0x40002850
#define ADDR_BKP_REG_1 (ADDR_BKP_REG_0 + 4)
#define ADDR_BKP_REG_2 (ADDR_BKP_REG_0 + 8)
...
uint32_t reg0 = *(__IO uint32_t*) ADDR_BKP_REG_0;
uint32_t reg1 = *(__IO uint32_t*) ADDR_BKP_REG_1;
uint32_t reg2 = *(__IO uint32_t*) ADDR_BKP_REG_2;
...
HAL_PWR_EnableBkUpAccess();
*(__IO uint32_t*) ADDR_BKP_REG_0 = 0xCAFECAFE;
*(__IO uint32_t*) ADDR_BKP_REG_1 = 0xBEEFBEEF;
*(__IO uint32_t*) ADDR_BKP_REG_2 = 0x12345678;
...
HAL_PWR_DisableBkUpAccess();
This all works with the RTC being disabled.
2022-09-02 09:18 AM
Hi,
Based on some tests I made with Nucleo-STM32F410RB, I confirm that you can read and write the backup registers while the RTC is disabled.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-09-02 01:28 PM
Why don't you use normal defined register accesses?
RTC->BKP0R = 0xCAFECAFE;
2022-09-03 11:50 AM
Thanks for the tip, this is indeed a more elegant way. I was erroneously supposing that the definition of BKP0R won't be included in the code generated by STM32CubeIDE when RTC is disabled.