cancel
Showing results for 
Search instead for 
Did you mean: 

LSERDY is set, but LSE not running correctly

AMill.7
Associate

Hi, I am working on a project for STM32F746ZGT6 that uses the RTC clocked from the LSE.

In some cases I am seeing an issue where the LSE appears to start (LSERDY reads as 1 within the call to HAL_RCC_OscConfig from the peripheral libraries) but it appears that the clock is not running correctly.

I can tell that the LSE is either not running at all, or running with incorrect frequency because:

  • When I try to configure the RTC, I get a timeout inside RTC_EnterInitMode where it pends for 1 second on the INITF flag being set
  • If I use TIM5 to measure the LSE clock period, I can see that the period is not always as expected, and sometimes I do not get any timer interrupt at all

My main question is, what are the conditions needed for LSERDY to be set to 1?

Clearly whatever these conditions are, they are being met, but I would like to know specifically what this means so that I can try to narrow down the source of issues with my LSE clock

1 ACCEPTED SOLUTION

Accepted Solutions
gbm
Lead III

LSE is very sensitive to PCB design. The crystal must be placed as close to the uC as possible, no other PCB tracks going under/crossing crystal tracks, no ground plane below the crystal tracks (but ground plane under the crystal is recommended). Setting the high drive option for an oscillator may help a little.

View solution in original post

3 REPLIES 3
gbm
Lead III

LSE is very sensitive to PCB design. The crystal must be placed as close to the uC as possible, no other PCB tracks going under/crossing crystal tracks, no ground plane below the crystal tracks (but ground plane under the crystal is recommended). Setting the high drive option for an oscillator may help a little.

Also read AN2867.

JW

MBabu.1
Associate II

I also recognized that LSERDY is no sufficiently reliable indicator if the quartz crystal is actually running. To workaround this problem I implemented a simple test which watches if the subsecond register changes (should happen every ~4ms) within 20ms:

 
```c
// Cheap/fast test if the oscillator does actual clock. More features not available in F4
uint32_t RTCSubSecRef = LL_RTC_TIME_GetSubSecond(hrtc.Instance);
uint32_t TimestampRef = OSAL_TicksMs();
do
{
  if (OSAL_TicksMs() - TimestampRef > RTC_NOOSC_TIMEOUT_MS)
  {
    // error case: The subsecond register has not changed within timeout duration
    break;
  }
} while(RTCSubSecRef == LL_RTC_TIME_GetSubSecond(hrtc.Instance));
```
 
Maybe this is helpful for anyone struggling with stopping crystals. Finally in my case it was an hardware issue as well but its helpful to have a software detection method.