AnsweredAssumed Answered

STM32L4 clock config problem

Question asked by Lukasz Przenioslo on Oct 5, 2017
Latest reply on May 1, 2018 by Imen D

Hello there,

I am using STM32L452VET. I have generated the startup code using latest STM32CubeMX 4.22.1. Here is my clock config:

Clock config

My problem is the following:

If I turn switch the compiler optimization flag to either:

  • -O1
  • -O2
  • -O3

The generated clock config works and the program starts.

If I turn the following flags:

  • -O0
  • -Os
  • -Og

The generated program will not work. The problem is with the PLL config part. The program (when debugging) will stop at this line and not move further, the MCU has to be reset:


The SYSCLKSource is 3, meaning it is trying to make the PLL the main clock source. This is called from the  HAL_RCC_ClockConfig function which is located in stm32l4xx_hal_rcc.c file. Here are the parameters:

    /**Initializes the CPU, AHB and APB busses clocks
  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_4) != HAL_OK)
    _Error_Handler(__FILE__, __LINE__);

What could be the problem in here? Why cant the program run when using weak or no optimization?

I would appreciate all help, this is an urgent case for me.

PS: For the clarification, I did not write any code yet, everything is autogenerated from CubeMx.