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

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

stm32_lse.inc -- small bug/feature

Post by geoffrey.brown »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stm32_lse.inc -- small bug/feature

Post by Giovanni »

Hi,

Moving in "bug reports".

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

Re: stm32_lse.inc -- small bug/feature

Post by Giovanni »

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: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: stm32_lse.inc -- small bug/feature

Post by geoffrey.brown »

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: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: stm32_lse.inc -- small bug/feature

Post by Giovanni »

Hi,

Change committed, I did the same also for HSE.

Giovanni
Post Reply