Hung Sketch - Update Report

A shrunk down Leonardo-compatible board, thumb drive sized with native USB support. [Product info]
Post Reply
Joined:Wed May 09, 2012 4:24 pm
Hung Sketch - Update Report

Post by squirrel » Sun May 13, 2012 11:35 pm

Gday to Marc and Jon

Thanks for your responses and detailed analysis/work and efforts
on my problem.

The upshot is that I have tried Marcs' recovery procedure
and I have tried it every which way to no avail.

If I plug in leostick too soon after the 90% completion point in
the IDE upload phase the IDE can't find the bootloader
COM port and avrdude exits saying NOT IN SYNC
(probably trying to use the wrong port).
If I plug leostick in too late after 90% completion
then I simply get a write error and that's all folks.

I simply can't find the balance point here in a very complicated
juggleing act. It is like trying to hit a moving target
or asking a one legged man to jump a 20 foot ditch !
Marc is probably younger and faster than me anyway.

The IDE picks up the COM ports as they become available
( which begs the question that it is taking
windows XP sp3 at least 6 seconds anyway to
delete/readd the device after leostick is
inserted [or reset applied] !?)
automatically anyway so instructions
5 to 7 in the procedure are a little confusing
and if you are saying that I also have extra time
to select the bootloader COM port in tools
while I do everything else then I am
simply baffled !

How did you make it work ?
Which version of windows did you use ?

The confusing thing is that right now
if I insert leostick the IDE tools tells me
that the COM port is number 3 (but NOT selected or ticked ?).
Then after the bootloader window has elapsed
the IDE is telling me that the tools COM port
is now number 5 and that this port is now
selected (ticked) ?

Can you tell me what I am doing wrong ?
I am trying to follow your procedure but I just can't seem
to make it work.

Life would be much simpler
if we could just tell avrdude ( or something maybe an ISP ?)
to erase the offending sketch page in the mcu
instead of having to use the bootloader
to overwrite it.
( instead of all this bootloader window riggermarole ).

I may need access to an ISP to fix this ( usbtinyisp ? )
or maybe Linux is the answer (not my strong point and a lot of work installing/setting up etc)
BUT if Linux only adds 2 seconds to our bootloader window
of opportunity then is it really going to work or be worth the trouble ?

This Leostick is really a complex beastie especially when it comes to recovery.
No doubt you have heard of the game of Twister.
Well that is what my head feels like now after
all the hours I have already put in on this (spinning and twisted into a mess) ?*O(

One more thing, the arduino IDE shows Freetronix Leostick as the selected
board under tools whereas Device Manager is showing Arduino Leonardo against the COM port.
Is this a problem ?

That's all for now.

I'll get Linux running on one of my other systems
and get back to you. I will need help
getting the IDE installed and set up etc..
I will have to download the Linux stuff to my XP system
and transfer the files to a thumb drive etc..
I probably won't be able to set up Internet access
on the Linux machine as I am using Telstra Bigpond
ADSL (2 wire gateway modem uses USB or ethernet) and doing all the
network stuff is out of my league
(too complicated - unless Jon knows how to set it up).

Any suggestions you can offer while I go at this will be
very welcome ( like which Linux distro do you recommend ?
I have Red Hat and a few others - I could download Ubuntu etc).

chou for now

Joined:Wed May 09, 2012 4:24 pm

Just a few more thoughts

Post by squirrel » Mon May 14, 2012 4:45 am

Marc ( nice to know you - I am also a mark BUT with a k )

Just a few more thoughts/observations with what is going on with this Leo Stick.

1. I get a device manager screen up with the COM & LPT section showing.
2. I plug in or reset my Leostick.
3. Freetronix leostick COM3 shows on the device manager display.
(we are now in the 3 to 7 second bootloader window with red rgb led pulseing nicely)
4. The bootloader window ends and bootloader jumps to the bad sketch.
( we now only have the blue power led showing which goes to high intensity.)
by the way sometimes at this stage the red rgb led also stays on (solid) ?
possibly demonstrating that the sketch is failing in more than one way.
5. The device manager now displays Arduino Leonardo COM5.

6. The tools/serial port list in the IDE finally settles on COM5 ticked.
(in the bootloader period the tools list shows COM3 but unticked).

7. I am assuming that the bootloader generates the Freetronix leostick
COM port identification and the script is generating (before it crashes)
the Arduino Leonardo COM port identification ?
Does anything sound wrong at this stage ?

8. I understand what your procedure is getting at.
We somehow have to be able to select COM3 in tools/serial port
BEFORE the 3 to 7 second bootloader window elapses
BUT how to do this because sometimes COM3 shows up in tools
and sometimes it DOES NOT ! (so how can you select it ?)

I have tried and even though I get what you are saying
I can't make it work.

So here we go again :

1. I plug in Leostick.
2. 3 seconds elapse before windows recognises the stick.
3. The IDE sees tools/serial port as COM3
BUT generally I have no time to get upload to 90%
where I am supposed to select COM3
and the IDE comes up COM port not found
or generally won't let you select COM3
as it isn't on the list anyway
and pretty soon time is up and the list reads COM5 again !?

If you can see where I may be going wrong please let me know.

This thing has got me totally bamboozled.
(like playing pig in the middle or russian roulette [OK with rubber bullets !])

Going the Linux route is a lot of work for me ( Linux install (maybe downloads)
IDE setup etc etc) and I will avoid it if possible.

Your approach is intrigueing me. It sure is a tough way to have to recover
something like this.

Maybe we can make it work in windows ( XP sp3 ) ?

I will try anything before going to Linux
for obvious reasons. ( an extra 1 to 2 seconds of bootloader window ?).

chou for now

Joined:Wed May 09, 2012 4:24 pm

Re: Hung Sketch - Update Report

Post by squirrel » Mon May 14, 2012 5:24 am


After I insert/reset (start) leostick the system takes 3 seconds to identify
Freetronix leostick COM3 OK ?

So if I fire up leostick and count 3 seconds I am in bootloader zone
where COM3 is available to windows and the arduino IDE, OK ?
At this stage COM3 is sometimes listed in tools/serial port
BUT not always (strange ?).

After I count 3 seconds (after I start leostick) then I hit upload
BUT pretty soon bootloader time is up and the sketch
is running and avrdude quits saying NOT IN SYNC
every time.

1. The IDE does NOT let me select COM3 !
2. I can't see how it is possible to align the 3 to 7 second window
with the upload phase of the IDE ?
( first compile runs and wastes plenty of time)

I am sure if you look at what you did to make things
work you could analyse your procedure down further.

The timing is critical and I don't think there
is much room to move at all (or get anything wrong).

Think about it a bit more. I am sure you can show me what
I am doing wrong time wise etc..

chou again

Joined:Wed May 09, 2012 4:24 pm

new developments

Post by squirrel » Mon May 14, 2012 9:05 am

Marc and Jon

I have been working on a different approach to uploading
a sketch to the leostick as so far your procedure
for juggleing the arduino IDE upload phase
with the bootloader timing has simply not been working
( as apparently it did for marc when he tried it).

There may be another way and I could be close
to cracking it.

I have set up avrdude in a DOS batch file ( and it works but not yet to full success)
and avrdude does allow me to select the COM port I want straight up.
So now I can eliminate the timing deadlock and wastage/padding
by sidestepping the compilation process and going straight
to the hex file upload.
I plug in leostick or apply reset and count 3 seconds
then run my avrdude batch file
and HEY PRESTO No more processing hangup !

I am running avrdude in verbose mode and I can see that it is now
running more fully and finally flashing a hex file to the mcu (BUT failing the final verify mode)
BUT initially avrdude could not find the input hex file or directory
I had specified (blink hex file path from IDE verbose avrdude upload).
I think this is happening because the IDE uses a temporary directory
for compile build and deletes everything after it is finished with avrdude.
i.e. I cannot find the Blink.cpp.hex file anywhere on my XP hard drive.

The next thing I did was to use a hex file from somewhere else
( don't panic because the avrdude flash didn't work and failed final verify
so I'm still at base 1 ).

I don't know how to locate the hex file for blink
on my system. I don't think it exists because
the IDE must be deleting it after avrdude completes.

SO the following may just work.

If someone can email me the hex file for Blink then
I can get my batch file avrdude to use that !

This could work ( excited ) !

My email is

If not I would then have to work out how to run the gcc compiler
first in another batch file to generate the hex file we need
and this process is even more complicated
than using avrdude commands in a batch file.

Here is another interesting thought.

What if we flash another copy of the Leostick bootloader
to the bad sketch page in the mcu via avrdude
THEN you will have 2 bootloader windows as the first bootloader
will transfer to the second after the 1st window elapses.

Could that possibly work ?

That's all for now.

Please email me the blink hex file
( or the leostick bootloader hex file ) as soon as you can
if this rationale looks OK to you otherwise please post and let me know
what you think.

again chou

Joined:Wed May 09, 2012 4:24 pm

Oh Dear ! Latest News

Post by squirrel » Mon May 14, 2012 4:55 pm

Marc and Jon

I have been running avrdude from dos batch file and when done this way
avrdude does not hangup and cease operations but proceeds and does everything expected.
BUT it still seems to be failing the final verification of the mcus flash rom
i.e. the new page as written
( could this indicate a damaged area in the flash rom memory in the new page ? ).

So I am assuming that as final verification does not happen
so the final flash update also is not applied ?
So the sketch page should not have been overwritten yet.

Doing things this way with avrdude in batch mode
is a lot faster and all I have to do is plug in the leostick,
count 3 seconds for windows to recognise it ( Freetronics leostick COM3 in
device manager ) and away avrdude goes to full completion
(more or less) EXCEPT right now I am not getting beyond the
final verification of flash. I could use the -V Do Not Verify
option but we don't want to do that do we ?


The bootloader still seems to be intact and runs from insertion/powerup/reset
as expected BUT now the USB/serial code in the bad sketch seems
to not be working at all because after the bootloader window elapses
and control is given over to the bad sketch I get a
USB DEVICE NOT RECOGNISED message from windows and Arduino Leonardo COM5
no longer is added to the COM & LPT device manager display ?

The code in the offending sketch page is now most likely
totally screwed whereas before I think the usb/serial
code there was at least working to produce the
Arduino Leonardo COM5 identification in device manager.
The blue power led was always settleing on high intensity
before but now settles on low intensity ?

Something seems to have changed but as far as I know
avrdude has updated NOTHING yet successfully.

I am sorry BUT trying to recover the leostick mcu
with the arduino IDE does not work as advertised folks.
The timing/balanceing act set out in Marcs'
procedure is basically a nice idea BUT a nightmare
to effect in a reliable fashion.

There should be a more reliable/successful approach
provided which I know there will be (over to you guys).
I am hoping the new arduino v1.01 IDE will be much faster
(it will need to be).

I have to say that if you advertise something
as being Windows/MacOS etc compatible
then you should really verify this
before you let people think
that something is going to work with that software.

So far this system has been VERY difficult
to use and so far impossible to program.

I have spent I don't know how many hours (days) already on this
and still have something that does nothing usefull.
I will not be bothering to even try to attempt
running the gcc compiler from a batch file due
to the time needed to create the batch file/set it up
and debug it etc..

I could still use one of those .hex files to try out that other
idea with avrdude. If avrdude keeps running across the
failure to pass the final verification then why might that be ?

Setting up a Linux box is going to take me hours
and hours of work not including setting up the arduino IDE
etc.. This is all taking too long folks
to what ? load a Blink sketch and flash a rgb led on and off ?
(very tired and losing patience).

The best solution may be just someone reprogramming the
stick ( via ISP I guess ) and getting it back into
off the shelf status so I can start again.
( if I then again have to set up Linux to upload sketches successfully
I will then look at that option).

Can I put my leostick into a jiffy bag and mail it to you guys
so you can reprogram it and get it back to me ?
I will cover the costs/jiffy bag etc of the return mail
(if you want to charge me for reprogramming then that's fine

Please post as soon as you can and let me know.

thanks again


Freetronics Staff
Freetronics Staff
Joined:Sat Oct 15, 2011 12:54 pm

Re: Hung Sketch - Update Report

Post by marc » Wed May 16, 2012 2:44 pm

Hi Mark,
This is a quick late night catchup on this post so please excuse the short post,
absolutely, we're happy to not only reprogram your board by ISP, but also send you a bonus if you like too!
Can you please email us or PM me your shipping address and contact details? '

Joined:Wed May 16, 2012 8:47 pm

Re: Hung Sketch - Update Report

Post by Carnes » Wed May 16, 2012 8:58 pm

I have had a little experience with this as well. It is fixable though.

Problem: The Arduino ide won't let you select the com port except during a short window.
Solution: The key to getting it selected is clicking the leostick reset button every second or so to keep it as a recognized arduino device. Once it is selected, it will remain even after unplugging the leostick.

Problem: avr dude time-outs and stuff during upload.
Solution: Pre-verify your sketch first. Press upload on the ide, press reset on the leostick. If the compile takes a while, press the leostick reset again. Once the upload begins, it will prevent the leostick from moving past the upload stage. You have now reprogrammed the leostick : )

This is using windows 7, Arduino IDE 1.0 (with leonardo uncommented), and of course the Leostick.

Post Reply