cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with LSE on stm32l562xx

as0
Associate II

Hello. I've a problem regarding LSE On stm32l562xx mcu. Sometimes it boots, sometimes it doesn't "90 % of time it generates timeout Error" . and it takes too much time to boot up to 4 seconds. I've tried all your sdk initializations, also tried setting lse drive to all 4 modes but nothing changes. Same behaviour and same time. Below is my initialization code and attached how we connect LSE on our board. Regards

 

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE0) != HAL_OK)
  {
    /*Error*/
  }

  /** 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_LSE|RCC_OSCILLATORTYPE_MSI;
  RCC_OscInitStruct.LSEState = RCC_LSE_ON_RTC_ONLY;
  RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;
  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
  RCC_OscInitStruct.PLL.PLLM = 1;
  RCC_OscInitStruct.PLL.PLLN = 55;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
  RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
  RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    /*Error*/
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  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_DIV1;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    /*Error*/
  }
11 REPLIES 11
Aime
ST Employee

Hi @as0 ,

 

Your configuration seems good, 110 MHz with the PLL_ON based on the MSI clock at 4 MHz.

Can you tell me where is the issue and which function fails?

 

Thank you

Aime

>>I've tried all your sdk initializations..

Perhaps it's the hardware?

Component choices, circuit topology, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
as0
Associate II

This part fails on timeout : "stm32l5xx_hal_rcc.c"  line 724

      /* Wait till LSI is ready */
      while (READ_BIT(RCC->CSR, RCC_CSR_LSIRDY) == 0U)
      {
        if ((HAL_GetTick() - tickstart) > LSI_TIMEOUT_VALUE)
        {
          /* New check to avoid false timeout detection in case of preemption */
          if (READ_BIT(RCC->CSR, RCC_CSR_LSIRDY) == 0U)
          {
            return HAL_TIMEOUT;
          }
        }
      }
 

I've attached an image of how i connect it. It doesn't seem that big deal

Aime
ST Employee

Hi @as0 ,

 

The failing section that you shared comes from the HAL_RCC_OscConfig() function and it seems not related to the LSE anymore.

 

I think that there is a miss part that you forget to mention in the code, because based on how the HAL is written you can not access to this section unless you wanted to active the LSI clock somewhere.

 

The line 699 check that you ask to change the LSI configuration. 

  /*------------------------------ LSI Configuration -------------------------*/

  if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_LSI) == RCC_OSCILLATORTYPE_LSI)

  {

 

At the line 705 the HAL check that you want to activate the LSI

  /* Check the LSI State */

  if (RCC_OscInitStruct->LSIState != RCC_LSI_OFF)

  {

 

Can you confirm it?

Thanks

Aime

as0
Associate II

ah sorry i copied a wrong section i made a new debug session and here is the right section: Line 823

      while (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
      {
        if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
        {
          /* New check to avoid false timeout detection in case of preemption */
          if (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)
          {
            return HAL_TIMEOUT;
          }
        }
      }
 
ticker is fine i checked it. 

Yet it fails to start consistently. The component values are overlaid and unreadable. The trace lengths and load capacitance of the crystal will impact this.

What type of 32.768 KHz crystal? 6, 9 or 12pF ? What value of the capacitors?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

it's 16 pf

Aime
ST Employee

Hi @as0 ,

 

The 16pF value seems a bit higher, to choose a load capacitance value you have to take into account the trace lengths which will increase the capacitance value. There is an application note which register by Microcontroller series all the recommended crystals and load capacitance values, at the table 7. Recommended crystal / MEMS resonators for the LSE oscillator in STM32 products

 

Please make sure that you are inline with the PCB design guidelines for improving oscillator stability.

  •  Avoid high values of stray capacitance and inductances, as they can lead to uncontrollable oscillation (the oscillator can resonate at overtones or harmonics frequencies). Reducing the stray capacitance also decreases startup time and improves oscillation frequency stability.
  • To reduce high frequency noise propagation across the board, the MCU/MPU must have a stable power supply source, to ensure noiseless crystal oscillations. This means that well-sized decoupling capacitor must be used for powering the device.
  • Mount the crystal as close as possible to the MCU/MPU, to keep tracks short, and to reduce inductive and capacitive effects. A guard ring around these connections, connected to the ground, is essential to avoid capturing unwanted noise, which can affect oscillation stability
  • Leakage current can increase startup time and even prevent the oscillator start. If the device operates in a severe environment (high moisture/humidity ratio) an external coating is recommended.

 

Thanks

Aime