Go Down

Topic: Porting code from UNO to LEONARDO (Read 44 times) previous topic - next topic

solar_eta

First let me apologise if this problem should be in Project Guidance

I have a fairly large sketch (28120 bytes flash and 660bytes SRAM free) that works well on a UNO and would appear to be just below the 28672 bytes that you have to play with on a Leonardo.

I want to port this sketch to a Leonardo so that I have a couple more Analog inputs to use. As the analog inputs a re processed with 'for' loops I'll will use a few more bytes of SRAM but the sketch should not get any bigger.

I've tried compiling the existing sketch onto a LEAOARDO and get a sketch too big error It tells me that the sketch now compiles to 30924 bytes! I'm using IDE 1.0.5 and SD fat.

I know that the LEONARDO has built in on chip USB and the code for this takes up some space but I thought that was covered by the 28672 max size.

My question is two fold why the enormous jump in the compiled size and would I solve the problem if I used a serial programmer?

westfw

The Leonardo includes USB code in each sketch to implement Serial.xxx() over the USB port.  That is IN ADDITION to the extra USB code that is present in the bootloader that makes it larger as well.

johnwasser

It might be possible to reduce the size of your sketch with some programming tricks.  If you would like some help with that you should show your code.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

solar_eta

Hi,

 I'm surprised that the compiler adds Serial.xxx() for the USB port when 'Serial' is not called anywhere in the code. I thought that the IDE was clever enough to recognise parts of services/functions/libraries that you didn't use and leave them out of the compiled code.

I don't need 'Serial' so is there a way to stop the wasted extra code from being included?

As for reducing the size I'm not sure that I can take 2.4K out. I've already used SD FAT and IDE 1.0.5 because they produce smaller code than the ordinary SD and 1.0.6. Iv'e also used fixed IP addresses because DHCP seems to add about 3.5K and I've torn the Time.h library apart as I only needed about a third of it. Short of tearing the Ethernet Library apart I don't think I've many places to go. Last time I tried optimising size of code it just got bigger - not much - but bigger. Stopping the IDE adding things I don't need has to be the way.

westfw

Quote
I'm surprised that the compiler adds Serial.xxx() for the USB port when 'Serial' is not called anywhere in the code. I thought that the IDE was clever enough to recognise parts of services/functions/libraries that you didn't use and leave them out of the compiled code.
It's not the Serial.xxx() code itself, but the USB infrastructure that creates the serial port for serial.xxx to use.  This is used to implement things like auto-reset even if the code doesn't use any serial.   There's been some discussion on setting things up to make this easier to omit, but I don't think anything has happened along those lines.


Go Up