Arduino 1.0.1 and Mega 2560 uploads fail

Upgraded from Arduino 1.0.0 to 1.0.1 today and found uploads started to fail with.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout

This seems to be related to having tight code loops in loop()

For example,

void loop()
{
tightloop:
digitalWrite(pinno, HIGH);
delayMicroseconds(duration);
digitalWrite(pinno, LOW);
delayMicroseconds(duration);
goto tightloop;
}

Yes, code is horrible.
Testing how fast it will go.

Trying to upload any new code fails with the errors above.

The only solution was to downgrade to 1.0.0.


Mac OSX version

You aren't going to get a quality answer because your code has a completly ridiculous and unnecessary use of GOTO.

If you remove the braindead call (because the loop will loop ANYWAY), is there still an issue?

Hmm, it shouldn't matter what code you're trying to upload. Does it happen only if that sketch is already on the board (i.e. can you upload it once)? Does it fail for other sketches (without the goto)?

The goto is not relevant here other than it saves about 4us in the low output time.

You get the same if running loop() code is very short.

e.g.

void loop()
{
if(digitalRead(pinin) == LOW)
dosomethingelse();
}

You can get the download to work by pressing reset immediately when you see Binary sketch size:...

The newer version is much more sensitive to this.

With longer code loops() its more reliable.

Weird. Can you try going into your boards.txt file (in the Contents/Resources/Java/hardware/arduino sub-directory of the application) and changing "stk500v2" (for the Mega 2560) to "wiring"? That should tell avrdude to reset the board before upload (in addition to the reset that's done in the IDE) and might help.

got same prob

The goto is not relevant here other than it saves about 4us in the low output time.

A "while(1)" would do the same, and be less of a flame-magnet. :wink:

Changing the protocol to 'wiring' fixes it.

It works every time now.

while(1) might be slower.

If the compiler is smart enough to output a jump instruction then there is no difference but it might produce a test and jump which would be slower. goto is very ugly and produces a jump.

Not good style I agree but I was seeing how fast I could toggle a pin using standard function calls. :slight_smile:

If the compiler is smart enough to output a jump instruction

I'd put a good sum of money on it.
In fact, it would be my first thought.