2 years, 3 months ago.

rtc hangs/freezes on set_time() on stm32f103c8t6

Connected 3.2v battery on vbat, and tried RTC samples.

The program hangs on call of set_time function.

#include "stm32f103c8t6.h"
//#include "rtc_api.h"
#include "stdio.h"
#include "mbed.h"

int main()
    set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37
   while (true) {
        time_t seconds = time(NULL);
        myLCD.printf("Time as seconds since January 1, 1970 = %d\n", seconds);

rtc_init(); also hangs the program.

if I skip set_time (or rtc_init), program does not hang but time(NULL) returns -1


Hello Boban,
According to the reference manual, chapter 5.1.2 "Battery backup domain", the VBAT pin powers the RTC unit, the LSE oscillator and the PC13 to PC15 IOs, allowing the RTC to operate even when the main digital supply (VDD) is turned off. But I don't think you can print or display anything while the VDD is off. Nevertheless, when the VDD is recovered the program shall resume to run without resetting the RTC and loosing the time information while the VDD was down. Unfortunately, as I know this did not work on the ST mbed boards in the past. Despite of this announcement I'm not sure that it has been fixed also for the NUCLEO-F103RB platform. At least it isn't on the list of tested boards.

posted by Zoltan Hudak 18 Feb 2017

Just to confirm that this does not work on STM32F103VET6 also... :(

posted by Boban Velickovic 12 Mar 2017
Comment on this question

1 Answer

To post an answer, please log in.