cancel
Showing results for 
Search instead for 
Did you mean: 

Bug in STM32CubeIDE/MX RCC clock config? Generated code trying to init LSE but I don't have an LSE nor is there one configured in the clock tree.

Grizz
Associate III

Using an STM32L562Q part: configured the clock tree to use LSI, MSI, and HSI48 internal clocks. Odd that RCC_OscInitStruct.OscillatorType = 0x3C

Code generator is setting RCC_OSCILLATORTYPE_LSE as one of clocks to init but I don't have an external LSE crystal. When main calls the clock config, it executes this code:

 /* Set the new LSE configuration -----------------------------------------*/

  if ((RCC_OscInitStruct->LSEState & RCC_BDCR_LSEON) != 0U)

  {

   if ((RCC_OscInitStruct->LSEState & RCC_BDCR_LSEBYP) != 0U)

   {

    /* LSE oscillator bypass enable */

    SET_BIT(RCC->BDCR, RCC_BDCR_LSEBYP);

    SET_BIT(RCC->BDCR, RCC_BDCR_LSEON);

   }

Code then fails 5 seconds later when the non-existent LSE doesn't come ready:

  /* 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)

    {

     /* New check to avoid false timeout detection in case of preemption */

     if (READ_BIT(RCC->BDCR, RCC_BDCR_LSERDY) == 0U)

     {

      return HAL_TIMEOUT;

3 REPLIES 3
Grizz
Associate III

FYI: As a test, I removed the erroneous RCC_OSCILLATORTYPE_LSE  flag in main.c and the clock tree initialized correctly and my main clock moved to 16 MHz as intended. I've seen the GPIO, ADC1, and RTC peripherals initialize and start up correctly, so it seems the internal and derived clocks are fine. I'm moving on with the SDMMC, SPI, DMA, USB and other peripherals now.

It would be nice to know what shoved RCC_OSCILLATORTYPE_LSE into my generated code. I don't want to have to remember to remove that from main.c.SystemClock_Config() every time the code generator runs again.

Amel NASRI
ST Employee

Hi @Grizz​ ,

Could you please check if the same issue is faced with STM32CubeMX 6.7 or not (latest revision)?

Thanks & Best regards,

Amel

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.

I'm using MX embedded in the STM32CubeIDE. The MX version is 6.7.0-RC2. It still code generates 4 clocks... the low speed external which I don't have/don't use. I'm attaching my Firmware.ioc file in case you find it helpful.

I'm think we might have to manually delete some bogus entry now that it's in the file. It's possible starting over from scratch might not produce the issue, but I'm too far along to start over.

Thanks