8 years ago.

RTC error: LSE clock initialization failed

I've looked everywhere I can think of and found little information on the problem I'm having. I'm using a 303k8 to read an analog value and then store it to an sd card. I ran this same code on a 303RE and it works without any issues at all. No compiler warnings but I get this error after a few seconds of the code hanging going to write to the SD card:

RTC error: LSE clock initialization failed.

Does anyone know what this is all about?

This is the link I found that talks about the issue but I don't have enough background in this to really understand what is changing and why.

https://developer.mbed.org/questions/68380/NUCLEO-F411RE-RTC-error-LSE-clock-initia/

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F303K8T6 microcontroller.

2 Answers

8 years ago.

I happened to have exactly the same issue on an Seeed Arch Max board (F407 IIRC). Problem is that apparantly the RTC fails to start, and it gives a blocking error which stops your code. The SD library uses the RTC to determine the time (of course if you didn't set it the time is still going to be pretty random).

Myself I couldn't care less about time, and went for the following workaround:

time_t read_rtc(void) {
    return 0;
}

int main() {
    
    attach_rtc(&read_rtc, NULL, NULL, NULL);
    //After this the rest of your main code

attach_rtc is an mbed function which allows you to use the C time library with MCUs which have no RTC themselves, or as in this case, to overwrite the standard RTC functions. There are four functions here (read, write, active and init iirc), since I don't do anything else with RTC only the read functions needs to be set. Here it is set to just return 0, but of course you can make it return any time you like to set as creation date on your SD files.

If you actually want to make the RTC work it is another problem :).

Accepted Answer

Looks like this did the trick. So is that attach interrupt setting the RTC NULL?

posted by Patrick McNamara 11 Jul 2016

It puts it on UNIX time 0, which is 01-01-1970 iirc. You can make it return any other time by just changing that number or using the mktime C function to calculate it. (Or use this site for example: http://www.epochconverter.com/)

The NULLs in the attach tell the code those functions don't exist: The underlying code is made to just ignore those ones and not try to call them. (So when before it would call the init function, it first checks if it is not NULL. In this case the init function is set to NULL, and it skips it).

Here you can see the function definition: https://github.com/mbedmicro/mbed/blob/master/hal/api/rtc_time.h

And here the implementation: https://github.com/mbedmicro/mbed/blob/master/hal/common/rtc_time.c

As you can see it always checks if those functions are NULL before calling them.

posted by Erik - 12 Jul 2016
8 years ago.

Hi there has been a recent fix on NUCLEO_F303K9, which is supposed to used LSI and not LSE See: https://github.com/mbedmicro/mbed/pull/2100 I think this should solve your problem

Bleh... I've been using mbed as my compiler. How do I integrate this with mbed?

posted by Patrick McNamara 11 Jul 2016

hello - I think that you'll get benefit of this change in mbed online compiler only after the next official release

posted by Laurent Meunier 13 Jul 2016