RTC driver uses BKP registers!

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: RTC driver uses BKP registers!

Post by alexblack »

barthess wrote: If I remeber correct, the reasons to store whole value of preload register is to avoid initializing of this register every system startup.

After all, why not eliminate the use of the backup memory, because its so little.
Prescaler value - a constant that does not change in the project. The sole purpose of non-volatile memory in this case - is to track reset prescaler. And the only possible case when the memory reset it is power off of the BKP domain, and in this case will be reset and the bit RCC_BDCR_RTCEN. So why not use it?
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: RTC driver uses BKP registers!

Post by barthess »

alexblack
You are right. There was some problems (can not remember what exactly) to flawlessly change value during debugging process. But in real life this value just hardcoded to 32768Hz and forgotten.
What we can do:
1) place rtc_lld_init() in hal_lld_backup_domain_init()
2) return flag from hal_lld_init(hal_lld_backup_domain_init()) and pass it to rtcInit() in halInit()
Any more elegant ideas, folks?
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: RTC driver uses BKP registers!

Post by barthess »

Givanni
That bug in tracker looks allready fixed/workarounded in Chibios.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: RTC driver uses BKP registers!

Post by Giovanni »

Also in stable branch?

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: RTC driver uses BKP registers!

Post by barthess »

Giovanni
1) Backup registers unlocking procedure identical both in stable and unstabel branch.
2) Problem with prescaler currently solving in this topic
Or I am incorrectly understand problems described in ticket?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: RTC driver uses BKP registers!

Post by Giovanni »

I hoped you knew, I didn't understand it fully :). But if the driver works then it is OK.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: RTC driver uses BKP registers!

Post by barthess »

alexblack
Could you test updated driver? It works as expected on my STM32-103STK board.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: RTC driver uses BKP registers!

Post by Giovanni »

Bartess, It looks good but probably you should perform that new function call from within an:

#if HAL_USE_RTC
#endif

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: RTC driver uses BKP registers!

Post by barthess »

Oops, my bad. Fixed.
alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: RTC driver uses BKP registers!

Post by alexblack »

barthess wrote:alexblack
Could you test updated driver? It works as expected on my STM32-103STK board.

I tested the driver on my board - everything works as planned.
The only thing I do not understand why set RTC hw ON, if RTC driver not used?
And maybe for high reliability switching RTC ON is better to move to location after prescaler setup in case, if a MCU reset occurs at the time the prescaler setup:

Code: Select all

static void hal_lld_backup_domain_init(void) {
...
/* Prescaler value loaded in registers.*/
#if HAL_USE_RTC
    rtc_lld_set_prescaler();
/* RTC clock enabled.*/
    RCC->BDCR |= RCC_BDCR_RTCEN;
#endif /* HAL_USE_RTC */
...   
Post Reply