Skip to main content
ricardomiguel
Associate II
August 18, 2016
Solved

LSE OSC32 stops working

  • August 18, 2016
  • 2 replies
  • 1876 views
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
    This topic has been closed for replies.
    Best answer by ricardomiguel
    Posted on December 07, 2016 at 14:24

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

    2 replies

    jpeacock23
    Associate
    August 18, 2016
    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

    HamidRezaMaddah
    Associate III
    December 7, 2016
    Posted on December 07, 2016 at 13:37

    I have the same problem. Have you solved it?

    ST Renegade
    Associate
    December 7, 2016
    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

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

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