Is there a way to update the RTC with computer information when the program is uploaded on the STM32F4 ? For example, the information of date and hour on the computer is: 12h40 11/09/2018, and when I flash the microcontroler with IAR/AC6, then the RTC is set whith these pieces of information ?
-
2I'd assume so. Registers map to specific memory locations (refer to Reference Manual -> Memory map and register boundary addresses for exact values). From the PC perspective all you do is reads and writes to those locations. You'd have to implement correct RTC date/time programming sequence on a PC (disable write protection beforehand and so on). – J_S Sep 11 '18 at 12:39
-
2I like this question, because it is good idea to set the time after flashing, especially if you have large batch of devices for programming. – vlk Sep 11 '18 at 21:10
4 Answers
My idea is to make a script which you run after flashing (I'm not familiar with IAR, but hope it is possible to run something after FLASH) and this script will set over debugging port RTC registers with current time.
If you use ST-Link/V2 hardware for flashing and you have any experience with python, you can use for that pyswd library. is easy, just in python script get actual time and set appropriate registers in connected MCU.

- 2,581
- 3
- 31
- 35
You can modify most port registers through SWD (or JTAG) in the same way as flash and RAM addresses.
Maybe some of the budget-class debug adapters lack a scriptable option, but at least the mainstream range of adapters allows you to write values to any address the CPU can reach through the internal buses (AHB, APBx etc.). If you read the reference manual carefully, you can at least find out the raw addresses (and bit patterns) of the registers you have to assign. If you are lucky, the software tools of your debug adapter even provide you a feature where you can do this with lots of syntactic sugar - without having to dive into the manuals.

- 1,294
- 11
- 27
As far as I see it, you have two options:
- Bake PC time into your firmware. To do this, you could build your firmware with some area of memory, or indeed the Makefile, dedicated for real-time values, which are populated by a script during the build. When the firmware first runs, it would read from these locations and update the RTC. If you went for this approach, your time would always be out by some amount, depending on how long it takes to build and download the firmware to the device.
- Write the PC time on first power-on. To do this, you would need an interface between the PC and the device, and an application running on the PC. The application would be commanded to get the current PC time and send it to the device over the interface (e.g., a serial cable), and the RTC would then be updated. This is a better approach, since device time will be more tightly coupled to PC time, and you could script this also. The downside here is you have to build the interface.
Also, as an aside, consider whether your application actually needs 'real-time'. Many embedded devices can make do with relative time, e.g., milliseconds elapsed since power-on.

- 1,833
- 1
- 15
- 32
-
I think this is not quite what the question is looking for - it is not about *building a timestamp from some real-time clock into the firmware* or *passing time synchronisation through the software application*, but to do this through the flasher (SWD / JTAG) connection. – HelpingHand May 31 '20 at 21:30
IMO easiest way is to modify openOCD TCL script to upload (after flashing) small program which will update the RTC. 15 mins of work

- 60,014
- 4
- 34
- 74
-
1Interesting DVs no comments. I often use modified by me openOCD if I have very specific programming needs. All other methods are time consuming and the saved time will extremely inaccurate - and the worst every time different. – 0___________ Sep 12 '18 at 10:12