The RTC driver topic

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

In my opinion the driver should not depend on the library or we would be back to the previous situation which is exactly what I wanted to avoid, the library should be optional.

The realtime counter clock is the system clock.

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

Re: The RTC driver topic

Post by barthess »

Next step performed.
Conversion code moved to rtc.c(h). Now HAL contains all needed functions.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

Much nicer this way I think, users will not have to search for extra files.

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

Re: The RTC driver topic

Post by barthess »

Giovanni wrote:Much nicer this way

Agree.
I have fixed RTC testhal application for F4x.
Waking up on it works fine in opposite to F1x I still have no ideas why.
Michail
Posts: 28
Joined: Mon Aug 04, 2014 6:55 am

Re: The RTC driver topic

Post by Michail »

Hello Barthess, hi Giovanni!

Think I've stumbled upon a bug in the RTC driver in current trunk on STM32F100C8.

In halInit() function hal_lld_init() calls before rtcInit().
hal_lld_init() calls hal_lld_backup_domain_init(), it calls rtc_lld_set_prescaler(), it calls rtc_acquire_access() and at last it calls rtc_wait_write_completed() :)
Call stack for my code is:

Code: Select all

8 rtc_wait_write_completed() rtc_lld.c:74 0x080059aa   
7 rtc_acquire_access() rtc_lld.c:87 0x080059d8   
6 rtc_lld_set_prescaler() rtc_lld.c:191 0x08005ad0   
5 hal_lld_backup_domain_init() hal_lld.c:76 0x08001992   
4 hal_lld_init() hal_lld.c:109 0x080019f4   
3 halInit() hal.c:66 0x08005b6c   

and in rtc_wait_write_completed() in os/hal/ports/STM32/LLD/RTCv1/rtc_lld.c we can see:

Code: Select all

static void rtc_wait_write_completed(void) {
  while ((RTCD1.rtc->CRL & RTC_CRL_RTOFF) == 0)
    ;
}

But RTCD1 was not initialised yet! RTCD1.rtc points to NULL and my program hangs here.

Code: Select all

"RTCD1"   {...}   
   rtc   0x00000000   
   callback   0x00000000   
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

Hi,

Thanks for finding, tomorrow I will fix this.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

I just committed a fix, could you verify functionality? I lack HW for this.

Giovanni
Michail
Posts: 28
Joined: Mon Aug 04, 2014 6:55 am

Re: The RTC driver topic

Post by Michail »

Yes, now everything works fine!

Thank you!
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: The RTC driver topic

Post by steved »

Just looked at the latest change to STM32/lld/rtc2/rtc_lld.c; calls to rtc_enter_init(); and rtc_exit_init(); have been added round the calendar initialisation. These calls are already present earlier and later in the code - should they have been deleted?
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: The RTC driver topic

Post by Giovanni »

It is possible, probably I misunderstood the requested change there, I will look into it again tomorrow.

Giovanni
Post Reply