cancel
Showing results for 
Search instead for 
Did you mean: 

Problem trying to compile RTC functionality on STM32F405

CBarb.1
Associate III

Hello,

I am trying to get my RTC module working working, I have setup everything using the stm32cubemx, so far all my peripherals are working but I seem to have an issue trying to setup my RTC which is a totally new experience for me using the STM32cube IDE. It seems that when I try to compile I get certain variables that appear to be undeclared, but these variables are declared within the HAL RTC library functions which are part of the compilation. Have I left some header file out? or is there something else I need to do so these variables are visible during compilation? I have attached the project file.

Thank you for your help.

Regards,

Carlos Barberis

*****************************************************************************************************

In my main.c file under main() I have the following:

 MX_RTC_Init(); // initialize the RTC

 HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD); // Set the time keep getting compile errors

 HAL_RTC_SetDate(&hrtc,&sDate,RTC_FORMAT_BCD);  // Set the date keep getting compile errors

The compile errors I get are shown below:

../Core/Src/main.c: In function 'main':

../Core/Src/main.c:193:28: error: 'sTime' undeclared (first use in this function)

 193 |  HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);

   |              ^~~~~

../Core/Src/main.c:193:28: note: each undeclared identifier is reported only once for each function it appears in

../Core/Src/main.c:197:27: error: 'sDate' undeclared (first use in this function)

 197 |  HAL_RTC_SetDate(&hrtc,&sDate,RTC_FORMAT_BCD);

   |             ^~~~~

1 REPLY 1

The error message tells it: you have to define (and fill in) a sTime struct, of RTC_TimeTypeDef type; and a sDate struct, of RTC_DateTypeDef type.

JW