Hello.I've been having issues with a program of mine that works perfectly fine while running with optimizations enabled but if I disable it, it doesn't seem to get to main, the only exception being running in debug mode. I have set up the pins using MCUXpresso Config Tools v7, and did not modify any of the generated code except for changing the #pragma push and #pragma pop for #pragma clang diagnostic push and #pragma clang diagnostic pop in the MK22FA12.h header file generated by Keil, as the ARM6 compiler seems not to accept the former.
main
#pragma push
#pragma pop
#pragma clang diagnostic push
#pragma clang diagnostic pop
MK22FA12.h
I have also changed the first line in the scatter file for #!armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m4 -xc (was #! armcc -E) and disabled the "Use Memory Layout from Target Dialog" option in the Linker.
#!armclang -E --target=arm-arm-none-eabi -mcpu=cortex-m4 -xc
#! armcc -E
Using debug mode every optimization setting seems to work fine.
Compiler: ARM V6.13.1
Board: MK22FX512AVLL12
SDK: MCUXpresso 2
IDE: Keil uVision5
I've included a simple project that makes one of the leds blink when it gets to main that reproduces the presented problem. I have tested with all optimization levels and the only one that does not work when I run is -O0*.*It does run, in debug mode only.If anyone could help me, I'd be really glad.
Blink.zip
Hi, have you found a solution? I know it is an older post but i have not found anything similar in the forums. I have a similar problem, when i turn off optimization (-O0) in my simple blinky program for TWR-KE18F, it runs only when in debug. For other optimization levels (-O1, O2, O3 etc.) the program works normally. I tried comparing the generated assembly in .lst files but can't tell where the problem is. I configured the clocks and pinout with MCUXpresso and did not change anything.
Compiler: ARM V6.12
Board: TWR-KE18F
What does the debugger do to make the program run when it otherwise doesn't?
What could the optimization "optimize out" to make the program work?
Hi Dario,
does it work with -O1?
Hi and thank you for reply,
yes it does, however I would like to know why it doesn't work with -O0 especially since the policy at our company is to avoid optimization.
Dario said: For other optimization levels (-O1, O2, O3 etc.) the program works normally.
Dario said:What could the optimization "optimize out" to make the program work?
One reason could be the "distance" between accesses for example to the watch dog.
Does it also stop working if you have the debugger attached? If so, reset your board and then attach the debugger and check where it sits.
Last resort: Add endless-loops and do the above to see where it stops working.
Dario said:the policy at our company is to avoid optimization.
I often see this (strange) policy. Esp. the lower levels (like common sub-expression removal) aren't very aggressive.
The better policy IMHO is: Options for Release version must be the same as for the tested version.
For anyone else that has this problem, this post helped me: https://community.arm.com/support-forums/f/keil-forum/35398/hardcoded-breakpoint-preventing-program-from-runningBasically, the program was getting stuck at SWI breakpoint - BKPT 0xAB inside __ARM_get_argv function. The __ARM_use_no_argv symbol is added automatically on higher optimization levels when compiling with armclang. That is why the program worked when i used -O1 instead of -O0. It also worked in debug mode because it skipped the breakpoint.
Thanks everyone for the help.