Using the ST-LINK Utility to configure the RTC to current time

Some registers are only legal for a specific access width (ie, -w32 may not be correct), or may not read back the written values which could cause a problem with verification.

There might also be sequence or state restrictions on accessing things.

An option that should work around most conceivable issues would be to craft a tiny program to do the job which would linked to run in RAM. You could substitute the data into its binary after figuring out the offset, upload the modified version, and run it. Or you could have the program get values from a region of RAM outside of the file's extents, which you would set before running. With finer grained control of the stlink you could also pass values in CPU registers, though you might(?) need the alternate open source command line program rather than ST's to do that (this small routine in RAM method is incidentally how that program accomplishes writing to flash)


So, one of the problems was, as Chris Stratton pointed out:

Some registers .. may not read back the written values which could cause a problem with verification.

This meant that the verification failed, causing the error to display, even though the write operation actually succeeded.

Below is the response I get when reading the PWR_ISR register, setting the INIT bit, then reading the register back again:

0x4000280C : 00000027

Writing 0x00000080 at 0x4000280C...Error!

0x4000280C : 000000A7

The verification of the ST-LINK Utility checks if the value written to the address and read from the address match. In this case, the write operation was successful, even though the two values don't match, as the INIT bit is now set.

The other problem was that I could not notice the effect of the write operation. While connected to the microcontroller, it gets kept in the reset state by the ST-LINK (known as "connect under reset"). I needed to use the HOTPLUG connect option, which connects to the microcontroller without halt or reset.

The “connect under reset” option allows to connect to the target before executing any instruction. This is useful in many cases like when the target contains a code that disables the JTAG/SWD pins.

The “HotPlug” option allows to connect to the target without halt or reset. This is useful to update RAM addresses or IP registers while application is running

The batch file fully works as I wanted it to! The command now looks like this:

ST-LINK_CLI.exe -c HOTPLUG -w32 <Address> <data> -w32 <Address> <data> ...

Tags:

Rtc

Stm32