AnsweredAssumed Answered

LSE OSC32 stops working

Question asked by nunes.ricardo on Aug 18, 2016
Latest reply on Dec 8, 2016 by Jaroslav Becka
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);
}




Outcomes