Bricked the 32U4 - Arduino part - recovered

I spent the day working on using Eclipse to develop for, and load code into the 32U4 part of my YUN. Using an external (to Eclipse) Windows batch file, (and a lot of help from the good people who watch this forum), I did:

  1. Open the virtual com port for the Arduino. (COM6 in my case)
  2. Set baud rate to 1200bps
  3. Close the port.
  4. Wait 5 seconds. (In which time the COM6 port disappears, and a COM7 port appears, for uploaded code)
  5. AVRDUDE - upload the hex file with my code.

All appeared to work, and I got a success message from AVRDUDE. Then the COM7 port disappeared. Then... NOTHING.

Even unplugging, and restarting the Arduino failed to produce anything. The 32U4 part of the Yun was dead. I had somehow scrubbed the bootloader. I don't know how, yet, but I will find out, and post here. In the meantime, just in case it's ever of any help to anyone, here's how i recovered it.

  1. I Fired up the Arduino IDE, and wrote a trivial sketch, to write Hello to the Serial port. Turn on Verbose output for compilation, and compiled the sketch. I could then see where the output .hex file lived.
  2. I connected to the Yun over WiFi, using WinSCP, and uploaded the hex file for my sketch to /etc/arduino/base.hex
  3. I opened a telnet session to the Yun, changed to /usr/bin
  4. Ran "merge-sketch-with-bootloader /etc/base.hex"

This adds the 32U4 bootloader code with the small sketch, producing a modified base.hex

  1. Finally, "run-avrdude /etc/base.hex", which flashes the Yun 32U4 with the bootloader and the simple sketch.

That's it. I have no clue how run-avrdude gets code onto the 32U4. I would love to hear from anyone how it works. But it does work.

Now to find out how I screwed it up in the first place.

Con

run-avrdude is a bash script that puts to 1 gpio #21, thus opening the gpio connection from ar9331 to 32u4, mimicking an external programmer, then it runs the real avrdude specifying the linuxgpio "programmer", finally it closes gpio #21

That's why you need to call merge-sketch-with-bootloader: you're reflashing the 32u4 just as you do with an external programmer

I also somehow bricked the 32U4 on my Arduino Yun.
The steps described above didn't totally work for me (i am on OSX, and the path you mention /etc/base.hex is not correct, should be /etc/arduino/base.hex as you point out in the step before). Also, i didn't use telnet but SSH (since it's OpenWRT based, works fine). Thanks a lot for posting this, i was able to unbrick it also :slight_smile:

For anyone else who needs to figure this out (and perhaps myself if i google this in the future :P) here are the steps i took to fix it.

[edit: i replaced the local ip-address by 'arduino.local', which should also work for you if your computer is on the same network as the Yun, either by ethernet or wifi]

SYMPTOMS:

  • In the Arduino IDE, under TOOLS -> PORT, there are no /dev/tty.usbmodem411 and /dev/cu.usbmodem411 showing up
  • TX/RX/L13 LEDs on the Yun board are not blinking
  • Same thing happens if you try on different computers

CAUSE:
32U4 Serial communication is bricked

SOLUTION (on OSX, other OS are similar):
1. Download the following file: Dropbox - File Deleted - Simplify your life and leave it in the Downloads folder.

OR compile your own (based on below code), and locate the compiled .hex file:

#include <SPI.h>
#include <Bridge.h> 

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

void loop() {
  Serial.print("Hello");  
}

2.
Make sure the Yun is connected to your Wifi network, or connect to the Arduino-Yun-XXX wifi network.

3.
Open the Arduino IDE and under TOOLS -> PORT select the Arduino Yun on the network. In the bottom right corner you can see the IP-address of the Yun. Write it down.

4.
Start the Terminal application on your Mac, and type the following (replace the ip-address with your Yun's ip as written down in the previous step):

scp ~/Downloads/unbrick_32u4.hex root@arduino.local:/etc/arduino/base.hex

It will say something like this, just enter 'yes' and press ENTER:

The authenticity of host 'arduino.local (192.168.240.1)' can't be established.
RSA key fingerprint is 45:31:f5:b8:a1:4e:3e:18:cd:da:fc:e2:c5:ca:68:8d.
Are you sure you want to continue connecting (yes/no)? [b]yes[/b]
Warning: Permanently added 'arduino.local' (RSA) to the list of known hosts.

It will then ask you for your password (default = 'arduino'):

root@arduino.local's password:
unbrick_32u4.hex                                                        100%   28KB  28.1KB/s   00:00

5.
Then, type the following command in your Terminal (again, replace with your own Yun's IP-address):

ssh root@arduino.local

and again enter your Yun's password and press enter:

root@arduino.local's password:

6.
If will show you the Linino shell:

BusyBox v1.19.4 (2013-08-07 16:16:02 CEST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

      ___                   ___                       ___           ___
     /\__\      ___        /\__\          ___        /\__\         /\  \
    /:/  /     /\  \      /::|  |        /\  \      /::|  |       /::\  \
   /:/  /      \:\  \    /:|:|  |        \:\  \    /:|:|  |      /:/\:\  \
  /:/  /       /::\__\  /:/|:|  |__      /::\__\  /:/|:|  |__   /:/  \:\  \
 /:/__/     __/:/\/__/ /:/ |:| /\__\  __/:/\/__/ /:/ |:| /\__\ /:/__/ \:\__\
 \:\  \    /\/:/  /    \/__|:|/:/  / /\/:/  /    \/__|:|/:/  / \:\  \ /:/  /
  \:\  \   \::/__/         |:/:/  /  \::/__/         |:/:/  /   \:\  /:/  /
   \:\  \   \:\__\         |::/  /    \:\__\         |::/  /     \:\/:/  /
    \:\__\   \/__/         /:/  /      \/__/         /:/  /       \::/  /
     \/__/                 \/__/                     \/__/         \/__/

            _______                     ________        __
           |       |.-----.-----.-----.|  |  |  |.----.|  |_
           |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
           |_______||   __|_____|__|__||________||__|  |____|
                    |__| W I R E L E S S   F R E E D O M
root@Arduino:~#

7.
Type the following commands:

cd /etc/arduino/
ls -la

It should show you the base.hex file in the list.

Then continue with these commands:

cd /usr/bin
./merge-sketch-with-bootloader.lua /etc/arduino/base.hex
run-avrdude /etc/arduino/base.hex

8.
If you've done all the steps correctly, you should have the following output:

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9587
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xD8"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xD8:
avrdude: load data hfuse data from input file 0xD8:
avrdude: input file 0xD8 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFB"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFB:
avrdude: load data efuse data from input file 0xFB:
avrdude: input file 0xFB contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "/etc/arduino/base.hex"
avrdude: writing flash (32748 bytes):

Writing | ################################################## | 100% 8.41s

avrdude: 32748 bytes of flash written
avrdude: verifying flash memory against /etc/arduino/base.hex:
avrdude: load data flash data from input file /etc/arduino/base.hex:
avrdude: input file /etc/arduino/base.hex contains 32748 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 7.88s

avrdude: verifying ...
avrdude: 32748 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

9.
Your Serial Ports should appear again now, and the TX/RX/L13 LEDs on the Yun start blinking again and your 32U4 is unbricked :slight_smile:

Thanks very much for the help! Hope these steps will help someone else also.
Cheers.

Thanks for posting this in such a clear fashion. Lifesaver.

Just for the record: that's exactly what happens when you flash the yun via wifi. If you can reach it with wifi, uploading the blink is THE way to unbrick the 32u4 of the yun
The above procedure should be used if your IDE doesn't show the yun IP address in the Ports menu but you're still able to access it via ssh

So... I have the same problem, but it is just will not get past this bad fuse:

root@ThiefCam2:/usr/bin# run-avrdude /etc/arduino/base.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9587
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xD8"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xD8:
avrdude: load data hfuse data from input file 0xD8:
avrdude: input file 0xD8 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFB"
avrdude: writing efuse (1 bytes):

Writing |                                                    | 0% 0.00s ***failed;  
Writing | ################################################## | 100% 0.06s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xFB:
avrdude: load data efuse data from input file 0xFB:
avrdude: input file 0xFB contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

[b][color=red]avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xcb != 0xfb
avrdude: verification error; content mismatch

avrdude: safemode: efuse changed! Was fb, and is now cb
Would you like this fuse to be changed back? [y/n] y[/color][/b]

(And here it sits).

I also tried it and said "n', but it complete unsuccessfully.

Any suggestions?

See this - Yun suddenly will not upload sketches - #9 by noblepepper - Arduino Yún - Arduino Forum

Also, be sure you're using the latest java IDE available. At the time of writing, it's 1.5.6 http://arduino.cc/en/Main/Software#toc3

Any suggestions for how to fix this if neither Wifi, serial (via screen, etc), nor Arduino IDE can connect to the Yun?

rwaldron:
Any suggestions for how to fix this if neither Wifi, serial (via screen, etc), nor Arduino IDE can connect to the Yun?

Plug in a wired Ethernet cable, and try to access it that way?


There are several methods to re flash the 32U4 in this thread. If you can access the web server at arduino.local (or whatever you named it) or the IP address, at the bottom of the first screen after login there is a button that allows you to load code by uploading the hex file through the web page - lots easier than using SCP and SSH to do it via the command line. I believe the result is the same: the bootloader gets re-flashed along with the sketch.

ShapeShifter:
Plug in a wired Ethernet cable, and try to access it that way?


There are several methods to re flash the 32U4 in this thread. If you can access the web server at arduino.local (or whatever you named it) or the IP address, at the bottom of the first screen after login there is a button that allows you to load code by uploading the hex file through the web page - lots easier than using SCP and SSH to do it via the command line. I believe the result is the same: the bootloader gets re-flashed along with the sketch.

Sorry, not sure why I didn't include that in the list, but that doesn't work either. Assuming I should expect the IP address to appear in the ports list of the IDE? No dice.

You mention using the IDE. Can you access the Yun's configuration pages using a web browser?

TOTAL LIFESAVER! Thanks guys :smiley: