Report
2 months, 2 weeks ago.

Real-time clock in STM32

Hello,

I switched to a STM32F103 board with additional 32khz oscillator and the possibility to connect a backup battery . Is there any ready made code example how to initialize the internal real-time clock and keep the clock running while the main CPU is off?

I searched for this topic bud did not find anything really useful.

Thanks in advance!

Best regards, Peter

One additional point: What is the right way to access the other data that I can store in the NV memory of the RTC?

posted by Peter Mueller 11 Jul 2017
Comment on this question

2 Answers

2 months, 1 week ago.

Just using the standard Time functions should do the job. Although I know at least in the past it initialized time to 0 even if it was already running, I don't know if that is still the case, but you can easily check that. Check https://developer.mbed.org/handbook/Time

Erik just talking about the F103 RTC, are you planing to add support for the F103 in your WakeUpRTC library? I use your Library on multiple STM32 MCUs and the F103 is the only one missing. Thank you for this great RTC Lib. Regards Helmut

posted by Helmut Tschemernjak 09 Jul 2017

Erik just talking about the F103 RTC, are you planing to add support for the F103 in your WakeUpRTC library? I use your Library on multiple STM32 MCUs and the F103 is the only one missing. Thank you for this great RTC Lib. Regards Helmut

posted by Helmut Tschemernjak 09 Jul 2017

Hello Erik,

I created a simple C++ project using mbed and copied over your example code to set and read the time. It works, but as soon I restart the uC (of course commenting out the set time call) the time is reset to default. So it seems not to work.

I create a C project and generate init code for the RTC using STM32CubeMX. Then I set the time and when cycling power, starting the debugger the time still runs.

So I guess that a) mbed resets the time after each restart b) the 32kHz clock for the RTC is not init

Do you know more about this topic? Is is possible to access the HAL code from mbed?

Best regards, Peter

posted by Peter Mueller 10 Jul 2017

@Helmut, I just checked, but the F1 series indeed has as (almost) only one a completely different RTC than the others. Since I don't have an F1 myself I cannot try adding it sadly :).

@ Peter, yes that is possible. In the online compiler you can import mbed-dev. Or here on github: https://github.com/ARMmbed/mbed-os/. You can also make a bugreport/feature request there. Here was one with same problem before: https://github.com/ARMmbed/mbed-os/issues/1403 (I remembered him asking, that is why I didn't know how much of that was implemented).

Here the check should be: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/rtc_api.c#L132 I quickly checked, by default RTC_LSI is not set on the F103. So it should do the check if it is already enabled. I don't know why it isn't working properly for you. Since it should work properly you can make a bug report. You can also of course try fiddling around with it yourself to figure out why it does not work. Since I don't have it myself I can't do much to help :).

posted by Erik Olieman 10 Jul 2017

Hello Eric,

I used this board: http://www.ebay.com/itm/STM32F103C8T6-ARM-STM32-Minimum-System-Development-Board-Module-For-Arduino-/311156408508?epid=532038167&hash=item48725e00bc:g:ngMAAOSwygJXhGtV

Can I send you somehow such a hardware? Price is really low.

Best regards, Peter

posted by Peter Mueller 10 Jul 2017

Yeah sure, that is possible. However how is it programmed? I do have standard Nucleo boards, so if they can program it, it is fine. But I don't have a standalone STM programmer.

posted by Erik Olieman 11 Jul 2017
2 months, 1 week ago.

Hi Eric, just for your info. The F103 board has at the small end the SWD/SWCK/GND/VDD Connectors, I connected this and the F103 Reset line to the Nucleo CN4 plus the RX/TX lines to the Nucleo CN3. Within mbed, I switched the the F103 Nucleo TARGET and programming via the mbed online .bin file, this works great even the cheap F103 has only 64kB flash.

Another options is to use openocd which allows to program and debug (gcc) the board as well many other mbed boards. Again using the compiled mbed online bin files or GCC compiled files. (the GCC code is 2 x bigger)

I have documented connecting the F103 with pictures and a wiki article, and I happy to share it when you like to use the F103 board. Drop me a private note. I have also a STM32F103C8T6 give away board which I am happy to spend for you.

Here at mbed, Zoltan Hudak has also a great coverage of the STM32F103C8T6 board. https://developer.mbed.org/users/hudakz/code/STM32F103C8T6_Hello/

PS: It is hard to believe that this board has an Cortex M3 with USB and RTC clock for this price, but it is true.

PS: Another option is to get the F103 Nucleo board which saves you the remote debugging/setup.

posted by Helmut Tschemernjak 11 Jul 2017

To post an answer, please log in.