STM32L4 clock config problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-05 6:31 AM
Hello there,
I am using STM32L452VET. I have generated the startup code using latest STM32CubeMX 4.22.1. Here is my 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:
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 #debugSolved! Go to Solution.
- Labels:
-
DEBUG
-
RCC
-
STM32L4 series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-06 5:23 AM
Hi
Przenioslo.Lukasz
anddoe.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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-05 6:48 AM
what does your RCC_OscInitStruct look like? Does it define PLL.PLLM? this is a bug in the current CubeMX application.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-05 7:04 AM
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
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-05 8:58 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-02-06 5:23 AM
Hi
Przenioslo.Lukasz
anddoe.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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-30 12:09 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-30 5:24 PM
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 releaseSorry for such inconvenience.
Best Regards,
Imen
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-11-11 8:19 PM
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.
