2020-12-15 04:32 AM
Hello world!
I'm working on a real-time synthesizer project since a few years :
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?
2020-12-15 06:12 AM
Single-step in disasm, and observe, what is written into RCC registers.
JW
2020-12-15 08:39 AM
I too ask same question, i check my project and here CubeIDE create it with -O0 .
???
2020-12-15 09:04 AM
Thanks @Community member
I compared all the RCC-> values with and without optimization, and the result is the same. ..
2020-12-15 09: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
2020-12-15 09:30 AM
The answer is all the same.
JW
2020-12-15 09: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
2020-12-16 02:29 AM
Thanks a lot for your answers, I will check everything and get back to you as soon as possible !
2020-12-16 05: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.
2020-12-16 08: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?