STM32duino RTC libary trouble

Hello,

After some time I finally got out of the confusion between the platforms of stm32. Now im working on the STM32duino platform with the bluepillf103 board. I managed to get the rtc working with this libary without a problem. It keeps the track of time nicely.

I ran into problems when I wanted to use the LSE_CLOCK as the clock source, which is the only one accurate enough to be called an rtc. Whenever I use the function as object.setClockSource(LSE_CLOCK); I automatically recieve an error of it not being a matching function to call. When I try to look around the libary its firmly defined as any other function. Any ideas?

Heres the code, platformio.ini and the error output:

void setup() {
  rtc.setClockSource(LSE_CLOCK);
  rtc.begin(HOUR_FORMAT_24);
  if (!rtc.isTimeSet()) {
    rtc.setTime(0, 6, 0);
  }
}

platformio.ini

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino

lib_deps = 
    STM32duino RTC

Compiler output:

src\main.cpp: In function 'void setup()':
src\main.cpp:69:31: error: no matching function for call to 'STM32RTC::setClockSource(sourceClock_t)'
rtc.setClockSource(LSE_CLOCK);
                           ^
In file included from src\main.cpp:9:0:
.pio\libdeps\bluepill_f103c8\STM32duino RTC_ID5502\src/STM32RTC.h:104:8: note: candidate: void STM32RTC::setClockSource(STM32RTC::Source_Clock)
   void setClockSource(Source_Clock source);
    ^~~~~~~~~~~~~~
.pio\libdeps\bluepill_f103c8\STM32duino RTC_ID5502\src/STM32RTC.h:104:8: note:   no known conversion for argument 1 from 'sourceClock_t' to 'STM32RTC::Source_Clock'
*** [.pio\build\bluepill_f103c8\src\main.cpp.o] Error 1

The STM32RTC class uses its own, nested enum. So the correct line is:

  rtc.setClockSource(STM32RTC::LSE_CLOCK);
1 Like

I will try that. Tried to look around the source files to resolve it but enums are totally new to me so thanks for showing me this significant difference.

If it helps, have a closer look at the error message…

First there is the error…

error: no matching function for call to 'STM32RTC::setClockSource(sourceClock_t)'

… so at first glance, the function doesn’t exist, right?

But then we’re told …

note: candidate: void STM32RTC::setClockSource(STM32RTC::Source_Clock)

… huh? It does exist?

Finally …

no known conversion for argument 1 from 'sourceClock_t' to 'STM32RTC::Source_Clock'

… ah… no known conversion… fantastic… clear as mud! :laughing:

But yeah, that last line gave it away… the function exists, but it didn’t like the value being past to it to set the source clock.

Thanks a lot for this explanation as well. I thought the syntax of STM32RTC::Source_clock is just for creating class functions, still a beginner in c++.

Especially when I looked at the comments for the function i was just weirded out the argument didnt get accepted.

/**
  * @brief set the RTC clock source. By default LSI clock is selected. This
  * method must be called before begin().
  * @param source: clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK
  * @retval None
  */

But youre right Ive had many problems with the libary when using it on other platforms and boards and I just assumed straight away it was some odd problem again and not an clear issue on my side and didnt completely read the error output and tried to figure it out.

1 Like