Pages: [1]   Go Down
Author Topic: sketch limit size  (Read 969 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'have taken this error so many times?

Code:
Binary sketch size: 3414 bytes (of a 14336 byte maximum)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13718
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is not an error, it states that the size of the sketch you made is smaller than the amount of Flash memory available.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how can we fix it?
Logged

Portugal
Offline Offline
God Member
*****
Karma: 6
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is not an error, it states that the size of the sketch you made is smaller than the amount of Flash memory available.

Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Weird people...
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 127
Posts: 8519
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how can we fix it?
If you don't compile your program you won't get that message...problem fixed.
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how can we fix it?
...don't compile ...

Or...

You could paste the following into setup()  5461 times:
Code:
   asm("nop"); // Two bytes worth of doing nothing except burning a clock cycle

Then the compiled sketch size will be equal to the maximum.



Regards,

Dave
« Last Edit: April 27, 2011, 10:50:48 am by davekw7x » Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
asm("nop"); // Two bytes worth of doing nothing except burning a clock cycle

Unfortunately it would be more than that wouldn't it? - Have you accounted for all of the other rubbish automatically added in?
Logged

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...it would be more than that wouldn't it? ...

Well obviously my post was made with sardonic intent, and I haven't actually inserted 5461 no-ops into anything to make the code size larger.

However, since you brought it up:

Ummm---What extra rubbish?

A nop instruction consists of one word of all zeros.  When I put the asm("nop") instruction in a given program, the program ends up with two more bytes in the text section and no other stuff that I can see.

Am I missing something?  I mean, there are certainly some mysterious things (waiting to bite us in the butt) in the demimonde that we call Arduino, but people have been known to use no-ops to give sub-microsecond delays right?  Do we really have to worry about a bunch of extra rubbish?



Regards,

Dave
Logged

Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well obviously my post was made with sardonic intent, and I haven't actually inserted 5461 no-ops into anything to make the code size larger.

I have, and it only took a couple of minutes!  smiley-grin smiley-grin smiley-grin

I copied and pasted 5461 lines of asm("nop");. It gave:

Quote
Binary sketch size: 11368 bytes (of a 30720 byte maximum)

Onions.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Binary sketch size: 11368 bytes ...

My sarcastic comment was about inserting no-ops in the setup() function of a given sketch.  What was the sketch size before you pasted in the no-ops?


Regards,

Dave
« Last Edit: April 27, 2011, 01:59:22 pm by davekw7x » Logged

Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Binary sketch size: 11368 bytes ...

My sarcastic comment was about inserting no-ops in the setup() function of a given sketch.  What was the sketch size before you pasted in the no-ops?


Regards,

Dave

It was 450 bytes. The code was:

Code:
void setup(){

[lots of no-ops]

}

void loop(){}

Without all the no-ops, the basic code compiles to 450 bytes.
On a more serious point, I am very interested as to how the no-ops function works. I have never heared of the asm() function before, and a google search reveals the American Society for Microbiology. What is it meant to do?

Thanks, Onions.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 7
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...
Binary sketch size: 11368 bytes ...It was 450 bytes.

Count again.  I'm betting that you inserted 5459 no-ops, not 5461.  (450 + 2*5459 = 11368)

Since we are being silly, I pasted exactly 5461 no-ops into the setup() function of the Blink example sketch.

Original size was 990 bytes.  With 5461 no-ops, the size is 11912 bytes.  (990 + 2*5461 = 11912)

With an empty sketch like yours, the size went from 428 bytes to 11350 (428 + 2*5461 = 11350)

Note that small differences in absolute code size (428 bytes contrasted with 450)  are undoubtedly due to different compiler versions, but the important thing (if anything in this thread---up to this point---can rightly be called important) is that each no-op increases the sketch size by exactly two bytes, as I previously claimed.  No extra junk that I can see.

Quote from: Onions
On a more serious point, I am very interested as to how the no-ops function works. I have never heared of the asm() function before, and a google search reveals the American Society for Microbiology. What is it meant to do?

The asm() function is not a standard C (or C++) library function.  It is supplied by the compiler/library vendor to allow programmers to insert assembly language instructions in the middle of their C programs.  You can read about it here: avr-libc: Inline Assembler Cookbook

The no-op instruction itself does exactly what its name implies: Does not affect the state of the CPU, i.e. it doesn't change contents of memory or registers or change flags or anything else.  It has to be fetched from memory, like all other instructions, and it takes exactly one clock cycle to fetch the instruction and do nothing else.

What is the asm() function good for?  Well, sometimes people think they are smarter than the compiler and they use asm() stuff to force certain instructions to be executed rather than trust the compiler to create assembly code that is as tight as it can be.  (Sometimes they are even right!)

What is the no-op instruction good for? Well sometimes people need to fine-tune the timing of their programs for various real-time purposes.  For example the SD library uses no-ops in a couple of places to make sure that external setup and hold times are met for certain of the SPI data transfers.  I have used no-ops in assembly language programs where I needed to equalize delay times between different branches of a routine that was generating symmetric waveforms

Stuff like that.


Regards,

Dave

Footnote:
Since the asm() function is not a standard C or C++ library function, its actual syntax requirements may change.  I experimentally determined that the simple form that I showed works for me in this test.  If I were going to use this seriously, I might use the form shown in the avr-libc reference that I gave (which is the form that is used in Sd2Card.cpp in the utility directory of the SD library).
« Last Edit: April 27, 2011, 05:08:17 pm by davekw7x » Logged

Newcastle, England
Offline Offline
Sr. Member
****
Karma: 3
Posts: 489
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks davekw7x!

It makes sense now. It is interesting to hear that the no-op actually has a use, and I will remember it for any future codes that need it. That assembly language is complicated - I like it!

Thanks!
Onions.
Logged

My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) smiley-grin

Pages: [1]   Go Up
Jump to: