GCC optimization -01 creates clocks problems (using Free
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 4:32 AM
Hello world!
I'm working on a real-time synthesizer project since a few years :
- using STM32F427VG
- ST drivers V1.0.0 not HAL (I think HAL wasn't existing in the past)
Everything is working well with optimization -O0.
When I enable optimization (eg -O1) compilation is OK, but after flashing, the STM32 goes mad, clocks are completely wrong and are way to fast. Timers frequencies I configured are OK, but seems that the system core clock is wrong.
I tried to isolate the problem with
#pragma gcc push_options
#pragma gcc optimize (o0)
#pragma gcc pop_options
But same result.
Have you run into similar problems?
- Labels:
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 6:12 AM
Single-step in disasm, and observe, what is written into RCC registers.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 8:39 AM
I too ask same question, i check my project and here CubeIDE create it with -O0 .
???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 9:04 AM
Thanks @Community member​
I compared all the RCC-> values with and without optimization, and the result is the same. ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 9:29 AM
> I compared all the RCC-> values with and without optimization, and the result is the same. ..
Then clocks are the same, too.
Post the RCC values. What is the primary clock source, HSE crystal or HSI? If HSE, what's its frequency?
How do you know that
> system core clock is wrong.
did you output it to MCO and measure? If not, do so.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 9:30 AM
The answer is all the same.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-15 9:41 AM
@jean​ maybe your trouble isnt speed , but variables dont marked as __IO is in -O0 compiled ok, but with -O1.. removed, when values is changed in IRQ.
And why you dont use -Os , that is in gcc recommended
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-16 2:29 AM
Thanks a lot for your answers, I will check everything and get back to you as soon as possible !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-16 5:38 AM
> maybe your trouble isnt speed , but variables dont marked as __IO ...
Which is a common mistake made in this context.
However, I would use the underlying C keyword "volatile" instead, because "__IO" is semantically misleading.
The "__IO" define is commonly used for peripheral registers, which are I/O.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-16 8:05 AM
Yes on most is __IO only alias for volatile. But question is about optimization levels and i can extend Jean question. Today i test my sw with DSI LCD and changing -O0 to any other level create problems on init my DSI LCD display with STM32F469. Any idea here?
