Upload to Mega2560 fails

Hello! Have problems with uploading the following simple sketch to my Mega2560 R3. Can anyone try it on different Mega2560 boards?

Used Arduino IDE 1.6.1, Windows 7. Ardino IDE stucks during upload via avrdude.exe. Arduino IDE 1.5.8 works good and sketch loads to the board. The command line is C:\Program Files Portable\arduino-1.6.1/hardware/tools/avr/bin/avrdude -CC:\Program Files Portable\arduino-1.6.1/hardware/tools/avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM13 -b115200 -D -Uflash:w:C:\Users\Garrison\AppData\Local\Temp\build2779919054098704581.tmp/Blink.cpp.hex:i


bool someF() { if( random( 50 ) > 50 ) return true; else return false; } //> someF(..)

void setup() { pinMode( 13, OUTPUT ); } //> setup(..)

void loop() { digitalWrite( 13, digitalRead( 13 ) == HIGH ? LOW : HIGH ); delay( 1000 );

if( someF() ) Serial.println( "!!!" );

} //> loop(..)

The stuck is actually because of "Serial.println( "!!!" )" line. If I change the text, the sketch uploads successfully to the board. The text which leads to stuck is three or more signs '!'. It all looks very strange...

Hello and welcome,

Yes, the "!!!" is a command that tells the Arduino Mega to start in a sort of debugging mode.

Hi, guix. Never heard about it... What does it mean? Actually the line of code "Serial.println( "!!!" )" is never executed because someF() always returns false. How can it affect process of uploading sketch to the board?

I'm not exactly sure how that happens, but it's it was caused by some code in the bootloader, as you can see here.

Edit: well actually it looks like this bug was fixed, but if you want the fix to be applied on your Arduino, you have to burn the updated bootloader.

Oh, yes, I see... Thank you, guix!

It will be the "!!!". You can't upload that. Ever.