Page 2 of 2

Re: Possible Stack Overflow ???

Posted: Sat Dec 08, 2018 8:38 pm
by mnf
- as a possible fix to the interrupt code generated by avr-gcc.

I altered the optimisation level in avra.bat to 3 (instead of 2 in FC7 or s in FC8) -to do this make a backup of avra.bat - you can find its location from 'compiler options') - edit the batch file (right click and choose edit) and change the -Os (in FC8) or -O2 (in FC7) in the first line to -O3 (note do not change the -o %2 %3)

The line should be similar to:
"%~dp0..\bin\avr-gcc.exe" -mmcu=%1 -O3 -ffunction-sections -fdata-sections -funsigned-char -o %2 %3 -lm -Wl,-gc-sections
after editing.
Save the file and reload FC.
(Alternately save the new batch file to a new filename and create a new compiler profile using the new bat file)

This sets the optimisation level of the compiler to maximum.

Recompiling Iain's program seems to give a much optimised interrupt routine. Attached are the lst files with -Os and -O3 optimisation - and the interrupt vector and interrupt routine are combined in the -O3 version. (Note that I have compiled it for the 328p processor here - I don't have a licence for the ATTiny13 in FC8 - however testing for ATTiny13 in FC7 gives a similar improvement).

So - are there any disadvantages to using -O3 over -Os (the gcc docs are at https://gcc.gnu.org/onlinedocs/gcc/Opti ... tions.html)
O3 opt.txt
(14.46 KiB) Downloaded 213 times
Os opt.txt
(15.16 KiB) Downloaded 202 times
Martin

Re: Possible Stack Overflow ???

Posted: Thu Dec 13, 2018 3:52 pm
by Benj
Hi Martin,

There's a nice pros and cons table here for the various optimisation levels.

https://www.rapidtables.com/code/linux/gcc/gcc-o.html

Seems that -O3 takes longer to compile and uses more ROM than -Os but certainly could be handy in cases like this.

On the flip side -O3 seems to have significantly faster code over -Os.

I wonder if there is a way we can add these as an easy to edit option inside Flowcode as most of our compilers are now GCC based. I'll think on it.

Re: Possible Stack Overflow ???

Posted: Thu Dec 13, 2018 10:19 pm
by mnf
An easy to change option sounds good...

As an aside. In v7 it is impossible to change the programmer from within the ide... In the options section, the only choice of .exe files means that the batch files can't be selected...

Martin

Re: Possible Stack Overflow ???

Posted: Fri Dec 14, 2018 10:40 am
by iain wilkie
Hi Guys,

I can confirm that changing the compiler option from Os to O3 cures the original stack overflow problem due to the reduced stack overhead used
in the interrupt routine.

So it might be an idea to have this option easily available from within Flowcode.

Can I also ask if it could be changed to allow easy access to the .lst file from within Flowcode, its such a faff about to have to look at it from
outside flowcode.

Cheers

Iain