Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world. And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download (registration required) various documents highlighting:

System Workbench for STM32


Brilliant For-loop Bug

Hi Everyone,

I’ve got a brilliant situation in which a second and third ‘for’ is simply ignored when being flashed to an STM32F103C8T6. I call this brilliant because of the obvious looks of a compiler bug or at least some speciality that shouldn’t be there because I’m only re-using the same ‘for’ a second and third time.

So by who and why was the second and third ‘for’ swallowed in the process of compiling and flashing to the STM32F103C8T6?

Please no guesses nor ‘should’ or protocols in your helping since it is a simple c test. Thanks.

The initial template was created with CubeMX, all used pins have been configured and port clocks enabled and of course the system clock configured. If this wasn’t the case not one pin would blink.

The result is that PC14, PC15 and PC13 toggle synchroneously as if the second and third ‘for’ doesn’t exist. It should be step sequencing but it is not. And yes everything was updated, saved and compiled before flashing. I have gone through all necessaties before calling on the forum.

Find screenshot attached.

Good luck!

Greets,
Ben

France

Hi Ben,

Even if I’m just “guessing”, I think even the first loop is ignored by the compiler, and it’s not a bug: your loops have no result at all, and can safely, according to the C standard, be ignored (or replaced by a simple “i = 10000;” assignment, if ever you used i later on (which is not the case in your code).

To obtain a delay in your code by a for loop, this loop must have some visible effect; the simplest way to obtain this effect, and avoids the compiler optimizing your code out (which is definitely not a bug in this case) you should declare i as volatile (volatile int i;) then the compiler will no more be allowed to simply suppress i and all its references...

Bernard


Hello Bernard,

Sounds great. Thanks for clarifying.

The first for is not ignored by the compiler.

I have attached the SW4STM32 project and two video clips showing evidence of this and for you to reproduce the phenomenon at your location.

Before calling your help I also tried rectifying the situation using different variables for each for-loop which didn’t help. I am not sure why the compiler would deem a variable fixed, that’s awkward, especially when used in a variable changing function such as a ‘for’. Under any other circumstances this has never caused me issues. Probably Arduino IDE is to blame for this :-) ... and our good old Microsoft Basic.

I believe there must be a compiler setting in Eclipse for such awkward compiling events to be prevented from happening. If a variable is clarified and a for-loop uses it it is obvious not to be a fixed number just to be stored somewhere. So I think the Eclipse/Plugin compiler optimizations here are rather pedantic and not offering any smooth learning curve for the autodidact. I like to call them quircks that cause forums and helpdesks to clog up.

Greets,
Ben

PS: In the attached video you see the SMD green led (PC13 3.3v to GPIOC_13) and 2 conventional green leds (PC14 and PC15 GND to GPIOC_14 and GND to GPIOC_15) hence the SMD led’s inversal.





France

Hi Ben,

This is exactly what I’ve said in my first answer; the compiler will always try to optimize out all code that has no visible effect; adding some delays is not considered a visible effect as the compiler has no idea about the time taken by any operation, so reducing this time is considered a good optimization (that is the real objective of optimization, isn’t it?).

I have however to investigate why, when i is declared as volatile, the last loop is ignored, as the purpose of volatile is to force the compiler to do all actions requested on the variable, as it may have some side effect...

Bernard (Ac6)