2025-02-07 03:04 AM
Hello,
I am trying to configure RTC time and date register from STM32CubeProgrammer CLI but as for now I am facing issues only. I was wondering if there's some special procedure to edit these registers straight from the programmer or not, since I am trying to replicate what's written on RM0456 to edit calendar values.
I made a simple C# console application:
uint RTC_REG_TR_BASEADDRESS = 0x46007800;
uint RTC_REG_DR_BASEADDRESS = 0x46007804;
uint RTC_REG_WPR_BASEADDRESS = 0x46007824;
uint RTC_REG_INIT_BASEADDRESS = 0x4600780C;
RunCmd($"{CLI_EXEC_PATH} -c port=swd dLPM mode=UR -hardRst -w32 {RTC_REG_WPR_BASEADDRESS} 0xCA");
RunCmd($"{CLI_EXEC_PATH} -c port=swd dLPM mode=UR -hardRst -w32 {RTC_REG_WPR_BASEADDRESS} 0x53");
RunCmd($"{CLI_EXEC_PATH} -c port=swd dLPM mode=UR -hardRst -w32 {RTC_REG_INIT_BASEADDRESS} 0x80");
Thread.Sleep(1000);
RunCmd($"{CLI_EXEC_PATH} -c port=SWD dLPM mode=UR -hardRst -w32 {RTC_REG_TR_BASEADDRESS} {RTC_REG_TR_VALUE}");
RunCmd($"{CLI_EXEC_PATH} -c port=SWD dLPM mode=UR -hardRst -w32 {RTC_REG_DR_BASEADDRESS} {RTC_REG_DR_VALUE}");
RunCmd($"{CLI_EXEC_PATH} -c port=swd dLPM mode=UR -hardRst -w32 {RTC_REG_WPR_BASEADDRESS} 0x00");
RunCmd() is just a simple method that starts a process on cmd.exe. RTC_REG_TR_/DR_VALUE are BCD date and time. So, basically, I write WPR register as suggested from HAL code, then follows the initialization and eventually the writing of those registers. Unfortunately, CLI reports some errors such "Failed to download data! If it's a flash memory, it may not be erased or protected".
Do you have any clue or tip to fix this?
2025-02-07 03:19 AM
Unprotect the RTC register access. You will find the derails in your MCU's Reference manual. Depending on the MCU model, you need to access RCC and/or PWR module.
2025-02-07 03:32 AM
Hello gbm, I think the first two command do that since I'm replicating 1:1 what
__HAL_RTC_WRITEPROTECTION_DISABLE
does. What do you mean with "you need to access RCC and/or PWR module"? Do RTC need to freeze before doing something on its registers?