cancel
Showing results for 
Search instead for 
Did you mean: 

LSERDY is not ready when boot after power off in VBAT mode.

Tinnagit
Senior II

I had use VBat with external low frequency OSC for RTC which it's can run fine even reset has occurred.

But it's has problem when it was boot from power off with VBat.

it's going to TimeOut error while checking LSE state in RCC initial.

/* Check the LSE State */
      if (RCC_OscInitStruct->LSEState != RCC_LSE_OFF)
      {
        /* Get Start Tick*/
        tickstart = HAL_GetTick();
 
        /* Wait till LSE is ready */
        while (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
        {
          if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
          {
            return HAL_TIMEOUT;
          }
        }
      }

the RCC_OscInitStruct->LSEState is set so it go to waiting RCC_BDCR_LSERDY was set but RCC_BDCR_LSERDY is not set even I try to extent RCC_LSE_TIMEOUT_VALUE, it's not matter.

only way I can do is power off it and remove a battery for a while.

And add a battery again then I take power on for it.

the system clock will go fine again.

I have no idea why LSE clock boot fail in VBat Mode but It boot fine without VBat Mode

this is my RCC config which it has nothing special.

the Error is in HAL_RCC_OscConfig(&RCC_OscInitStruct), that 's too early.

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  RCC_CRSInitTypeDef pInit = {0};
 
  /** Configure the main internal regulator output voltage
  */
  HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
 
  /** Configure LSE Drive Capability
  */
  HAL_PWR_EnableBkUpAccess();
  __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH);
 
  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE
                              |RCC_OSCILLATORTYPE_HSI48;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
  RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1;
  RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
  RCC_OscInitStruct.PLL.PLLN = 8;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Enables the Clock Security System
  */
  HAL_RCC_EnableLSECSS();
 
  /** Enable the SYSCFG APB clock
  */
  __HAL_RCC_CRS_CLK_ENABLE();
 
  /** Configures CRS
  */
  pInit.Prescaler = RCC_CRS_SYNC_DIV1;
  pInit.Source = RCC_CRS_SYNC_SOURCE_LSE;
  pInit.Polarity = RCC_CRS_SYNC_POLARITY_RISING;
  pInit.ReloadValue = __HAL_RCC_CRS_RELOADVALUE_CALCULATE(48000000,32768);
  pInit.ErrorLimitValue = 34;
  pInit.HSI48CalibrationValue = 32;
 
  HAL_RCCEx_CRSConfig(&pInit);
}

Thank You

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, it's too complicate.

I had 5 boards and it's only single one it can solved by cleaning a PCB by solvent.

And the other board, they are not work fine.

So I think that I have to re-design this board with very restrict to follow AN2867

Oscillator design guide for STM8AF/AL/S, STM32 MCUs and MPUs - Application note

And if it's work fine that I will update later.

View solution in original post

7 REPLIES 7
JPeac.1
Senior

If the LSE is running, with a crystal, at the point where you shut down the main power then the LSE should continue to run as long as VBAT provides power. What kind of battery is connected to VBAT?

If LSERDY is not set after restarting, then the RTC and VBAT have failed in some manner. You should not have to wait for LSERDY if the LSE continued to run from VBAT. Assuming the RTC and LSE work correctly with main power then the problem may be with the type of battery or how it is connected to VBAT.

If you have an oscilloscope, you can verify the LSE is running by checking the LSE pins on the STM32 while main power is off. You should see a 32.768KHz waveform. If not, you have a hardware problem (unless you turn off the LSE as part of a shutdown procedure). What voltage do you see on VBAT with main power off?

Jack Peacock

I had use CR2032 for VBat

I think that it maybe about PCB Layout but it just maybe, I'm not sure that I need to prove it by check OSC signal with Oscilloscope later.

But I don't think a LSE design guide is very strict that I think it should be good enough to operate.

and I had check a power supply that it work fine.

I have to find out what is the root-cause.


_legacyfs_online_stmicro_images_0693W00000bjsEZQAY.png

Tinnagit
Senior II

it was solved by solvent.

clean it and it work fine.

Sarra.S
ST Employee

Hello @Tinnagit​,

Could you explain what solved your problem? so it can be benefic for other users facing similar issue

Thank you!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Ok, it's too complicate.

I had 5 boards and it's only single one it can solved by cleaning a PCB by solvent.

And the other board, they are not work fine.

So I think that I have to re-design this board with very restrict to follow AN2867

Oscillator design guide for STM8AF/AL/S, STM32 MCUs and MPUs - Application note

And if it's work fine that I will update later.

After that... I had check that it's about LSE Clock Source.
so I had don't use LSE Clock Security System (CSS) - Disable CSS in CubeMX Clock configuration.
(don't have this line in RCC)

 

HAL_RCC_EnableLSECSS();

 

and it can boot fine. this problem is gone.
a necessary stuff to program the firmware to controller please remove Battery backup before start program it and attach it after testing that it can boot fine.