cancel
Showing results for 
Search instead for 
Did you mean: 

LSE OSC32 stops working

ricardomiguel
Associate II
Posted on August 18, 2016 at 16:50

I have a custom board with STM32F446RE, with RTC powered by coin cell batteries. After testing 2 boards in the field for several days they stoped working and, while debugging, I realised that there a timeout in the LSE initialization:

HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
{
(...) stm32f4xx_hal_rcc_ex.h : line 2257
__HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
if
((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
{
/* Get Start Tick*/
tickstart = HAL_GetTick();
/* Wait till LSE is ready */
while
(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
{
if
((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
{
return
HAL_TIMEOUT; 
// RETURNS HERE!!!
}
}
}
else
(...)
}

This happens during my SystemClock_Config:

void SystemClock_Config(
void
)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 4;
RCC_OscInitStruct.PLL.PLLR = 2;
if
(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
NVIC_SystemReset();
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if
(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
NVIC_SystemReset();
}
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SDIO|RCC_PERIPHCLK_CLK48|RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLQ;
PeriphClkInitStruct.SdioClockSelection = RCC_SDIOCLKSOURCE_CLK48;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
HAL_StatusTypeDef res = HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
if
(res != HAL_OK)
{
NVIC_SystemReset();
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}

At this point I have 1 good board (only used in house for debugging) and 2 bad ones with the same symptom. Measuring the coin cell voltage gives 3.064V for the good board and 3.029 and 2.972V for the bad ones. In the bad ones there is no signal in OSC32_IN and OSC32_OUT pin. By removing the coin cell, put it back on and reprogram the board everything works as expected again. Any idea what's wrong? This is my RTC initialization code:

void
cfg_rtc(RTC_HandleTypeDef* rtc)
{
__HAL_RCC_RTC_ENABLE();
__HAL_RTC_RESET_HANDLE_STATE(rtc);
rtc->Instance = RTC;
rtc->Init.HourFormat = RTC_HOURFORMAT_24;
rtc->Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
rtc->Init.SynchPrediv = RTC_SYNCH_PREDIV;
rtc->Init.OutPut = RTC_OUTPUT_DISABLE;
rtc->Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
rtc->Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
HAL_StatusTypeDef status = HAL_RTC_Init(rtc);
assert
(status == HAL_OK);
}

#lse
1 ACCEPTED SOLUTION

Accepted Solutions
ricardomiguel
Associate II
Posted on December 07, 2016 at 14:24

The cap values weren't right for crystal we used. Changing them solved the problem

View solution in original post

6 REPLIES 6
jpeacock23
Associate III
Posted on August 18, 2016 at 19:51

In most cases if the LSE fails to start it's a problem with the load caps not matched to the crystal.  ST has an app note, AN2867, on how to determine the cap values for a particular crystal (not all crystals are the same!) and if you need a load resistor.  The fact that one board works doesn't mean the values are correct, only that one board just happens to work running out of spec.

  Jack Peacock

ricardomiguel
Associate II
Posted on December 07, 2016 at 14:24

The cap values weren't right for crystal we used. Changing them solved the problem

Posted on December 07, 2016 at 13:37

I have the same problem. Have you solved it?

Posted on December 07, 2016 at 13:47

Hey guys,

as Jack said, the app note is a good starting point. Also you can try to increase the timeout. Maybe the time the LSE needs to stabilize has increased due to environment conditions + wrong design. Also for LSE there is some parameter called driving level or something similar. It can't be set in CubeMX if I remember well, however you can do it manually, try to set this level higher (there are four levels) to support the startup and put it back after the LSE runs...

Renegade

Posted on December 07, 2016 at 13:57

Dear

I have studied the 

AN2867 application note.

Jakc told about ' fail to start'. but my problem is 'stop working'. And the problem don,t solve , till power of the board and removing the coin battery. 

I think some thing cause latch-up , same as ESD. Or short circuit on crystal pins. Is it possible? 

Posted on December 08, 2016 at 08:09

Hello,

have you calculated if your low-speed crystal is compatible with the LSE oscillator in ST microcontroller according to the AN2867? The important parameters for the calculation are ESR, load capacitance, shunt capacitance. These you can find in the crystal datasheet or ask the crystal manufacturer. T

he resistance of external resistor (if used) is also important for this calculation. 

You can find a list of recommended low-speed crystal for each STM32 family 

in the application note

. In case of some STM32 microcontrollers there is an option to increase the crystal drive level (in some cases even on-the-fly) resulting in higher current consumption, but compatibility also with cheaper crystals with poorer characteristics.

I would suggest you to try to replace the current crystal with one from the list of recommended ones and see if it solves the issue. If you for some reason have to keep the current one, calculate the compatibility according to the application note.

‌