Hang during upload (Win7 x86-64)

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
anacreon
Posts: 4
Joined: Mon Jan 16, 2012 1:54 pm

Hang during upload (Win7 x86-64)

Post by anacreon » Mon Jan 16, 2012 2:10 pm

Although I had the BlinkWithoutDelay demo working for a short time, I now can't upload anything to the stick. Now, any upload attempt hangs at around 90%, saying:
Binary sketch size: 4442 bytes (of a 28672 byte maximum)

It sits like this for minutes. If I eventually press the reset button, we see:
avrdude: ser_send(): write error: sorry no info avail

Tried to flash it from a Mac, but then got:
avrdude: stk500_recv(): programmer is not responding

Help!

smarthall
Posts: 6
Joined: Mon Jan 16, 2012 3:24 am

Re: Hang during upload (Win7 x86-64)

Post by smarthall » Mon Jan 16, 2012 9:12 pm

This happens if you have crashed the Atmega with your sketch. What happens is you accidentally crash the chip, or override the timer used for USB. The chip can then no longer respond to the reset packet sent to it just before the Arduino goes to program it.

The best way to get yourself out of this situation is to load the blink sketch in the IDE, then hit the reset button and quickly after click the upload button. This should upload the sketch while the stick is in the bootloader mode (you can tell from the slowly pulsing red LED).

Hope it all works again. :D

anacreon
Posts: 4
Joined: Mon Jan 16, 2012 1:54 pm

Re: Hang during upload (Win7 x86-64)

Post by anacreon » Mon Jan 16, 2012 9:25 pm

I was trying the reset -> upload trick, but the 3-second bootloader window isn't very long. What happens when I hit reset, watching Windows Device Manager, is that the COM4 device is removed and re-added. Until the device reappears, avrdude complains that it can't open the serial port (quite reasonably, as for a short time it doesn't exist).

The problem is that the 3 seconds that the Leostick will wait for input isn't long enough for Windows to put back the COM device. Is there any way of extending the bootloader mode delay from my current situation? Would I have more luck hitting the bootloader mode window on another platform?

smarthall
Posts: 6
Joined: Mon Jan 16, 2012 3:24 am

Re: Hang during upload (Win7 x86-64)

Post by smarthall » Mon Jan 16, 2012 9:32 pm

You could grab someone with a Linux PC, just to get it back to a working state? The three second dtime is plenty for a Linux computer to get it all attached and setup. Increasing the bootloader time requires you to upload an entirely new bootloader (which I dont know if we have the code for yet). To do this you need to solder the 6 pin programming header to the board and use an AVR programmer device. Unfortunately I dont have the equipment here to do this, although if you look around enough you will almost certainly find someone willing to help.

If you haven't sorted it out by lunchtime PM me through the forums and I'll try to meet you and help out. :D

anacreon
Posts: 4
Joined: Mon Jan 16, 2012 1:54 pm

Re: Hang during upload (Win7 x86-64)

Post by anacreon » Mon Jan 16, 2012 9:59 pm

Success! Found someone with a Mac who was able to upload. To avoid future problems, are there tips or techniques to avoid crashing the board?

smarthall
Posts: 6
Joined: Mon Jan 16, 2012 3:24 am

Re: Hang during upload (Win7 x86-64)

Post by smarthall » Mon Jan 16, 2012 10:19 pm

So far, I've noticed the following things:

tone()
Serial.begin()
Serial.write()
Serial.println()
Any of the serial stuff (Use LUFA instead)
The whole Tone library
Playing with timers

And the things that will crash any chip:

Dividing by zero
Using too much stack space

anacreon
Posts: 4
Joined: Mon Jan 16, 2012 1:54 pm

Re: Hang during upload (Win7 x86-64)

Post by anacreon » Tue Jan 17, 2012 12:34 am

Oh, and one large part of the problem is the IDE's bundling of compile + flash into the "Upload" operation. By my rough estimate it takes ~3 seconds to compile BlinkWithoutDelay, which effectively eats up the window of opportunity.

Can I dissociate "Compiling Sketch" from "Uploading"?

smarthall
Posts: 6
Joined: Mon Jan 16, 2012 3:24 am

Re: Hang during upload (Win7 x86-64)

Post by smarthall » Tue Jan 17, 2012 1:20 am

Yes! As long as you are not scared of the command line.

If you hold down Shift when you click the upload button you can see the commands that Arduino is running to put the file on the device. There will be a step where it launches avrdude on the compiled hex file to upload the code to the stick. If you grab this hex file, then run the same avrdude command in a terminal (from the right directory) you should be able to manually perform the upload step yourself.

Maybe keep the hex file around for the simple blink program and write a batch file that does the avrdude upload to easily restore the key. Then you start using the Arduino IDE again.

thingalon
Posts: 2
Joined: Sat Jan 21, 2012 1:30 am

Re: Hang during upload (Win7 x86-64)

Post by thingalon » Sat Jan 21, 2012 1:55 am

Holding shift didn't show the command-line for commands, but I found that turning on verbose output in File -> Preferences did the trick.

From that, I got the following command to run:

Code: Select all

C:\arduino-1.0\hardware/tools/avr/bin/avrdude -CC:\arduino-1.0\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega32u4 -carduino -P\\.\COM3 -b1200 -D -Uflash:w:C:\Users\THINGA~1\AppData\Local\Temp\build6634743744047272416.tmp\BareMinimum.cpp.hex:i
I'm able to run that from the command-line after the LeoStick finishes booting, producing the same hanging effect I get when using the "Upload" button -- but if I run the command during boot, it reports that COM3 doesn't exist yet.

I suspect that Windows takes long enough to set up COM3 as a device, that the unit has finished booting and has already crashed before I can send stuff to it :(

Any ideas?

thingalon
Posts: 2
Joined: Sat Jan 21, 2012 1:30 am

Re: Hang during upload (Win7 x86-64)

Post by thingalon » Sun Jan 22, 2012 12:30 am

Ah, I solved my own problem by using Linux to reprogram my LeoStick.

Windows just does not connect to the device fast enough to catch it before the offending program starts. Using Linux, I was able to install Blink back on the device and all is well in the world.

Post Reply