Skip to main content
Visitor II
October 31, 2023
Question

Problem with LSE on stm32l562xx

  • October 31, 2023
  • 3 replies
  • 4751 views

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*/
  }
    This topic has been closed for replies.

    3 replies

    ST Employee
    October 31, 2023

    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

    as0Author
    Visitor II
    November 1, 2023

    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;
              }
            }
          }
     
    ST Employee
    November 2, 2023

    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

    Graduate II
    October 31, 2023

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

    Perhaps it's the hardware?

    Component choices, circuit topology, etc.

    as0Author
    Visitor II
    November 1, 2023

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

    Graduate II
    November 3, 2023

    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?

    as0Author
    Visitor II
    November 3, 2023

    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.