This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to create a steady delay?

Hi,

My application runs on a STM32F103ZE uC. The application needs to light up some indicator Leds for a fixed amount of time just to indicate a correct startup. This amount of time should be system clock (internal SYSCLK signal) independent and also optimization level independent.

As it is a startup indicator it should be a simple mechanism so my first idea is using a simple 'for' loop.

The SYSCLK and internal prescalers AHB/APB1/APB2 are all initialized using '#defines' so I can calculate the internal code execution speed and define a corresponding relative for-loop value from it to keep the loop execution at a fixed speed.

But the optimization level may be of influence.

My question is: how can I disable the optimization (set it to level 0) only for a small piece of code? I mean, after execution of the startup Led pattern the optimization should be automatically set back to the value set by the Project.

Thanks

Henk