Page 1 of 1

STM32VLDISCOVERY Setting the Time & Date

Posted: Tue May 28, 2013 2:00 am
by esn
Hi,
I am new to Chibios. Stumbled across it accidentally and was able to compile version 2.4.3 without errors, and successfully.
ran the demo under demos/ARMCM3-STM32F100-DISCOVERY. very impressive.

To implement clock calender functions, I currently use these ST following header functions along with the relevant source code with success.
#include "stm32f10x_bkp.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_rtc.h"
#include "stm32f10x_pwr.h"


Unfortunately the Chibios RTC demo does not show an example of using the function rtcSetTime(&RTCD1, &timespec);
Simply passing the relevant parameters clearly is not enough.

I hard-coded the time and date and programed chip as follows:- year, month, date, hour, minutes, seconds, [ 2012, 6, 8, 20, 38, 0 ] = 0x4FD262A8
Code Snippet

Code: Select all

   
   timespec.tv_sec = 0x4FD262A8;              // Hardcode time and date for testing purposes
   rtcSetTime(&RTCD1, &timespec);             // Program Stm32 Clock


with the above code the date is set correctly but the clock is set at zero's and does not run.

Hope I have explained my requirements clearly.
If further information is required please do not hesitate to ask.

Any help appreciated
Regards

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Tue May 28, 2013 6:18 am
by DrunkenDonkey
While I have never used it, there's the void rtcInit(void); maybe worth calling before any other rtc functions, give it a shot.

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Tue May 28, 2013 7:56 am
by Giovanni
Hi,

All the xxxInit() functions of the HAL drivers are called by the HAL itself when halInit() is invoked, you should not call them directly.

About the problem: make sure that the clock settings in mcuconf.h are correct for RTC usage, also make sure that your oscillator is actually running, there could be a problem.

Giovanni

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Wed May 29, 2013 3:53 am
by esn
Hi.
Thank you for replies.
@Giovanni
I know the oscillator is working fine, because I have code currently programmed into the board which displays the time & date correctly.

I looked in the mcuconf.h for clock settings as suggested but the only thing I can see relating to clock is the following two references..

Code: Select all

Reference 1
/*
 * HAL driver system settings.
 */
#define STM32_RTCSEL                        STM32_RTCSEL_HSEDIV

Reference 2
/*
 * RTC driver system settings.
 */
#define STM32_RTC_IRQ_PRIORITY              15


Does the file mcuconf.h have information missing relating to the clock settings?
is there something I am missing?

Forgot to mention I am running Chibios under Keil on XP Box.

Regards

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Wed May 29, 2013 7:55 am
by esn
HI,

I found out what the problem was nothing to do with Chibios;-)
When I was converting my program across to Chibios, the variable which held the total seconds count got messed up.
It should have kept the value through the whole scope of my RTC conversion function, but it didn't.
So when the date was being calculated all was fine, but when it came to calculate the time, it needed the original total seconds count to calculate it.
But instead it was getting loaded with a variable set to zero, hence the time was always set to zero's.

I apologies for any disruptions to the forum and sincerely appreciate the help given.

Thanks
Esn
Best Regards

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Wed May 29, 2013 7:59 am
by Giovanni
Hi,

mcuconf.h should have all the setting. The relevant ones are (defaults):

Code: Select all

#define STM32_LSE_ENABLED                   FALSE
#define STM32_RTCSEL                        STM32_RTCSEL_HSEDIV


You need to enable LSE and select it as source:

Code: Select all

#define STM32_LSE_ENABLED                   TRUE
#define STM32_RTCSEL                        STM32_RTCSEL_LSE


Giovanni

Re: STM32VLDISCOVERY Setting the Time & Date

Posted: Wed May 29, 2013 8:00 am
by Giovanni
You posted just before me.

Don't worry about asking, this forum is for this kind of questions.

Giovanni