Problem with the optimizations options

Guest #1172536
Rate this post
• ▲ useful
▼ not useful
I have follow the manual 'ARM Development with Eclipse' but I have a
problem. Maybe you can tell me a clue in order to solve it.

In short, the problem I have is, after having all instaled, configured,
and running, I only can 'blink' a output port if I compile the source
file with the -O1, -O2, -O3 or -Os option in the arm-elf-gcc. If I
compile with the option -O0 (or without entering any -O parameter), the
program seems not to run. And the port doesn't blink.

The compilation and linking have no errors, and I can download the .hex
file in the ARM correctly. But when I run the program, it doesn't work.
Only works when I enter one of these parameters options: -O1, -O2, -O3
or -O. Obviously I don't make any other change.

I have been looking for more info in the internet, without any luck.
Could you help me? Could you tell me some clue if you know about this
problem?

Thank you very very much. I don't know what to do. I want to compile
with no optimization option because I want to use some active wait loops
(you know, e.g. for(i=0; i<100000; i++); )

Best regards from Valencia, Spain.
#1172537
Rate this post
• ▲ useful
▼ not useful
Make sure that your empty-loop counter is declared volatile, otherwise
the compiler may optimise it out. It fixed it here:
http://en.mikrocontroller.net/topic/83014#146546, here:
http://en.mikrocontroller.net/topic/106276#239418 and
here:http://en.mikrocontroller.net/topic/60811#58628

That said, using a loop to implement delays is problematic for this and
many other reasons, all ARM based micro-controllers include timer
hardware which would be a better way to implement timing functions (and
probably consume less power).

Clifford
Moderator #1172538
Rate this post
• ▲ useful
▼ not useful
Vicente wrote:
> In short, the problem I have is, after having all instaled, configured,
> and running, I only can 'blink' a output port if I compile the source
> file with the -O1, -O2, -O3 or -Os option in the arm-elf-gcc. If I
> compile with the option -O0 (or without entering any -O parameter), the
> program seems not to run. And the port doesn't blink.

It's difficult to help without knowing the target and code. "Doesn't
blink" could mean anything. Maybe some delay-loops in unoptimized builds
are that slow that you simple have to wait for "blinking". Do you have
some debugging soft- and hardware? A simple Wiggler-type JTAG-hardware,
OpenOCD and gdb should do.

> Thank you very very much. I don't know what to do. I want to compile
> with no optimization option because I want to use some active wait loops
> (you know, e.g. for(i=0; i<100000; i++); )

As Clifford already pointed out this is not a good approach to implement
delays for "real-world" applications.  But yes, such delays-loops should
work with -O0. But I have never tested this myself without declaring the
counter-variable as volatile (I usualy use -Os or -O2 for my free and
commercial projects). So if you just need the delay-loop use volatile
unsigned long i to declare the counter and keep the optimization
enabled. While -Ox with x>0 and the volatile should get you going the
"doesn't blink"-problem with -O0 might have another reason.

Martin Thomas

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.