Skip to main content
Visitor
September 17, 2026
Question

Set RTC through STM32Cube Programmer

  • September 17, 2026
  • 12 replies
  • 65 views

I’m trying to set up flashing firmware and initializing the RTC clock on a blank or chip erased STM32H747Xi using the STM32Cube CLT package that contains the STM32_Programmer_CLI.exe command line tool. I can’t seem to write to the critical registers for RTC. Is there a procedure to set the RTC? If so, can you list the steps needed to do so?

Thanks,

Johnas

12 replies

waclawek.jan
Super User
September 17, 2026

If you can write to individual registers, then it should be not much dissimilar to what you’d do in a program to write to those registers, isn’t it? So, generally, it’s about enabling clocks in RCC (PWR, and I don’t know if in ‘H7 there’s a dedicated RTC APB clock), enabling backup-domain writes by PWR_CRx.DBP, enabling the RTC writes through its own lock mechanism requiring to write key(s) to RTC_WPR, and for some registers putting the RTC into INIT mode.

It’s probably best to get acquainted with this sequence using a debugger.

JW

 

Visitor
September 17, 2026

I tried to write individual registers in the RTC domain. However, I’m getting write errors. These registers seem to be protected. I can write to flash and RAM in other areas. Is there an unlock sequence or something that allows write privileges to the RTC registers?

Andrew Neil
Super User
September 17, 2026

The Reference Manual would detail any unlock sequence.

As ​@waclawek.jan said, the process would be the same as if you were doing it in code - so look at code examples which set the RTC.

Maybe get what you want working in code, then try in the debugger (as Jan suggested), then via the programmer API ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Visitor
September 17, 2026

STM32_Programmer_CLI -c port=SWD -w8 0x58004024 0xCA
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.22.0
      -------------------------------------------------------------------

ST-LINK SN  : 00260008544B500120343637
ST-LINK FW  : V3J16M9B5S1
Board       : STLINK-V3SET
Voltage     : 3.31V
SWD freq    : 8000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x450
Revision ID : Rev V
Device name : STM32H7xx
NVM size  : 2 MBytes
Device type : MCU
Device CPU  : Cortex-M7/M4
BL Version  : 0x91


Downloading 8-bit data...

██████████████████████████████████████████████████Error:
Downloading 8-bit data failed...
If it's a Flash memory, it may be not erased or protected

STM32_Programmer_CLI -c port=SWD -w8 0x58004024 0x53
      -------------------------------------------------------------------
                       STM32CubeProgrammer v2.22.0
      -------------------------------------------------------------------

ST-LINK SN  : 00260008544B500120343637
ST-LINK FW  : V3J16M9B5S1
Board       : STLINK-V3SET
Voltage     : 3.31V
SWD freq    : 8000 KHz
Connect mode: Normal
Reset mode  : Software reset
Device ID   : 0x450
Revision ID : Rev V
Device name : STM32H7xx
NVM size  : 2 MBytes
Device type : MCU
Device CPU  : Cortex-M7/M4
BL Version  : 0x91


Downloading 8-bit data...

██████████████████████████████████████████████████Error:
Downloading 8-bit data failed...
If it's a Flash memory, it may be not erased or protected

 

Tried 32-bit versions of this command with the same outcome.

Andrew Neil
Super User
September 17, 2026

Again, I’d suggest getting this working in code first: then you’ll know that you have the sequences, addresses, etc correct - without having to worry about any extra vagaries of the programmer API.

Once you have a known-working sequence, then move on to implementing that via the programmer API.

As ever - one small step at a time ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
September 17, 2026

If you are trying to turn clocks on the settings in registers like RTC secure configuration register (RTC_SECCFGR) need to be cleared for your clocks or GPIO or whatever else. This register can be written only when the APB access is secure.

You can only clear them (make the clock work) in a secure project.  Alternatively if you are making a development non-secure project clocks can be set whatever values in SECCFGR.

What gets problematic is a mix of secure and non-secure project - once you are in non-secure you cant turn any clocks on etc.

Hope that helps if not post more information about what you are trying to do as regards project etc please.

Visitor
September 17, 2026

Hi Rich,

I’m looking at the register map for the RTC peripheral in the reference manual for the STM32H7 (RM0399) and I see no such register.

To Jan and Andrew, I have working firmware that sets the RTC registers and I’ve looked at the procedure that it follows. I’m doing the same thing only from a PC calling STM32_Programmer_CLI.exe with the appropriate arguments. Is it possible that this is restricted via STLink/SWD?

Thanks,

Johnas

Associate II
September 17, 2026

OK for STM32H747 there is “The Equivalent: RTC_PRIVCFGR (RTC Privilege Configuration Register)
Instead of Secure vs. Non-Secure, the legacy H7 splits operations into Privileged (OS/Kernel) and Unprivileged (User Application) modes. By configuring RTC_PRIVCFGR, you can block unprivileged application tasks from tampering with the clock.

That might be a red herring.


On a blank or chip-erased STM32H747Xi, trying to write values directly into the RTC registers using individual register will not work.

“This occurs because the hardware places an intricate hardware-level lock over the RTC domain following a reset. Simply sending a write command to an RTC address will fail unless the system clock is enabled, the backup domain power is unlocked, and the specific RTC write-protection hardware sequence is executed in a highly coordinated, continuous manner. 

STM32_Programmer_CLI.exe executes each line as an isolated debug action, meaning the hardware locks reset back into place between commands. 

The industry-standard production procedure to bypass this involves flashing a minimal initialization script or code to do the work from inside the chip”

RTC initialization with STM32CubeProgrammer

Another option for you Johnas is to use the Bootloader (see AN2606 Rev 70 page 321) The bootloader will write code directly to flash and possibly allow a small app to run in RAM to set the RCT etc?  see also AN3155.

Visitor
September 17, 2026

Hi Rich,

No RTC_PRIVCFGR register either. However, the link you provided makes it clear that individual commands can’t be sent. Instead, an RTC initialization function must be injected and run from there to enable the RTC. I can’t assume that there is firmware running on the MCU. This is for factory programming and usually the MCU is blank.

I may try your suggestion of injecting some code into RAM and running it to initialize the RTC.

Thanks,

Johnas

Associate II
September 17, 2026

Hi Jonas,

Just check that the bootloader in STM32H747Xi is itself allowed to run that code from RAM. The bootloader is good for anything up to 256 byte blocks of code or 2 x 256 bytes is ok too.

Pavel A.
September 20, 2026

Like with external flash loaders: you can make a small program to set up the RTC, load in into the RAM and run.

Even write a “fake” external loader.