2

I'm trying to add a bootloader hex to Nick Gammon's Atmega Board Programmer sketch, and I can't seem to get a hex file to convert.

I need to convert "Arduino-usbserial-atmega16u2-Uno-Rev3.hex", but that wasn't working so I thought I'd try converting one that's already used in the sketch, "Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex", but that's not working either. I've followed the instructions from http://www.gammon.com.au/bootloader

I've tried it using Wine and Paralells. Clicking the copy button when using Wine causes the program to stop responding.

Here is a screenshot of the error:

Error Screenshot

Thank you

  • Why do you need to do this? Normally you don't need to reflash the Atmega16U2 chip. – Nick Gammon Mar 1 '16 at 21:22
  • I work at a university and I'm making a shield that plugs into the top of dead Arduinos the see if they can be fixed with a simple re-flash of the chips, which is usually the fix. I used your sketch to put the Atmega16U2 chips into DFU mode, but it still requires me to connect the Arduinos to a computer to finish off the fix. It'd just be easier to put the working hex file on the chip in the first place. – JosephFTaylor Mar 2 '16 at 18:42
  • I have another sketch which uploads a hex file from a SD card. The size of the full file for the Atmega16U2 may not fit into the bootloader programmer PROGMEM. However you could easily reflash the entire chip using the hex-uploader sketch. In fact you probably don't need the bootloader on the Atmega16U2 - because that is only used for entering DFU mode. – Nick Gammon Mar 2 '16 at 19:39
1

I can't reproduce that.

My apologies - I couldn't quite read the error message in the screen dump. What you got was:

Don't know end address for 0
Please add to table: end_addresses
Run-time error
World: smaug2
Immediate execution
[string "Immediate"]:96: Cannot continue
stack traceback:
        [C]: in function 'error'
        [string "Immediate"]:96: in function 'process'
        [string "Immediate"]:134: in main chunk

The relevant error is the first line. That file has code for address 0 - which is not part of the bootloader. It tries to detect bootloader addresses, and zero is not one of them. Looking at the start of the file I see this:

:1000000090C00000A9C00000A7C00000A5C000006B
:10001000A3C00000A1C000009FC000009DC0000060
:100020009BC0000099C0000097C0000048C40000B9
:100030000CC4000091C000008FC000008DC0000003
:100040008BC0000089C0000087C0000085C0000090
:1000500083C0000081C000007FC0000002C100001A
:100060007BC0000079C0000077C0000075C00000B0
:1000700073C0000071C000006FC000006DC00000C0
:100080006BC0000069C0000067C0000065C00000D0
:1000900063C0000061C000001201100102000008EE
:1000A0004123430001000102DC0109023E0002017C
:1000B00000C0320904000001020201000524000111
:1000C0001004240206052406000107058203080027
:1000D000FF09040100020A000000070504024000B5
:1000E00001070583024000010403090432034100B3
:1000F00072006400750069006E006F002000280027
:100100007700770077002E006100720064007500B0
:1001100069006E006F002E0063006300290000007C
:10012000000011241FBECFEFD2E0DEBFCDBF11E033
:10013000A0E0B1E0ECEAFFE002C005900D92A6312C

In particular the format is:

 :10 0000 00 90C00000A9C00000A7C00000A5C00000 6B
  ^  ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
len  addr TT   data                          sumcheck

So this file includes code for the Atmega16U2 as well as the bootloader.

My sketch is not designed to program non-bootloaders (it is a bootloader programmer after all).


Scroll down that page for how to reprogram the Atmega16U2 chip.

The bootloader programmer sketch (as published) will put the bootloader onto the Atmega16U2. Then follow the instructions on that page, or on this page, below, for entering DFU mode and uploading the main part of the code (not the bootloader part).


Entering DFU mode

If you have just flashed the bootloader using the bootloader programmer sketch then it should enter DFU mode, visible because the pin 13 LED flashes rapidly.

If not, enter DFU mode by shorting together Reset and Ground briefly with a screwdriver or similar. They are the two left-most pins visible in the image above, nearest to the Reset button and below the hole on the board.

(Don't keep them shorted, just a brief touch should do it).

Enter DFU mode

Once in DFU mode, you should see it appear as an Atmel USB device, if you type lsusb (on Linux):

$ lsusb
...
Bus 003 Device 092: ID 03eb:2fef Atmel Corp. 
...

A Uno which is not in USB mode might look like this:

$ lsusb
...
Bus 003 Device 090: ID 2341:0043 Arduino SA Uno R3 (CDC ACM)
...

(or not appear at all if there is no firmware on it).

If you are using Ubuntu or similar you can obtain the DFU programmer as follows:

 sudo apt-get install dfu-programmer

You can obtain the code for the firmware from here:

http://gammon.com.au/Arduino/Arduino-atmega16u2-Uno-firmware-Rev3.hex

(RH-click and "save as" to put a copy on your hard disk).

Assuming you place that firmware in the current directory of your terminal window, you can now flash the code as follows:

sudo dfu-programmer atmega16u2 flash Arduino-atmega16u2-Uno-firmware-Rev3.hex

You should see a message like:

Validating...
4034 bytes used (32.83%)

Now you can unplug the USB cable, plug it back in, and the USB interface should be back to factory settings.

For other operating systems, such as Windows, you should be able to get a copy of the DFU programmer from:

  • Why am I getting the same error message when I try and convert Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex, the same used in your bootloader programmer sketch? – JosephFTaylor Mar 2 '16 at 18:39
  • Being a combined file it would start at address zero as well. I would have stripped out the low-order bytes from the .hex file, leaving only the bootloader part. – Nick Gammon Mar 2 '16 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.