STM32VLDISCOVERY Setting the Time & Date

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

esn
Posts: 3
Joined: Mon May 27, 2013 11:52 pm

STM32VLDISCOVERY Setting the Time & Date

Postby esn » Tue May 28, 2013 2:00 am

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

DrunkenDonkey
Posts: 124
Joined: Sun Aug 28, 2011 5:16 pm

Re: STM32VLDISCOVERY Setting the Time & Date

Postby DrunkenDonkey » Tue May 28, 2013 6:18 am

While I have never used it, there's the void rtcInit(void); maybe worth calling before any other rtc functions, give it a shot.

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32VLDISCOVERY Setting the Time & Date

Postby Giovanni » Tue May 28, 2013 7:56 am

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

esn
Posts: 3
Joined: Mon May 27, 2013 11:52 pm

Re: STM32VLDISCOVERY Setting the Time & Date

Postby esn » Wed May 29, 2013 3:53 am

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

esn
Posts: 3
Joined: Mon May 27, 2013 11:52 pm

Re: STM32VLDISCOVERY Setting the Time & Date

Postby esn » Wed May 29, 2013 7:55 am

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

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32VLDISCOVERY Setting the Time & Date

Postby Giovanni » Wed May 29, 2013 7:59 am

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

User avatar
Giovanni
Site Admin
Posts: 14455
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: STM32VLDISCOVERY Setting the Time & Date

Postby Giovanni » Wed May 29, 2013 8:00 am

You posted just before me.

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

Giovanni


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 6 guests