cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 clock config problem

Posted on October 05, 2017 at 15:31

Hello there,

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

0690X00000608UrQAI.png

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:

MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_ClkInitStruct->SYSCLKSource);

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.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_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.

#optimization #stm32l4 #clock #debug
1 ACCEPTED SOLUTION

Accepted Solutions
Jeanne Joly
Senior III
Posted on February 06, 2018 at 14:23

Hi

Przenioslo.Lukasz

and

doe.john.016

,

Sorry for my late reply.

This issue about 'PLLM is no more generated' is fixed in the CubeMx version 4.23 asmentioned in the Release note of STM32CubeMX

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Frelease_note%2Fb2%2F02%2F4b%2Fe3%2F81%2F32%2F49%2Fc4%2FDM001076pdf%2Ffiles%2FDM001076pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM001076pdf

.

You can upgrade with the latest CubeMX release (version4.24).

Best Regards,

Jeanne

View solution in original post

7 REPLIES 7
john doe
Lead
Posted on October 05, 2017 at 15:48

what does your   RCC_OscInitStruct  look like?  Does it define PLL.PLLM?  this is a bug in the current CubeMX application.

Imen.D
ST Employee
Posted on October 05, 2017 at 16:04

Hello,

This is known bug 

raised internally

and it will be fixed in our next release.

Thank you for your contribution and sorry for any inconvenience it may bring for you.

Kind Regards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on October 05, 2017 at 15:58

You are right. The initialization of RCC_OscInitStruct.PLL.PLLM was missing in the generated code. After adding the line:

RCC_OscInitStruct.PLL.PLLM = 1;

Before the HAL_RCC_OscConfig, everything works. I am wondering why was it working on better optimization levels....

Anyways seems like it is a bug indeed. Thank you very much for help.

Jeanne Joly
Senior III
Posted on February 06, 2018 at 14:23

Hi

Przenioslo.Lukasz

and

doe.john.016

,

Sorry for my late reply.

This issue about 'PLLM is no more generated' is fixed in the CubeMx version 4.23 asmentioned in the Release note of STM32CubeMX

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Frelease_note%2Fb2%2F02%2F4b%2Fe3%2F81%2F32%2F49%2Fc4%2FDM001076pdf%2Ffiles%2FDM001076pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM001076pdf

.

You can upgrade with the latest CubeMX release (version4.24).

Best Regards,

Jeanne

Posted on April 30, 2018 at 19:09

Greetings,

    I still observe this problem with the latest version of CubeMx, version 4.25.  Without a setting for PLLM, the CPU will hang on the call to HAL_RCC_ClockConfig.  Manually adding the line that Lukasz describes still seems to work.  

Posted on May 01, 2018 at 00:24

Hello

Hassan.Ricardo

,

We confirm that PLLM parameter

is no more generate for STM32L4 in the STM32CubeMX

version 4.25

.

It seems to be a regression issue after being fixed in version 4.23 and 4.25 for L4+ (

asmentioned in the Release note of STM32CubeMX

/external-link.jspa?url=http%3A%2F%2Fwww.st.com%2Fcontent%2Fccc%2Fresource%2Ftechnical%2Fdocument%2Frelease_note%2Fb2%2F02%2F4b%2Fe3%2F81%2F32%2F49%2Fc4%2FDM001076pdf%2Ffiles%2FDM001076pdf%2Fjcr%3Acontent%2Ftranslations%2Fen.DM001076pdf

).

T

his bug passed internally for fix in the nextt release

Sorry for such inconvenience.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
mycall
Associate II

I had the same problem. I am running 4.27.0 (latest as of 11/11/2018) and same bug. Seems like such a simple and important thing would have been fixed by now.