7 years, 11 months ago.

Function set_time with STM32L053 and internal RTC clock source

Hello, I have the board with STM32L053 MCU and without external 32.768khz clock source. And I need to setup RTC. I'm trying this code:

Code

#include "mbed.h"

Serial terminal(PA_9, PA_10);
DigitalOut led1(PA_3);

void toggle_led() {
    led1 = !led1;
}

int main() {
      set_time(1256729737);
      time_t seconds = time(NULL);
      terminal.printf("Seconds since January 1, 1970: %d\n", seconds);
...

}

And there's no any response after set_time function, Console is empty. How could I fix that?

THanks

1 Answer

7 years, 11 months ago.

I cannot tell much for the L0, however I am working with the STM32L4. The L4 Nucleo board uses a 32k crystal which means the RTC clock works independent of the MCU clock. set_time works for me on L4.

However it depends how the mbed OS is configured, the L4 version exspectes that the RTC crystal (LSE) is available otherwise it will hang at set_time.

You can have a look into the mbed source at rtc_api.c in the STM HAL code.

Hello, thanks for the reply. But how I can change something in mbed sources?

posted by Anatoly Zimin 16 Jan 2017

You can download the mbed sources gfromt github, look into it and copy code into your project.

posted by Helmut Tschemernjak 16 Jan 2017

And could I use it in online IDE?

posted by Anatoly Zimin 16 Jan 2017

Yes, the IDE accepts all C/C++ code, even if it has been copied from the mbed sources.

posted by Helmut Tschemernjak 16 Jan 2017

I don't know how to make changes of hal functions in mbed IDE. Are there any way for that?

posted by Anatoly Zimin 23 Jan 2017