cancel
Showing results for 
Search instead for 
Did you mean: 

GCC optimization -01 creates clocks problems (using Free

jean
Senior

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?

9 REPLIES 9

Single-step in disasm, and observe, what is written into RCC registers.

JW

MM..1
Chief II

I too ask same question, i check my project and here CubeIDE create it with -O0 .

???

Thanks @Community member​ 

I compared all the RCC-> values with and without optimization, and the result is the same. ..

> 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

The answer is all the same.

JW

MM..1
Chief II

@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

jean
Senior

Thanks a lot for your answers, I will check everything and get back to you as soon as possible !

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

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?