code bloat - cannot compile working MWC for 10dof TRI anymor

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

code bloat - cannot compile working MWC for 10dof TRI anymor

Post by Hamburger »

Hi,
I have one TRI with 328p nano and 10dof FreeIMU 0.35 MS. I use it with LCD for configuration and telemetry.
Over time it has become more and more difficult to create a working binary due to size. The configuration does work with r809 (barely). Now I did some catchup to the current r864 and code size will not load anymore.

My config is nothing out of the ordinary - I post it so you may decide whether MWii should support such combination or if the active decision is made that old hardware+features combination shall be abandoned.

Code: Select all

#define TRI

#define FREEIMUv035_MS

#undef INTERNAL_I2C_PULLUPS

// 2
#define YAW_DIRECTION -1

#define ALLOW_ARM_DISARM_VIA_TX_ROLL
#undef ALLOW_ARM_DISARM_VIA_TX_YAW

#define I2C_SPEED 400000L

// 5

#define FAILSAFE

#define RCAUXPIN12

#define VBAT 
#define VBATSCALE     79 // mystery 20A ESC/BEC, war HK-SS-ESC:78 //79 //110 // mein spezieller Spannungsteiler 3S
#define VBATLEVEL1_3S 102 // 10.2V unter Last
#define VBATLEVEL2_3S 100 // 10.0V unter Last
#define VBATLEVEL3_3S 98  // 9.8V unter Last
#define NO_VBAT       75 // Avoid beeping without any battery

#define LCD_CONF
#define LCD_VT100
//#define LCD_CONF_AUX

#define POWERMETER_HARD
#define PLEVELDIVSOFT 10000
#define PLEVELDIV 1540
#define PSENSORNULL 504


#define LCD_TELEMETRY
#define LCD_TELEMETRY_AUTO "1"
#define VBATREF 24 // 12.6V - VBATLEVEL1_3S  (for me = 126 - 102 = 24)

I must save space by removing even more features

Code: Select all

#undef FAILSAFE 
#define SUPPRESS_TELEMETRY_PAGE_2
#define SUPPRESS_TELEMETRY_PAGE_3
#define SUPPRESS_TELEMETRY_PAGE_4
#define SUPPRESS_TELEMETRY_PAGE_5
#define SUPPRESS_TELEMETRY_PAGE_6
#define SUPPRESS_TELEMETRY_PAGE_7
#define SUPPRESS_TELEMETRY_PAGE_8
#define SUPPRESS_TELEMETRY_PAGE_9


It sure becomes more difficult over time.

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by Tommie »

I'Ve just build your configuration with my branch (including the latest additions and some private ones):

Code: Select all

stefan@exa:~/git/multiwii-firmware [tri…] $ avr-size build/MultiWii.hex 
   text      data       bss       dec       hex   filename
      0     29220         0     29220      7224   build/MultiWii.hex

So it still fits into the 32kB flash.

Enabling size optimization (-Os) in the compiler even yields a smaller result:

Code: Select all

stefan@exa:~/git/multiwii-firmware [tri…] $ avr-size build/MultiWii.hex 
   text      data       bss       dec       hex   filename
      0     27408         0     27408      6b10   build/MultiWii.hex

Plenty of space left.

What are your compiler options?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by Hamburger »

smart guess. In truth I had not looked for that for a long time.

Code: Select all

OFLAG =   -O2
# set -Wno-unused-variable to suppress 'defined but not used'
OPTFLAGS = $(OFLAG) -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder -Wno-unused-variable

I know -Os will produce smaller binary size. Nevertheless, whichever compiler switches we use, the tendency of increasing binary size has been there. If it is for features we want, good. If it comes as unwanted side effects, we have to take care of it. I know Alex did a large step to make code truly conditional with moving WMP & nunchuk support to become dependant on #define.

What I want to point out is we have to do it some more.
Example:
By #ifdef GPS the GPS_whatever variables declarations in MWii.ino (and fixing the occurrences in code likewise), I could save approx. 600 bytes in early r800 versions. Have not checked with latest.

It is a constant struggle we have to be aware of.

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by Tommie »

So just use "-O1" or even "-Os", which will shrink your code to a completely acceptable size. No need for generating a panic, since everything is still small enough to handle it with a ATMega328p.

BTW, I just wanted to give avr-gcc a spin to see whether it generates code of a different size; it however fails while compiling the new code due to a new handling of the PROGMEM attribute. I just fixed and commited my part, but LCD.ino also has a few occurances that make gcc 4.7 blow up.

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by Hamburger »

Tommie wrote:So just use "-O1" or even "-Os", which will shrink your code to a completely acceptable size. No need for generating a panic, since everything is still small enough to handle it with a ATMega328p.


You may not know MWii has already had its 'out of memory' last year. You need not patronize me.

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by kos »

Tommie wrote:BTW, I just wanted to give avr-gcc a spin to see whether it generates code of a different size; it however fails while compiling the new code due to a new handling of the PROGMEM attribute. I just fixed and commited my part, but LCD.ino also has a few occurances that make gcc 4.7 blow up.


cross-avr/gcc-4.5.3-r2

http://www.carlocaponi.it/cgi-bin/blog/arduino

User avatar
UndCon
Posts: 293
Joined: Mon Feb 21, 2011 2:10 pm

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by UndCon »

I think the whole project has become crazy

so many sensors - so many boards - so many LCD options - so many flightmodes


I say keep the core - add functionality for the bigger boards only

If you want GPS - MEGA boards
If you want a Tricopter - MINI boards

If you want LCD RTH POS WTF LOL ROFLMAO features - MEGA boards


//UndCon

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by Tommie »

No. There is no need for a straight cut like this. You _can_ use GPS with a simple ATMega328 (I prefer to use the controller names, because "MEGA", "MINI" or whatever carries no semantic); But you have to be careful about the features you integrate. You cannot use a small controller and have it all, but the selection of the gadgets included should be left to the user.
I am using an ATMega328p (no Arduino or whatever), and I have ACC/MAG/BAROSonar/GPS, a custom I²C camera trigger, a data transfer framework to communicate with my TX and some custom LED stuff; it fits.

User avatar
dramida
Posts: 473
Joined: Mon Feb 28, 2011 12:58 pm
Location: Bucharest
Contact:

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by dramida »

where do i put this declaration?

Code: Select all

OFLAG =   -O2
# set -Wno-unused-variable to suppress 'defined but not used'
OPTFLAGS = $(OFLAG) -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder -Wno-unused-variable

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by kos »

dramida wrote:where do i put this declaration?

Code: Select all

OFLAG =   -O2
# set -Wno-unused-variable to suppress 'defined but not used'
OPTFLAGS = $(OFLAG) -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder -Wno-unused-variable


you have to change some constant in the Arduino IDE CODE ...

User avatar
kos
Posts: 286
Joined: Thu Feb 16, 2012 4:51 am
Location: Fr

Re: code bloat - cannot compile working MWC for 10dof TRI an

Post by kos »

you should add

Code: Select all

--omg-optimized


Tommie wrote:So just use "-O1" or even "-Os", which will shrink your code to a completely acceptable size. No need for generating a panic, since everything is still small enough to handle it with a ATMega328p.


it's not about OPTIMILAZIATIONS, it's about USE flags.

http://funroll-loops.info/

Post Reply