stm32l412

Report here problems in any of ChibiOS components. This forum is NOT for support.
geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

stm32l412

Postby geoffrey.brown » Thu Mar 16, 2023 6:11 pm

Does anybody have a working example using the stm32L412? I've had to upgrade to the latest ChibiOS to find any support, but I don't have an example of the correct configuration files
Geoffrey

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

Re: stm32l412

Postby geoffrey.brown » Thu Mar 16, 2023 9:34 pm

Looks like upgrading to ChibiOS 20.3 to the latest to get support from stm32l412 is a major lift (I've go a lot of projects on 20.3 that are interrelated). Anybody have the necessary headers for stm32l412 that are compatible with 20.3?

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: stm32l412

Postby Giovanni » Fri Mar 17, 2023 1:07 pm

Hi,

You may try to back-port the ports/STM32/STM32L4xx directory to 20.3.x but probably it would not be without problems. Considering that 20.3 is at EOL you should rather consider putting your effort into updating to 21.11.x.

Giovanni

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

Re: stm32l412

Postby geoffrey.brown » Fri Mar 17, 2023 1:54 pm

Thanks. One of my issues (perhaps the major one) is that I had to modify the rtc related files because of the busy waiting that the stock code does on read -- rare, but can take and RTC time tick. Instead, I use the approach of reading the time registers twice and checking for rollover.
Basically, I have an unusual environment in which the RTC is fed by and external 1Khz signal (from an rv-3028 rtc chip). It's all about power. This gives me more accuracy at a lower power budget than a crystal.

There are a few other small changes I made to eliminate some related issues.



/* Synchronization with the RTC and reading the registers, note
DR must be read last.*/
// while ((rtcp->rtc->ISR & RTC_ISR_RSF) == 0)
// ;


#if STM32_RTC_HAS_SUBSECONDS
ssr = rtcp->rtc->SSR;
#endif /* STM32_RTC_HAS_SUBSECONDS */
tr = rtcp->rtc->TR;
dr = rtcp->rtc->DR;
// check for rollover
#if STM32_RTC_HAS_SUBSECONDS
ssr2 = rtcp->rtc->SSR;
#endif /* STM32_RTC_HAS_SUBSECONDS */
tr2 = rtcp->rtc->TR;
dr2 = rtcp->rtc->DR;


#if STM32_RTC_HAS_SUBSECONDS
if ((tr2 != tr) || (dr2 != dr) || (ssr2 != ssr)) {
ssr = rtcp->rtc->SSR;
#else
if ((tr2 != tr) || (dr2 != dr) ) {
#endif /* STM32_RTC_HAS_SUBSECONDS */
tr = rtcp->rtc->TR;
dr = rtcp->rtc->DR;
}
cr = rtcp->rtc->CR;
// rtcp->rtc->ISR &= ~RTC_ISR_RSF;

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: stm32l412

Postby Giovanni » Fri Mar 17, 2023 8:21 pm

Hi,

What guarantees that there is not another rollover after the check? this is why the original code is in a loop.

Giovanni

geoffrey.brown
Posts: 87
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 15 times

Re: stm32l412

Postby geoffrey.brown » Thu Mar 30, 2023 9:24 pm

This is from AN4759

"When the system is woken up from low-power modes (SYSCLK was off, consequently, the APB clock was
off too), the application must first clear RSF, and then wait until RSF is set again before reading the calendar
registers. This ensures that the value read by the application is the current calendar value, and not the value
before entering the low-power mode.
By setting BYPSHAD = 1 in RTC_CR, the calendar values are taken directly from the calendar counters instead
of reading the shadow register. In this case, it is not mandatory to wait for the synchronization time, but the
calendar registers consistency must be checked by the software. The user must read the required calendar field
values. The read operation must then be performed again. The results of the two read sequences are compared.
If the results match, the read result is correct. If they do not match, the fields must be read one more time, and the
third read result is valid."

The problem I'm dealing with is the first line -- waiting for the RSF to be set after wakeup. In my application that would significantly increase the overall energy usage since the RTC is running off a 1024Hz external signal and the typical wakeup period is only ~1 millisecond. We're logging data for a year with a 5.5 mAh battery -- a 0.5gram logger carried by a song bird.

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: stm32l412

Postby Giovanni » Fri Mar 31, 2023 6:30 am

Hi,

I see your problem, I am not sure I can use the bypass mode in the general purpose driver.

I am moving this in "bug reports" because that is the place I check for "things to do", I will give it a try.

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: stm32l412

Postby Giovanni » Tue Apr 11, 2023 12:48 pm

More notes, perhaps the bypass mode should be used as default, having large delays while reading date/time is not that nice.

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: stm32l412

Postby Giovanni » Tue May 30, 2023 1:42 pm

Hi,

I committed RTCv2 and RTCv3 drivers using bypass mode, feedback appreciated.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 4 guests