How to backup an Atmega32u2 using Arduino as ISP?

Hello, I am trying to backup an Atmega32u2 and flash a new firmware with Arduino UNO using the instructions shown at:

GitHub - PrusaOwners/mk3-32u2-firmware: Updated Atmega 32u2 Firmware for the Einsy Rambo

After I connected the two boards using the wires, where do I enter the following commands to backup the Amega32u2 and flash a new firmware? I opened a command prompt on Windows 11 but it does not recognize what avrdude is.

cd ~
mkdir mk3_32u2_backup
cd mk3_32u2_backup
avrdude -p m32u2 -F -P /dev/ttyACM0 -b 19200 -c avrisp -U flash:r:firmware_backup.hex:i -U eeprom:r:eeprom.hex:i -U lfuse:r:lowfuse:h -U hfuse:r:highfuse:h -U efuse:r:exfuse:h -U lock:r:lockfuse:h

In case my UNO is connected to a Windows 11 PC via COM9, what shall I change the β€œ/dev/ttyACM0” to?

The linked tutorial on the provided link is also broken.

Hi @bbqq.

That is where you enter the commands.

You must specify the full path to the executable.

You can determine the path to the installation of the AVRDUDE tool on your computer that is used by Arduino IDE by performing an upload in Arduino IDE and then examining the command Arduino IDE generated. I'll provide instructions you can follow to do that:

  1. Plug the USB cable of the Arduino board you are using as an "Arduino as ISP" programmer into your computer.
  2. Select File > New Sketch from the Arduino IDE menus.
  3. Select Tools > Board > Arduino AVR Boards > Arduino Uno from the Arduino IDE menus.
  4. Select your board's port from the Tools > Port menu.
  5. Disconnect the USB cable of the Arduino board from your computer.
    β“˜ This will cause the upload to fail, but that is OK because we only want Arduino IDE to generate an upload command for us, and don't actually need (or want) the sketch to be uploaded.
  6. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  7. Check the box next to "Show verbose output during: ☐ upload" in the "Preferences" dialog.
  8. Click the "OK" button.
    The "Preferences" dialog will close.
  9. Select Sketch > Upload from the Arduino IDE menus.
  10. Wait for the upload to fail.
  11. Scroll up the black "Output" panel at the bottom of the Arduino IDE window until you see the avrdude command that was generated for the upload.

The command will look something like this:

"C:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude" "-CC:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM35" -b115200 -D "-Uflash:w:C:\Users\username\AppData\Local\Temp\arduino\sketches\2550236D1AAA5295D4F743C245319248/sketch_aug7a.ino.hex:i"

In this example we learned that the path of the avrdude executable is:

C:\Users\username\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude

You can then copy the path of the avrdude executable and use that in the command prompt.

Change it to COM9.

The current location of the tutorial is here:

https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoISP/

I submitted a fix for the broken link:

1 Like

Thanks. In the mk3_32u2_backup directory, after executing:

avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U flash:r:firmware_backup.hex:i -U eeprom:r:eeprom.hex:i -U lfuse:r:lowfuse:h -U hfuse:r:highfuse:h -U efuse:r:exfuse:h -U lock:r:lockfuse:h

It gave me:

avrdude: AVR Part "m32u2" not found.

What shall I do?

Possibly its an older version of` avrdude that did not have support for that MCU yet. What version of the IDE do you have installed?

Sadly avrdude does not seem to have a flag to show its version number to confirm and no longer seems to list part numbers it supports like it once did, but you could try just typing:

avrdude -c avrisp

(i.e. omitting the -p flag) and see whether the version you have outputs one.

In any case you can download a recent version of avrdude from here.

I am using the latest 2.3.6 IDE. Using the command you provided, it listed:

Valid parts are:
t10 = ATtiny10 [C:\WinAVR-20100110\bin\avrdude.conf:15443]
t8 = ATtiny9 [C:\WinAVR-20100110\bin\avrdude.conf:15403]
t5 = ATtiny5 [C:\WinAVR-20100110\bin\avrdude.conf:15363]
t4 = ATtiny4 [C:\WinAVR-20100110\bin\avrdude.conf:15323]
ucr2 = 32UC3A0512 [C:\WinAVR-20100110\bin\avrdude.conf:15302]
x128a4 = ATXMEGA128A4 [C:\WinAVR-20100110\bin\avrdude.conf:15204]
x64a4 = ATXMEGA64A4 [C:\WinAVR-20100110\bin\avrdude.conf:15107]
x32a4 = ATXMEGA32A4 [C:\WinAVR-20100110\bin\avrdude.conf:15010]
x16a4 = ATXMEGA16A4 [C:\WinAVR-20100110\bin\avrdude.conf:14913]
x256a3b = ATXMEGA256A3B [C:\WinAVR-20100110\bin\avrdude.conf:14816]
x256a3 = ATXMEGA256A3 [C:\WinAVR-20100110\bin\avrdude.conf:14719]
x192a3 = ATXMEGA192A3 [C:\WinAVR-20100110\bin\avrdude.conf:14622]
x128a3 = ATXMEGA128A3 [C:\WinAVR-20100110\bin\avrdude.conf:14525]
x64a3 = ATXMEGA64A3 [C:\WinAVR-20100110\bin\avrdude.conf:14428]
x256a1 = ATXMEGA256A1 [C:\WinAVR-20100110\bin\avrdude.conf:14331]
x192a1 = ATXMEGA192A1 [C:\WinAVR-20100110\bin\avrdude.conf:14234]
x128a1d = ATXMEGA128A1REVD [C:\WinAVR-20100110\bin\avrdude.conf:14137]
x128a1 = ATXMEGA128A1 [C:\WinAVR-20100110\bin\avrdude.conf:14040]
x64a1 = ATXMEGA64A1 [C:\WinAVR-20100110\bin\avrdude.conf:13943]
m6450 = ATMEGA6450 [C:\WinAVR-20100110\bin\avrdude.conf:13754]
m3250 = ATMEGA3250 [C:\WinAVR-20100110\bin\avrdude.conf:13565]
m645 = ATMEGA645 [C:\WinAVR-20100110\bin\avrdude.conf:13376]
m325 = ATMEGA325 [C:\WinAVR-20100110\bin\avrdude.conf:13187]
usb82 = AT90USB82 [C:\WinAVR-20100110\bin\avrdude.conf:13007]
usb162 = AT90USB162 [C:\WinAVR-20100110\bin\avrdude.conf:12823]
usb1287 = AT90USB1287 [C:\WinAVR-20100110\bin\avrdude.conf:12634]
usb1286 = AT90USB1286 [C:\WinAVR-20100110\bin\avrdude.conf:12445]
usb647 = AT90USB647 [C:\WinAVR-20100110\bin\avrdude.conf:12257]
usb646 = AT90USB646 [C:\WinAVR-20100110\bin\avrdude.conf:12068]
m32u4 = ATmega32U4 [C:\WinAVR-20100110\bin\avrdude.conf:11880]
t84 = ATtiny84 [C:\WinAVR-20100110\bin\avrdude.conf:11697]
t44 = ATtiny44 [C:\WinAVR-20100110\bin\avrdude.conf:11515]
t24 = ATtiny24 [C:\WinAVR-20100110\bin\avrdude.conf:11333]
m128rfa1 = ATMEGA128RFA1 [C:\WinAVR-20100110\bin\avrdude.conf:11145]
m2561 = ATMEGA2561 [C:\WinAVR-20100110\bin\avrdude.conf:10951]
m2560 = ATMEGA2560 [C:\WinAVR-20100110\bin\avrdude.conf:10758]
m1281 = ATMEGA1281 [C:\WinAVR-20100110\bin\avrdude.conf:10570]
m1280 = ATMEGA1280 [C:\WinAVR-20100110\bin\avrdude.conf:10381]
m640 = ATMEGA640 [C:\WinAVR-20100110\bin\avrdude.conf:10193]
t85 = ATtiny85 [C:\WinAVR-20100110\bin\avrdude.conf:10012]
t45 = ATtiny45 [C:\WinAVR-20100110\bin\avrdude.conf:9833]
t25 = ATtiny25 [C:\WinAVR-20100110\bin\avrdude.conf:9653]
pwm3b = AT90PWM3B [C:\WinAVR-20100110\bin\avrdude.conf:9472]
pwm2b = AT90PWM2B [C:\WinAVR-20100110\bin\avrdude.conf:9289]
pwm3 = AT90PWM3 [C:\WinAVR-20100110\bin\avrdude.conf:9106]
pwm2 = AT90PWM2 [C:\WinAVR-20100110\bin\avrdude.conf:8922]
t2313 = ATtiny2313 [C:\WinAVR-20100110\bin\avrdude.conf:8735]
m328p = ATMEGA328P [C:\WinAVR-20100110\bin\avrdude.conf:8547]
t88 = attiny88 [C:\WinAVR-20100110\bin\avrdude.conf:8361]
m168 = ATMEGA168 [C:\WinAVR-20100110\bin\avrdude.conf:8173]
m88 = ATMEGA88 [C:\WinAVR-20100110\bin\avrdude.conf:7987]
m48 = ATMEGA48 [C:\WinAVR-20100110\bin\avrdude.conf:7800]
t861 = ATTINY861 [C:\WinAVR-20100110\bin\avrdude.conf:7612]
t461 = ATTINY461 [C:\WinAVR-20100110\bin\avrdude.conf:7423]
t261 = ATTINY261 [C:\WinAVR-20100110\bin\avrdude.conf:7234]
t26 = ATTINY26 [C:\WinAVR-20100110\bin\avrdude.conf:7077]
m8535 = ATMEGA8535 [C:\WinAVR-20100110\bin\avrdude.conf:6919]
m8515 = ATMEGA8515 [C:\WinAVR-20100110\bin\avrdude.conf:6761]
m8 = ATMEGA8 [C:\WinAVR-20100110\bin\avrdude.conf:6600]
m161 = ATMEGA161 [C:\WinAVR-20100110\bin\avrdude.conf:6460]
m32 = ATMEGA32 [C:\WinAVR-20100110\bin\avrdude.conf:6285]
m6490 = ATMEGA6490 [C:\WinAVR-20100110\bin\avrdude.conf:6092]
m649 = ATMEGA649 [C:\WinAVR-20100110\bin\avrdude.conf:5907]
m3290p = ATMEGA3290P [C:\WinAVR-20100110\bin\avrdude.conf:5724]
m3290 = ATMEGA3290 [C:\WinAVR-20100110\bin\avrdude.conf:5539]
m329p = ATMEGA329P [C:\WinAVR-20100110\bin\avrdude.conf:5354]
m329 = ATMEGA329 [C:\WinAVR-20100110\bin\avrdude.conf:5170]
m169 = ATMEGA169 [C:\WinAVR-20100110\bin\avrdude.conf:4990]
m163 = ATMEGA163 [C:\WinAVR-20100110\bin\avrdude.conf:4832]
m162 = ATMEGA162 [C:\WinAVR-20100110\bin\avrdude.conf:4636]
m1284p = ATMEGA1284P [C:\WinAVR-20100110\bin\avrdude.conf:4446]
m644p = ATMEGA644P [C:\WinAVR-20100110\bin\avrdude.conf:4254]
m644 = ATMEGA644 [C:\WinAVR-20100110\bin\avrdude.conf:4064]
m324p = ATMEGA324P [C:\WinAVR-20100110\bin\avrdude.conf:3873]
m164p = ATMEGA164P [C:\WinAVR-20100110\bin\avrdude.conf:3682]
m16 = ATMEGA16 [C:\WinAVR-20100110\bin\avrdude.conf:3504]
c32 = AT90CAN32 [C:\WinAVR-20100110\bin\avrdude.conf:3313]
c64 = AT90CAN64 [C:\WinAVR-20100110\bin\avrdude.conf:3123]
c128 = AT90CAN128 [C:\WinAVR-20100110\bin\avrdude.conf:2933]
m128 = ATMEGA128 [C:\WinAVR-20100110\bin\avrdude.conf:2755]
m64 = ATMEGA64 [C:\WinAVR-20100110\bin\avrdude.conf:2574]
m103 = ATMEGA103 [C:\WinAVR-20100110\bin\avrdude.conf:2434]
8535 = AT90S8535 [C:\WinAVR-20100110\bin\avrdude.conf:2313]
8515 = AT90S8515 [C:\WinAVR-20100110\bin\avrdude.conf:2199]
4434 = AT90S4434 [C:\WinAVR-20100110\bin\avrdude.conf:2116]
4433 = AT90S4433 [C:\WinAVR-20100110\bin\avrdude.conf:1992]
2343 = AT90S2343 [C:\WinAVR-20100110\bin\avrdude.conf:1868]
2333 = AT90S2333 [C:\WinAVR-20100110\bin\avrdude.conf:1740]
2313 = AT90S2313 [C:\WinAVR-20100110\bin\avrdude.conf:1627]
4414 = AT90S4414 [C:\WinAVR-20100110\bin\avrdude.conf:1514]
1200 = AT90S1200 [C:\WinAVR-20100110\bin\avrdude.conf:1399]
t15 = ATtiny15 [C:\WinAVR-20100110\bin\avrdude.conf:1266]
t13 = ATtiny13 [C:\WinAVR-20100110\bin\avrdude.conf:1093]
t12 = ATtiny12 [C:\WinAVR-20100110\bin\avrdude.conf:960]
t11 = ATtiny11 [C:\WinAVR-20100110\bin\avrdude.conf:896]

I also went to the link you provided to download the latest version of the software. I extracted it to windows’ desktop. I see there is an arvdude.exe but trying to right-click to run it even as an administrator showed nothing. So what shall I do next?

I went to that directory from Command Prompt and then executed:

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U flash:r:firmware_backup.hex:i -U eeprom:r:eeprom.hex:i -U lfuse:r:lowfuse:h -U hfuse:r:highfuse:h -U efuse:r:exfuse:h -U lock:r:lockfuse:h

It gave me:

Error: cannot open port \.\COM9: Access is denied.

Error: unable to open port COM9 for programmer avrisp

Avrdude done. Thank you.

Its a command line program, so does not open a GUI. It needs to be run from a command prompt or powershell.

Sounds like something already has the port open. Make sure Serial Monitor is closed within the IDE, or even better shut down the IDE completely. Failing that, unplug the UNO, wait a few seconds and plug it in again, then try avrdude again.

BTW, if you prefer a GUI, then try avrdudess which is a GUI wrapper for avrdude.

Thanks. I closed the Arduino IDE and it looked like it was uploading something as shown below:

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U flash:r:firmware_backup.hex:i -U eeprom:r:eeprom.hex:i -U lfuse:r:lowfuse:h -U hfuse:r:highfuse:h -U efuse:r:exfuse:h -U lock:r:lockfuse:h

Processing -U flash:r:firmware_backup.hex:i
Reading flash memory ...
Reading | ################################################## | 100% 19.93 s
Writing 32016 bytes to output file firmware_backup.hex

Processing -U eeprom:r:eeprom.hex:i
Reading eeprom memory ...
Reading | ################################################## | 100% 3.18 s
Writing 1024 bytes to output file eeprom.hex

Processing -U lfuse:r:lowfuse:h
Reading lfuse memory ...
Writing 1 byte to output file lowfuse

Processing -U hfuse:r:highfuse:h
Reading hfuse memory ...
Writing 1 byte to output file highfuse

Processing -U efuse:r:exfuse:h
Reading efuse memory ...
Writing 1 byte to output file exfuse

Processing -U lock:r:lockfuse:h
Reading lock memory ...
Writing 1 byte to output file lockfuse

Avrdude done. Thank you.

Then, I continued:

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U hfuse:w:0xD1:m
Reading 1 byte for hfuse from input file 0xD1
Writing 1 byte (0xD1) to hfuse, 1 byte written, 1 verified

Avrdude done. Thank you.

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>wget https://raw.githubusercontent.com/PrusaOwners/mk3-32u2-firmware/master/hex_files/DFU-hoodserial-combined-PrusaMK3-32u2.hex
'wget' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U flash:w:DFU-hoodserial-combined-PrusaMK3-32u2.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m
OS error: file DFU-hoodserial-combined-PrusaMK3-32u2.hex is not readable: No such file or directory

Avrdude done. Thank you.

So after I set the high fuse bits, I tried to fetch and flash the firmware. Then, it reported that the .hex is not readable. Maybe I need to install wget to continue?

Sounds like the first avrdud step worked. The wget program is a download tool that is common on Linux or Unix systems. There is a Windows version, but you can just download the file from their firmware Github using your browser. Then retry the second avrdude step which seems to have failed because the file did not get downloaded in the previous one.

OK. I downloaded the file from the source you mentioned. Then, the following happened:

C:\Users\user1\Desktop\avrdude-v8.1-windows-x64>avrdude -p m32u2 -F -P COM9 -b 19200 -c avrisp -U flash:w:DFU-hoodserial-combined-PrusaMK3-32u2.hex -U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m

Processing -U flash:w:DFU-hoodserial-combined-PrusaMK3-32u2.hex:i
Reading 7418 bytes for flash from input file DFU-hoodserial-combined-PrusaMK3-32u2.hex
Writing 7418 bytes to flash
Writing | ################################################## | 100% 8.60 s
Reading | ################################################## | 100% 4.67 s
7418 bytes of flash verified

Processing -U lfuse:w:0xFF:m
Reading 1 byte for lfuse from input file 0xFF
Writing 1 byte (0xFF) to lfuse, 1 byte written, 1 verified

Processing -U hfuse:w:0xD9:m
Reading 1 byte for hfuse from input file 0xD9
Writing 1 byte (0xD9) to hfuse, 1 byte written, 1 verified

Processing -U efuse:w:0xF4:m
Reading 1 byte for efuse from input file 0xF4
Writing 1 byte (0xF4) to efuse, 1 byte written, 1 verified

Avrdude done. Thank you.

I connected the prusa machine to Pi and:

[ 10.651634] Bluetooth: RFCOMM socket layer initialized
[ 10.651645] Bluetooth: RFCOMM ver 1.11
[ 3500.459409] usb 3-2: USB disconnect, device number 2
[31848.788635] usb 3-2: new full-speed USB device number 3 using xhci-hcd
[31848.981851] usb 3-2: New USB device found, idVendor=2c99, idProduct=0002, bcdDevice= 1.00
[31848.981861] usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[31848.981864] usb 3-2: Product: Original Prusa i3 MK3
[31848.981866] usb 3-2: Manufacturer: Prusa Research (prusa3d.com)
[31848.981869] usb 3-2: SerialNumber:
[31849.232938] cdc_acm 3-2:1.0: ttyACM1: USB ACM device

Is it the end or I have to continue with "Building the DFU Bootloader and Hoodserial for the MK3 Einsy"?

Seems to me that they provide the ready made file that you downloaded from their site and have now successfully uploaded to your 32u2.

I think the Building the DFU Bootloader and Hoodserial for the MK3 Einsy section is optional information should someone for any reason need to build the .hex file from the sourcefiles. I don't think its a necessary step.

I think you now have the firmware programmed on to your 32u4 chip so can probably proceed to testing it with the 3D printer.

1 Like

Thank you very much for your help. I wouldn't be able to make it without you.