Leonardo upload ~ 8K bytes troubles

Hi

I have problem with uploading about 8K bytes of flash to a Leonardo which should take at least 28K.

When I cut down the size to 6762 bytes it goes fine.

When the size is 7168 or more the program crashes and the serial port is not started. Then I press the reset button and upload works again.

In some way my problem look similar to this: http://forum.arduino.cc/index.php?topic=213013.0 But I guess it is someting else.

I'm using Arduino 1.0.5 on debian testing.

My test-program is below. Any help much appriciated - even if you test the code and don't have any errors running it.

/* TooBig */

static const char text1[] = " GNU GENERAL PUBLIC LICENSE\n" " Version 2, June 1991\n" "\n" " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n" " 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" " Everyone is permitted to copy and distribute verbatim copies\n" " of this license document, but changing it is not allowed.\n" "\n" " Preamble\n" "\n" " The licenses for most software are designed to take away your\n" "freedom to share and change it. By contrast, the GNU General Public\n" "License is intended to guarantee your freedom to share and change free\n" "software--to make sure the software is free for all its users. This\n" "General Public License applies to most of the Free Software\n" "Foundation's software and to any other program whose authors commit to\n" "using it. (Some other Free Software Foundation software is covered by\n" "the GNU Library General Public License instead.) You can apply it to\n" "your programs, too.\n" "\n"; static const char text2[] = " When we speak of free software, we are referring to freedom, not\n" "price. Our General Public Licenses are designed to make sure that you\n" "have the freedom to distribute copies of free software (and charge for\n" "this service if you wish), that you receive source code or can get it\n" "if you want it, that you can change the software or use pieces of it\n" "in new free programs; and that you know you can do these things.\n" "\n" " To protect your rights, we need to make restrictions that forbid\n" "anyone to deny you these rights or to ask you to surrender the rights.\n" "These restrictions translate to certain responsibilities for you if you\n" "distribute copies of the software, or if you modify it.\n" "\n"; static const char text3[] = " For example, if you distribute copies of such a program, whether\n" "gratis or for a fee, you must give the recipients all the rights that\n" "you have. You must make sure that they, too, receive or can get the\n" "source code. And you must show them these terms so they know their\n" "rights.\n" "\n" " We protect your rights with two steps: (1) copyright the software, and\n" "(2) offer you this license which gives you legal permission to copy,\n" "distribute and/or modify the software.\n" "\n"; static const char text4[] = " Also, for each author's protection and ours, we want to make certain\n" "that everyone understands that there is no warranty for this free\n" "software. If the software is modified by someone else and passed on, we\n" "want its recipients to know that what they have is not the original, so\n" "that any problems introduced by others will not reflect on the original\n" "authors' reputations.\n" "\n";

void setup() { Serial.begin(9600); }

void loop() { Serial.print(sizeof(text1)); Serial.print(text1); Serial.print(sizeof(text2)); Serial.print(text2); Serial.print(sizeof(text3)); Serial.print(text3); // 6762 OK //Serial.print(sizeof(text4)); Serial.print(text4); // 7168 bad // Uncomment the line above to crash test delay(500); }

You probably don't have enough ram to hold all that text...

westfw: Good point. It could be a run time error.

So I made another program which send 80 chars in each loop and expecting the buffer to be emtied each time. The result was the same: The program gets uploaded and then it doesnt work.

Actually the USB enumeration goes really bad. First, here is the dmesg output when it is good: [ 4731.463079] usb 1-2: Product: Arduino Leonardo [ 4731.463083] usb 1-2: Manufacturer: Arduino LLC [ 4731.466123] cdc_acm 1-2:1.0: This device cannot do calls on its own. It is not a modem. [ 4731.466150] cdc_acm 1-2:1.0: ttyACM6: USB ACM device

and when it goes wrong it looks like: [ 5755.389273] usb 1-2: Product: \xffffffd0\xffffff89\xffffff89 [ 5755.389299] usb 1-2: Manufacturer: \xffffffd0\xffffff89\xffffff89 [ 5755.392275] cdc_acm 1-2:1.0: This device cannot do calls on its own. It is not a modem. [ 5755.392303] cdc_acm 1-2:1.0: ttyACM6: USB ACM device [ 5755.399308] input: \xffffffd0\xffffff89\xffffff89 \xffffffd0\xffffff89\xffffff89 as /devices/pci0000:00/0000:00:1a.0/usb1/1-2/1-2:1.2/input/input62

Other times it crashes without even writing ttyACM.

Here program 2:

/* TooBig */

int n = 0;

static const char textA[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"; static const char textB[] = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n"; static const char textC[] = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n"; static const char textD[] = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD\n"; static const char textE[] = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n"; static const char textF[] = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF\n"; static const char textG[] = "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\n"; static const char textH[] = "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n"; static const char textI[] = "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\n"; static const char textJ[] = "JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ\n"; static const char textK[] = "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK\n"; static const char textL[] = "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL\n"; static const char textM[] = "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\n"; static const char textN[] = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\n"; static const char textO[] = "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO\n"; static const char textP[] = "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP\n"; static const char textQ[] = "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\n"; static const char textR[] = "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\n"; static const char textS[] = "SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n"; static const char textT[] = "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n"; static const char textU[] = "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\n"; static const char textV[] = "VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"; static const char textW[] = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; static const char textX[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"; static const char textY[] = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\n"; static const char textZ[] = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\n"; static const char texta[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"; static const char textb[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"; static const char textc[] = "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n";

void setup() { Serial.begin(9600); delay(2000); }

void loop() { ++n; if (n==1) Serial.print(textA); if (n==2) Serial.print(textB); if (n==3) Serial.print(textC); if (n==4) Serial.print(textD); if (n==5) Serial.print(textE); if (n==6) Serial.print(textF); if (n==7) Serial.print(textG); if (n==8) Serial.print(textH); if (n==9) Serial.print(textI); if (n==0) Serial.print(textJ); if (n==11) Serial.print(textK); if (n==12) Serial.print(textL); if (n==13) Serial.print(textM); if (n==14) Serial.print(textN); if (n==15) Serial.print(textO); if (n==16) Serial.print(textP); if (n==17) Serial.print(textQ); if (n==18) Serial.print(textR); if (n==19) Serial.print(textS); if (n==20) Serial.print(textT); if (n==21) Serial.print(textU); if (n==22) Serial.print(textV); if (n==23) Serial.print(textW); if (n==24) Serial.print(textX); // 6880 ok if (n==25) Serial.print(textY); // 6986 ok if (n==26) Serial.print(textZ); // 7086 ok if (n==27) Serial.print(texta); // 7192 ok if (n==28) Serial.print(textb); // 7298 ok

ifdef BIG

if (n==29) Serial.print(textc); // 7404 fail

endif

// Uncomment the line above to crash test while (n>30) ; delay(300); }

See reply #1

Use code tags.

You misunderstand. A declaration like "static const char textA[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";" creates a char array IN RAM. (This is because the AVR has a "harvard architecture" which prevents the flash memory from being directly addressable, so all data objects have to be in RAM. On an ARM or PIC32 with some compilers, "static const" would have been sufficient to cause the string to be stored in flash memory. On an AVR, it takes special declarations, and special functions to access flash memory.)

So your 26 strings of 80 bytes each woudl use 2080 bytes of RAM, but the Uno only has 2048 bytes of RAM.

See here, for how to cause your strings to be left in flash only: http://arduino.cc/en/Tutorial/Memory

westfw: Oh, yes, damn. It was the PROGMEM. Thanks.

My original problem was that the upload didn't work. I thought it was this but obviously something else.