stm32_lse.inc -- small bug/feature Topic is solved

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

stm32_lse.inc -- small bug/feature  Topic is solved

Postby geoffrey.brown » Fri May 19, 2023 9:56 pm

I think the following code:

Code: Select all

__STATIC_INLINE void lse_init(void) {

#if STM32_LSE_ENABLED
  /* LSE activation.*/
#if defined(STM32_LSE_BYPASS)
  /* LSE Bypass.*/
  RCC->BDCR |= STM32_LSEDRV | RCC_BDCR_LSEON | RCC_BDCR_LSESYSEN | RCC_BDCR_LSEBYP;
#else
  /* No LSE Bypass.*/
  RCC->BDCR |= STM32_LSEDRV | RCC_BDCR_LSEON | RCC_BDCR_LSESYSEN;
#endif
  while ((RCC->BDCR & (RCC_BDCR_LSESYSRDY | RCC_BDCR_LSERDY)) !=
         (RCC_BDCR_LSESYSRDY | RCC_BDCR_LSERDY)) {
  }
#endif
}


should be:

Code: Select all

__STATIC_INLINE void lse_init(void) {

#if STM32_LSE_ENABLED
  /* LSE activation.*/
#if defined(STM32_LSE_BYPASS)
  /* LSE Bypass.*/
  RCC->BDCR |= STM32_LSEDRV | RCC_BDCR_LSEON | RCC_BDCR_LSESYSEN | RCC_BDCR_LSEBYP;
#else
  /* No LSE Bypass.*/
  RCC->BDCR |= STM32_LSEDRV | RCC_BDCR_LSEON | RCC_BDCR_LSESYSEN;

  while ((RCC->BDCR & (RCC_BDCR_LSESYSRDY | RCC_BDCR_LSERDY)) !=
         (RCC_BDCR_LSESYSRDY | RCC_BDCR_LSERDY)) {
  }
  #endif
#endif
}


In other words, the busy wait should only occur in the case where an external clock is not used. The reason is that the external clock might depend upon hardware that needs to be "brought" up during initialization. It's not clear that the wait is meaningful.

For my application, I copied the (edited) stm32_lse.inc into an include folder that is searched before the system folders, so no harm no foul. But it did take some time to identify the issue when it occurred in 20.0.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: stm32_lse.inc -- small bug/feature

Postby Giovanni » Sat May 20, 2023 5:25 am

Hi,

Moving in "bug reports".

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: stm32_lse.inc -- small bug/feature

Postby Giovanni » Sun May 28, 2023 9:23 am

Hi,

What is the issue exactly? the behavior of LSERDY bit does not depend on LSEBYP, the RM states:

"After the LSEON bit is cleared, LSERDY goes low after 6 external low-speed oscillator clock
cycles."

So it is just a small delay not related to actual oscillator stability, HSERDY does the same.

Giovanni

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

Re: stm32_lse.inc -- small bug/feature

Postby geoffrey.brown » Mon Jun 26, 2023 6:24 pm

6 cycles at 1khz is a long time. When using standby mode, the whole life cycle is 1) go to standby, 2) wake on event, 2) do something quickly 34go back to standby. So this wait is completely incompatible with minimum power. The tags I build average 200nA when not collecting data and 500nA when collecting data.

Geoffrey

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: stm32_lse.inc -- small bug/feature

Postby Giovanni » Sat Jul 01, 2023 9:22 am

Hi,

Change committed, I did the same also for HSE.

Giovanni


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 9 guests