Author Topic: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase  (Read 12391 times)

0 Members and 1 Guest are viewing this topic.

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
I don't know much about microcontrollers in general, and I don't know much about Atmel microcontrollers or the Arduino platform/IDE.   I've attempted to use Google to search for a solution, but I can't seem to find anything that helps.

I'll try to make a long story as short as possible.  I purcased a used Arduino, with a bad 16U2 (USB interface) microcontroller.   I should have just used it as is, or thrown it away, but I thought "eh, why not.  I'll buy another 16U2 and have a go at fixing it."   I got the new chip installed, and was trying to reprogram it using my USBtiny and AVRDUDE.  (I know about the 6 pin ICSP header for the 16U2)

I barely know how to use AVRDUDE and the USBtiny, but I  have learned a costly lesson. "Erase chip" will indeed erase.    If only I didn't have the "good" Arduino connected at the time.   Stupid, careless, many other applicable adjectives - yes, I know.  So now I have a known good (hardware) Arduino, with a blank 16U2.   

I took a third Arduino, and tried again to read the flash and EEprom from the 16U2.   I created two files, one for the flash, and one for the EEprom, and the "Verify" function said the files were good.  (They matched the third arduino,  Which I've manged to not destroy, so far.)

However, when I attempt to write the flash and EEprom to the bricked arduino,  I get a verification error.   It won't work.

I suspect that I'm not really reading the "good" arduino because the lock bits are set at 0x0F (unmolested, working unit) , while the blank 16U2 is showing 0x3F for the lock bits.   I believe that means the good unit is read-protected.   I don't know however. 

I attempted to find these files on the internet, but all I can find is a "combined" file that is used with atmel "Flip."   "Flip" seems great for firmware upgrades, but since my 16U2 is bricked, it does me no good.

Can anyone help me out of this mess?  Are the files available somewhere?  I've looked and looked and can't find it.  I am horrible at using search engines, so forgive me if they are readily available.   Again, I'm not terribly upset at being out two Arduinos, but because one of them has no hardware problems at all, (was working before I got careless and erased its 16U2) I'd like to undo my mistake for general principles.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
I read at the Arduino site about the process for programming the 16U2 and it mentioned that the .hex file is included with the distribution.  So, I installed the latest and greatest.  Low and behold, there is a file named: Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3 included.

This page may help:

https://www.arduino.cc/en/Hacking/DFUProgramming8U2

All of the above is a guess!  I have never had occasion to do this.
 

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
I read at the Arduino site about the process for programming the 16U2 and it mentioned that the .hex file is included with the distribution.  So, I installed the latest and greatest.  Low and behold, there is a file named: Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3 included.

This page may help:

https://www.arduino.cc/en/Hacking/DFUProgramming8U2

All of the above is a guess!  I have never had occasion to do this.
That would work if I hadn't erased my 16U2 completely.    That page describes using an atmel program called "Flip" that works via USB to program a 16U2 that still knows how to talk to a USB port.  Mine, sadly, does not.   I think need the files I can upload using USBtiny for the Flash and EEprom.  Or, an explanation of what I really do need to do. 
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
"
I suspect that I'm not really reading the "good" arduino b"

I don't know if you have established that the arduino is bricked.

Since you have a standalone programmer, I would try to download a simple blinky and ssee if you can get that going.

Moral of the story: doing nothing when you don't know what you are doing is often the optimal strategy.
================================
https://dannyelectronics.wordpress.com/
 

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
I know it's bricked.   I had the 16U2 ICSP connected to the USB tiny, and accidently used the "erase chip" function of AVRDUDE. Now, when I connect it to my computer,   my computer doesn't even know that a USB device has been connected.  a "good" ardunio loads the driver and appears as as an arduino connected via com port.

Yes, I do indeed wish I had done nothing, but I accidentally erased the 26U2 on a working unit.   I shouldn't have tried to fix the damaged one when I didn't know what I was doing.  I am aware of that.  Now, I'd like to undo the damage I've done.  I'd like to think I can re-program the 16U2, but this is proving difficult.

I'm not sure if I can read another "good" arduino with my USBtiny.   I'm not sure if these are protected.  (I did read that one can perform the "erase chip" function on a read protected chip - but the code will then be gone.  (I know the code is gone - that's why I'm in this mess)

I try to use the read flash and read eeprom functions, and I do get two files, but these files won't write - I keep getting  verification errors.



 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Let me try one more time.

There is nothing magical about the code you erased, as long as you can reprogram the arduino. Because the code you had eerased is readily available and you can always flash it tto your avr, again, as long as you can reprogram it.

So you have to establish that you can no longer reproogra thee avr.

Until then, the game isn't over yet.
================================
https://dannyelectronics.wordpress.com/
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16864
  • Country: lv
What I think, you don't program the fuses, therefore it has no chance to work right.
 

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
I know there's nothing magical about it, but I need to get it.  I can't find it anywhere.  I'm not talking about the ATMEGA328 programs that I would write and upload, I'm talking about the programs in the 16U2 that serves as the USB interface.  (They used to use the FTDI chip, now they use the 16U2 for USB communication) 

I put a brand new, from Digi-Key, 16U2 on Arduino 1.   I was attempting to read the flash and eeprom from ARduino2.  Stupidly, and I know I was stupid, I accidentally erased the 16U2 on arduino 2.    So, I am attempting to read the eeprom and flash from arduino 3.  I do so, and AVRDUDE, with my USBtiny, does give me two files.  When I attempt to write them to Arduino 2,  I get "Verification error"   and the arduino2 fails to function.

If the 16U2 were working, I could use the atmel flip program on the site someone mentioned above to load the firmware (described as "combined" flash and eeprom) but the flip program communicates with the 16U2 via USB.  My 16U2 doesn't communicate via USB anymore.  (because I ereased it.)

I'm not speaking about using the USBtiny on the ICSP for the ATMEGA328 and accidentally erasing it.  I was connected to the 16U2 ISCP header and erased it. 

Sorry if I can't describe the problem properly.   I know I've never done this with atmel micros before, but I figured "how difficult can it be to copy an existing 16U2 on to the new one I just soldered in?"  Well, now I know how bad it can get.  I wish I hadn't tried.  But I did.   This is where my ignorance hinders me.   

Can I copy the firmwear from a working arduino, or do I need to find the files somewhere?  My thought was, that if I have the files, that bypasses any problem I have reading the firmware.   I can't find them.   

 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Try this:

http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/

Seems legit.  As pointed out, its rarely a case of 'permanently bricked', but if you've changed the fuses - especially the SPIEN which disables serial programming via the SPI port - then its just a pain.  But a second AVR (be it in arduino format, or just an atmega88) that you can flash, then you have plenty of options open to you.  If we assume that its fuses are corrupt, has no bootloader, but the SPIEN is still clear to 0 (ISCP SPI port works) then you just need an AVR programmer, and the firmware as a hex - as well as the fuse settings required. 

Given how popular the uno r3 is, I'm willing to bet those are freely available, of not actually packaged with the arduino IDE.
 
The following users thanked this post: wblock

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
Try this:

http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/

Seems legit.  As pointed out, its rarely a case of 'permanently bricked', but if you've changed the fuses - especially the SPIEN which disables serial programming via the SPI port - then its just a pain.  But a second AVR (be it in arduino format, or just an atmega88) that you can flash, then you have plenty of options open to you.  If we assume that its fuses are corrupt, has no bootloader, but the SPIEN is still clear to 0 (ISCP SPI port works) then you just need an AVR programmer, and the firmware as a hex - as well as the fuse settings required. 

Given how popular the uno r3 is, I'm willing to bet those are freely available, of not actually packaged with the arduino IDE.

  I'll study that link.    A quick glance reveals people are re-programming the 16U2.  The question is, are they really putting them back afterward or does everyone just buy another UNO?  I think I scanned it a day or so ago, but couldn't find what looked like the correct files.   Maybe I need a different programmer from the USBtiny.

It'd be great if Arduino had a "burn 16U2" function that does the same thing for the 16U2 as the "Burn bootloader" does for the atmega328.  (EDIT:  I now realize the link Buriedcode posted will create exactly that function.)     I suppose the answer is people aren't supposed to be fooling around with the 16U2 unless they know how to do this manually.    I thought I did.  You'd think doing a "read" of chip A and then a "write" to chip b would make a copy of chip A, but it isn't working and I'm too ignorant to know what's wrong.   Am I not reading the good 16U2?   Have I screwed up some setting trying to write to the erased one?   I thought I knew enough, but a little knowledge is a dangerous thing.   
« Last Edit: May 25, 2016, 11:31:12 pm by Excavatoree »
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16864
  • Country: lv
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #10 on: May 25, 2016, 11:01:19 pm »
You'd think doing a "read" of chip A and then a "write" to chip b would make a copy of chip A, but it isn't working and I'm too ignorant to know what's wrong.   Am I not reading the good 16U2?   Have I screwed up some setting trying to write to the erased one?   I thought I knew enough, but a little knowledge is a dangerous thing. 
I guess you are ignoring what have been told about fuses. Without programming them you cannot make a proper copy.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #11 on: May 25, 2016, 11:59:59 pm »
Study the Instructables process.  It will use avrdude and either an Arduino acting as an ICSP programmer or another type of ICSP programmer to reprogram the 16U2 INCLUDING the fuses.  The file I pointed you to is the correct file and we know you have a programmer.  Just follow the Yellow Brick Road and all should be well.  Don't forget the bit about shorting pins 5 & 6 (briefly) to get the chip into the proper mode.  Since pin 5 is RESET, I'm pretty sure 'briefly' is the way to go.

If not, toss 'em and buy some more.  Write yourself a "Do Better Slip" and move on.
 

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #12 on: May 26, 2016, 12:23:52 am »
Ding Ding Ding - we have a winner.

I followed the instructable that Buriedcode linked to above.   Arduino2 is now working.

I would like  to figure out why I couldn't copy the programming directly with avrdude, but I suppose I need to learn a lot more before I can grasp what wasn't happening.

Thanks, everyone for your help.

EDIT:  Well I'll be darned.  The first ardunio works as well.   My soldering of the QFN (I hope that's correct) package is less than stellar.  OK, it looks like a dog's breakfast.  To be fair, it's my first leadless package soldering ever, and I did it just an iron and hot air.
« Last Edit: May 26, 2016, 12:29:26 am by Excavatoree »
 

Offline Athanasis

  • Contributor
  • Posts: 49
  • Country: cy
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #13 on: May 26, 2016, 01:26:55 am »
Excavatoree, what about info found in this page?

http://www.instructables.com/id/How-to-Restore-the-Arduino-UNO-R3-ATmega16U2-Firmw/

Isn't enough? Why doesn't it work for you?
 

Offline Athanasis

  • Contributor
  • Posts: 49
  • Country: cy
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #14 on: May 26, 2016, 01:33:56 am »
Wooww. Sorry I really didn't notice that same link was posted above and everything fixed. Good to hear.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #15 on: May 26, 2016, 02:01:36 am »
Ding Ding Ding - we have a winner.

I followed the instructable that Buriedcode linked to above.   Arduino2 is now working.

I would like  to figure out why I couldn't copy the programming directly with avrdude, but I suppose I need to learn a lot more before I can grasp what wasn't happening.

Thanks, everyone for your help.

EDIT:  Well I'll be darned.  The first ardunio works as well.   My soldering of the QFN (I hope that's correct) package is less than stellar.  OK, it looks like a dog's breakfast.  To be fair, it's my first leadless package soldering ever, and I did it just an iron and hot air.

You may be copying the code without copying the fuses.  I'm not sure how just reading program memory is going to get you the fuse values.
 

Offline ExcavatoreeTopic starter

  • Frequent Contributor
  • **
  • Posts: 901
  • Country: us
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #16 on: May 26, 2016, 02:43:14 am »

You may be copying the code without copying the fuses.  I'm not sure how just reading program memory is going to get you the fuse values.

I did set the fuses on the "blank" controller before I tried to write the files I read from the other one.  I suspect, but don't know, that the read protect lock bit was set on the microcontroller I was trying to copy.   However, that doesn't explain why I do get two files that will pass the validation, but won't write to the other controller. 

Fortunately for me, the procedure outlined in the "Instructable" link above uses the "burn bootloader" feature of the arduino IDE.  That feature sets the fuses, then writes the software.  So my ARduino works, but I'm still ignorant as to why I couldn't do it manually.

Someone else above said that the firmware for the 16U2 should be included with the arduino IDE - indeed it is.   The Instructable above showed how to set up my own "board" which is the USB portion of the UNO, and then tell it the bootloader is the correct firmware.   For all its faults, the Ardunio IDE is very powerful, but someone as ignorant as I can only follow "cookbook" instructions.

Also, the 16U2 firmware is on one combined file - I'm not sure how to write that to the controller using AVRDUDE, or if that would even work.   Many  unknowns for me to learn about.
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #17 on: May 26, 2016, 10:31:52 am »
Whilst you've got it working, and don't 'need' anything more, I think I'll step up on my soap box a bit and talk about the Arduino.

The use of buying one with a ready made bootloader, USB-serial bridge, and a full fledged IDE with custom language (Arduino wiring language) is very convenient for quick prototyping, it also removes people from the 'bare metal' process of using said devices.  For the most part this isn't a bad thing - most just want to write code, flash LED's, read sensors print to LCD etc.. but over the years there has been a steady stream of questions and confusion surrounding erroneous chip behavior, and configuration/flashing - almost all of which can be worked out by reading the datasheet's relevant section.  These are things the Arduino environment shields you from (see what I did there?).

I'm not suggesting 'everyone should read it all and program in assembly!' because that's just silly.  But I *do* think arduino users, if they start to make more complicated projects or commercial ones, should move on to programming in C and become familiar with the devices memory structure, configuration so they can buy a blank AVR - or any micro - write code, and flash it. 

Whilst it may seen antiquated to some, as in 'well, its cheap, why bother if I can get one with a bootloader and familiar with sketches?' tinkerers should at least be aware of the underlying silicon.  It also makes for more efficient programming because once you've had to write your own libraries for peripherals you become aware of its merits/pitfalls/quirks.  The Arduino language is very convenient but often I will see some 'overclocking' their AVR because it can't do what they want fast enough, when in reality it would work just fine at 8MHz when written in C, without the hand holding for even simple pin toggles.

I think 'bricking' your UNO R3's USB-serial part was a good lesson, and something I think we should all do at some point - because then if gives one a reason/chance to work out just how these things are actually flashed, what the fuse settings do, what alternatives there are for configuration.  Years ago I went down the cheapskate route of 'buy a few AVR's, make my own programmer, write/use open source software etc.. and of course it wasn't that tough, but I could have saved a lot of time if I had an Arduino around - but then I wouldn't know what I know today.  So maybe I'm a bit bitter I had to start from scratch, but almost everything is a learning experience.
 
The following users thanked this post: amyk

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #18 on: May 26, 2016, 11:16:24 am »
Agree completely! I wonder how many perfectly working Arduinos have been "bricked" and thrown away without realising that they can be reprogrammed, missing out a good learning opportunity for their owners... :palm: Unless you physically damage something (e.g. overvoltage, ESD, wearing out the flash) you can reprogram and reuse these indefinitely.

Quote
Also, the 16U2 firmware is on one combined file - I'm not sure how to write that to the controller using AVRDUDE, or if that would even work.
Usually, firmware for standalone programming is one single file that is just written to the flash. AVRDUDE can definitely do that. Not saying you should brick it again and try fixing it entirely with AVRDUDE, but I encourage you read the datasheet, play around some more with programming/reading back completely blank chips, and keep in mind the sentence above.
 

Offline jnz

  • Frequent Contributor
  • **
  • Posts: 593
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #19 on: May 26, 2016, 02:30:37 pm »
For fwiw, the new Nordic powered Arduino Uno has an M4, an M0, and a proprietary wifi processor that also appears to be flashable.

I think that's a little much for a hobbiest board and will lead to more posts like this one.
 

Offline CJay

  • Super Contributor
  • ***
  • Posts: 4136
  • Country: gb
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #20 on: May 26, 2016, 04:30:46 pm »
Agree completely! I wonder how many perfectly working Arduinos have been "bricked" and thrown away without realising that they can be reprogrammed,

Thousands, the maker community seems to be full of people who are new to the whole idea of programming, EE etc. and have never read a datasheet in their life and entirely possibly will never read one .

Which is an astonishing testament ot the power of Arduino and Raspberry Pi even if they don't progress any further than the Arduino IDE or Scratch on Pi. 
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #21 on: May 26, 2016, 04:47:21 pm »
For fwiw, the new Nordic powered Arduino Uno has an M4, an M0, and a proprietary wifi processor that also appears to be flashable.

I think that's a little much for a hobbiest board and will lead to more posts like this one.

It won't if people will just keep their ICSP programmers locked away.  With any of the USB->Serial solutions, it is going to be pretty hard to 'brick' the CPU.  It's when avrdude shows up that the problems begin.

As to programming the Arduino, I thought I was writing code in C.  It looks like C, it uses the avr-gcc compiler, why should I think it is something else?  I have no idea how Wiring works and little interest in finding out.

I don't use the Arduino for much but a couple of days ago I wanted to do a little test on a UART stream.  There is no faster way in the world to write a bit of code to send chars than with an Arduino.  Two lines of code and I'm done.  Three if I count the delay().
 

Offline jancumps

  • Supporter
  • ****
  • Posts: 1272
  • Country: be
  • New Low
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #22 on: May 26, 2016, 04:50:32 pm »
Whilst you've got it working, and don't 'need' anything more, I think I'll step up on my soap box a bit and talk about the Arduino.

snipped

...

.. but over the years there has been a steady stream of questions and confusion surrounding erroneous chip behavior, and configuration/flashing - almost all of which can be worked out by reading the datasheet's relevant section.  These are things the Arduino environment shields you from (see what I did there?).

....

If the Arduino wouldn't shield this from [us], there would most likely be an even much bigger steady stream of questions and confusion surrounding this?
 

Offline macboy

  • Super Contributor
  • ***
  • Posts: 2254
  • Country: ca
Re: Arduino Uno R3 - bricked . Need to re-program 16U2 after chip erase
« Reply #23 on: May 26, 2016, 05:00:39 pm »
The "Firmware" provided by Arduino for the 16u2 USB chip implements the USB-UART function to talk to the main microcontroller. Yes, you can update this firmware. They do this using the Atmel DFU functionality. All Atmega16u2 chips leaving the factory have a special bootloader burned into them which enables this functionality. Unfortunately, it appears you wiped this out by erasing the chip with a ICSP programmer.

All you need to do to make your Arduinos work again is to restore the DFU bootloader, then program the Arduino 16u2 firmware onto the chip over USB using the tools and methods at https://www.arduino.cc/en/Hacking/DFUProgramming8U2

Go here https://github.com/arduino/Arduino/tree/master/hardware/arduino/avr/firmwares/atmegaxxu2 and download the Arduino Combined firmware for UNO 16u2. This is also included in the latest Arduino distributions (I have 1.6.8 and it's there). You can program this onto the 16u2 over the 6 pin ICSP connector and it should restore not only the DFU bootloader but a working USB-serial firmware as well. Note the readme.txt file in that location which contains the following information about how to program:
Code: [Select]
avrdude -p at90usb82 -F -P usb -c avrispmkii -U flash:w:UNO-dfu_and_usbserial_combined.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:mThat command includes the critical FUSE configurations. You may need to adjust the filename, programmer type, etc.
 
The following users thanked this post: wblock


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf