Possible Stack Overflow ???

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: Possible Stack Overflow ???

Post 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 231 times
Os opt.txt
(15.16 KiB) Downloaded 223 times
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Possible Stack Overflow ???

Post 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.

mnf
Valued Contributor
Valued Contributor
Posts: 1208
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 440 times

Re: Possible Stack Overflow ???

Post 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

iain wilkie
Posts: 97
Joined: Tue Jul 14, 2009 4:37 pm
Has thanked: 13 times
Been thanked: 9 times

Re: Possible Stack Overflow ???

Post 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

Post Reply