|
| 1 | +--- |
| 2 | +title: "Flash the USB-to-serial firmware for UNO (R3 or earlier) and Mega boards" |
| 3 | +id: 4408887452434 |
| 4 | +--- |
| 5 | + |
| 6 | +The following boards use either an Atmega16U2 or Atmega8U2 chip as a USB-to-serial converter: |
| 7 | + |
| 8 | +* Arduino UNO (R3 or earlier, including SMD variants) |
| 9 | +* Arduino Mega (Rev3 or earlier) |
| 10 | +* Arduino Mega2560 Rev3 |
| 11 | +* Arduino MegaADK Rev3 |
| 12 | + |
| 13 | +If the Arduino firmware for these chips is missing or has been corrupted, it will no longer be possible to program the board over USB. However, Atmega16U2 or Atmega8U2 chips support a DFU (Device Firmware Upgrade) protocol that can be used to flash the Arduino firmware via USB, to restore USB-to-serial functionality. |
| 14 | + |
| 15 | +You may want to try this procedure if: |
| 16 | + |
| 17 | +* Your board is not being detected properly, and you already tried [the standard troubleshooting steps](https://support.arduino.cc/hc/en-us/articles/4412955149586-If-your-board-is-not-detected-by-Arduino-IDE). |
| 18 | +* You have replaced the Atmega16U2 or Atmega8U2 with a new chip that is missing the Arduino firmware. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 1. Get the firmware |
| 23 | + |
| 24 | +The firmware is included in the **Arduino AVR Boards** package. When it's installed, you can find the firmware inside the [Arduino15 folder](https://support.arduino.cc/hc/en-us/articles/360018448279-Where-can-I-find-the-Arduino15-folder-): |
| 25 | + |
| 26 | +* Windows: `%USERPROFILE%\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\firmware\firmwares\atmegaxxu2\arduino-usbserial` |
| 27 | +* macoS: `~/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial` |
| 28 | +* Linux: `~/.arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial` |
| 29 | + |
| 30 | +You can also access the files from the [board package repository on GitHub](https://github.com/arduino/ArduinoCore-avr/tree/master/firmwares/atmegaxxu2/arduino-usbserial). |
| 31 | + |
| 32 | +Do one of the following: |
| 33 | + |
| 34 | +* Ensure that that **Arduino AVR Boards** package has been installed using Arduino IDE or Arduino CLI. |
| 35 | +* [Download the firmware for your board from GitHub](https://github.com/arduino/ArduinoCore-avr/tree/master/firmwares/atmegaxxu2/arduino-usbserial). |
| 36 | + |
| 37 | +Use the table below to find the correct firmware to use for your board: |
| 38 | + |
| 39 | +| Board | Serial chip | Firmware | |
| 40 | +|:----------------------|:------------|:-----------------------------------------------| |
| 41 | +| Arduino UNO R3 | Atmega16U2 | Arduino-usbserial-atmega16u2-Uno-Rev3.hex | |
| 42 | +| Arduino Mega2560 Rev3 | Atmega16U2 | Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex | |
| 43 | +| Arduino MegaADK Rev3 | Atmega16U2 | Arduino-usbserial-atmega16u2-MegaADK-Rev3.hex | |
| 44 | +| Arduino UNO (R1/R2) | Atmega8U2 | Arduino-usbserial-uno.hex | |
| 45 | +| Arduino Mega | Atmega8U2 | Arduino-usbserial-mega.hex | |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## 2. Connect your board with the Atmega16U2/8U2 in DFU mode |
| 50 | + |
| 51 | +To enable DFU programming, the Atmega16U2/8U2 chip needs to be reset to DFU mode. |
| 52 | + |
| 53 | +<!-- UNO (Rev3 or earlier), and Mega boards use either an Atmega16U2 or Atmega8U2 chip as a USB-to-serial converter. By setting a board to **DFU mode** (Device Firmware Update) you can [upload USB-to-Serial firmware to the chip](https://support.arduino.cc/hc/en-us/articles/4408887452434-Flash-USB-to-serial-firmware-in-DFU-mode). --> |
| 54 | + |
| 55 | +Follow these steps: |
| 56 | + |
| 57 | +1. Connect the board to your computer |
| 58 | + |
| 59 | +1. **If you're a "Rev 1" board:** If you're using an older revision (UNO Rev1 or Mega Rev1), you need to also assert and hold the **HWB line**. Find the two HWB pads on the back of the board and short them using something conductive, like a piece of wire. |
| 60 | + |
| 61 | +  |
| 62 | + |
| 63 | +1. Find the RESET and GND pins for the ATmega USB-Serial Processor. They are the innermost two pins of the six located close to the USB port. |
| 64 | + |
| 65 | +  |
| 66 | + |
| 67 | +1. Short the pins using a jumper cable or other (follow [these instructions](#rev1) for UNO Rev1). |
| 68 | + |
| 69 | +1. Short the RESET and GND pins to reset the board. |
| 70 | + |
| 71 | +1. Release or remove any wires or other material before proceeding to the next step. |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## 3. Program the chip |
| 76 | + |
| 77 | +You can flash the firmware using dfu-programmer (recommended) or the original Atmel FLIP application (Windows only). |
| 78 | + |
| 79 | +In this section: |
| 80 | + |
| 81 | +* [Using dfu-programmer](#using-dfu-programmer) |
| 82 | +* [Using Atmel FLIP](#using-atmel-flip) |
| 83 | + |
| 84 | +### Using dfu-programmer {#using-dfu-programmer} |
| 85 | + |
| 86 | +<a id="using-dfu-programmer-(macos%2Flinux)"></a> <!-- Maintain old anchor links --> |
| 87 | + |
| 88 | +**[dfu-programmer](https://github.com/dfu-programmer/dfu-programmer)** is a lightweight, multi-platform command-line programmer that implements the Atmel FLIP USB DFU Protocol[^1]. |
| 89 | + |
| 90 | +[^1]: [The Atmel FLIP USB DFU protocol](https://ww1.microchip.com/downloads/en/AppNotes/doc8457.pdf) is based on part of official USB DFU specification, but does not implement it entirely. For this reason, Atmega16U2 or Atmega8U2 chips cannot be used with **dfu-util** or other tools that implement the main USB DFU specification. |
| 91 | + |
| 92 | +Follow these steps: |
| 93 | + |
| 94 | +1. Install dfu-programmer: |
| 95 | + |
| 96 | + * **Windows:** Download [the latest dfu-programmer release from GitHub](https://github.com/dfu-programmer/dfu-programmer/releases). |
| 97 | + |
| 98 | + * **macOS:** dfu-programmer requires the **libusb library** (libusb-1.0.0) to run. Manually installing libusb is complicated, so it's highly recommended to install dfu-programmer using the [homebrew package manager](https://brew.sh/), which will include libusb-1 as a dependency. |
| 99 | + |
| 100 | + When homebrew is installed, run this command in Terminal to install dfu-programmer: |
| 101 | + |
| 102 | + `brew install dfu-programmer` |
| 103 | + |
| 104 | + * **Linux:** Run this command in Terminal to install dfu-programmer: |
| 105 | + |
| 106 | + `sudo apt-get install dfu-programmer` |
| 107 | + |
| 108 | +1. Open your system's command line application. |
| 109 | + |
| 110 | +1. If you downloaded dfu-programmer from GitHub, move into the surrounding folder (for example, the Downloads folder): |
| 111 | + |
| 112 | + * Windows (cmd): `cd %USERPROFILE%\Downloads` |
| 113 | + * macOS/Linux: `cd ~/Downloads` |
| 114 | + |
| 115 | +1. Erase the memory (replace `<atmegaxxu2>` with either `atmega8u2` or `atmega16u2`). |
| 116 | + |
| 117 | + * Windows: `dfu-programmer.exe <atmegaxxu2> erase` |
| 118 | + * macOS/Linux: `dfu-programmer <atmegaxxu2> erase` |
| 119 | + |
| 120 | +1. Flash the firmware: |
| 121 | + |
| 122 | + * Windows: `dfu-programmer <atmegaxxu2> flash <firmware path>` |
| 123 | + * macOS/Linux: `dfu-programmer <atmegaxxu2> flash <firmware path>` |
| 124 | + |
| 125 | +1. Disconnect and reconnect the board to your computer. |
| 126 | + |
| 127 | +<!-- |
| 128 | +
|
| 129 | +* **Example: UNO R3 (Windows):** |
| 130 | + ``` |
| 131 | + TODO |
| 132 | + ``` |
| 133 | +
|
| 134 | +* **UNO R3 (macOS/Linux):** |
| 135 | + ``` |
| 136 | + dfu-programmer atmega16u2 flash ~/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Uno-Rev3.hex |
| 137 | + ``` |
| 138 | +
|
| 139 | +* **Mega2560 Rev3 (Windows):** |
| 140 | + ``` |
| 141 | + TODO %localappdata% |
| 142 | + ``` |
| 143 | +
|
| 144 | +* **Mega2560 Rev3 (macOS/Linux):** |
| 145 | + ``` |
| 146 | + dfu-programmer atmega16u2 flash ~/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex |
| 147 | + ``` |
| 148 | +
|
| 149 | +--> |
| 150 | + |
| 151 | +#### Examples commands for dfu-programmer |
| 152 | + |
| 153 | +> [!NOTE] |
| 154 | +> The examples assumes that version 1.8.6 of Arduino AVR Boards is installed. |
| 155 | +
|
| 156 | +##### UNO R3 on Windows |
| 157 | + |
| 158 | +``` |
| 159 | +dfu-programmer.exe atmega16u2 flash %USERPROFILE%\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\firmware\firmwares\atmegaxxu2\arduino-usbserial\Arduino-usbserial-atmega16u2-Uno-Rev3.hex |
| 160 | +``` |
| 161 | + |
| 162 | +##### UNO R3 on macOS |
| 163 | + |
| 164 | +``` |
| 165 | +dfu-programmer atmega16u2 flash ~/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Uno-Rev3.hex |
| 166 | +``` |
| 167 | + |
| 168 | +##### UNO R3 on Linux |
| 169 | + |
| 170 | +``` |
| 171 | +dfu-programmer atmega16u2 flash ~/.arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Uno-Rev3.hex |
| 172 | +``` |
| 173 | + |
| 174 | +##### Mega2560 Rev3 on Windows |
| 175 | + |
| 176 | +``` |
| 177 | +dfu-programmer.exe atmega16u2 flash %USERPROFILE%\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\firmware\firmwares\atmegaxxu2\arduino-usbserial\Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex |
| 178 | +``` |
| 179 | + |
| 180 | +##### Mega2560 Rev3 on macOS |
| 181 | + |
| 182 | +``` |
| 183 | +dfu-programmer atmega16u2 flash ~/Library/Arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex |
| 184 | +``` |
| 185 | + |
| 186 | +##### Mega2560 Rev3 on Linux |
| 187 | + |
| 188 | +``` |
| 189 | +dfu-programmer atmega16u2 flash ~/.arduino15/packages/arduino/hardware/avr/1.8.6/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex |
| 190 | +``` |
| 191 | + |
| 192 | +### Using Atmel FLIP {#using-atmel-flip} |
| 193 | + |
| 194 | +<a id="using-flip-(windows)"></a> <!-- Maintain old anchor links --> |
| 195 | + |
| 196 | +Before you begin: |
| 197 | + |
| 198 | +1. Open Device Manager. |
| 199 | + |
| 200 | +1. Expand the **libusb-win32-devices** category. If it is missing, [follow these steps](#install-libusb-win32) before proceeding. |
| 201 | + |
| 202 | +1. Take a note of the device name, which should be either **ATmega16U2** and **ATmega8U2**. |
| 203 | + |
| 204 | +Now flash the firmware using FLIP: |
| 205 | + |
| 206 | +1. Download and install [FLIP](https://www.microchip.com/en-us/development-tool/flip). |
| 207 | + |
| 208 | +1. Open FLIP. |
| 209 | + |
| 210 | + > [!NOTE] |
| 211 | + > Opening the application may prompt a 'Could not find a Java Virtual Machine' error. In this case, [install Java Runtime Environment](https://www.java.com/en/download/manual.jsp) with the **Windows Online** option. |
| 212 | +
|
| 213 | +1. Select the device name you identified earlier (ATmega16U2 or ATmega8U2). |
| 214 | + |
| 215 | +1. Click the Cable button, select USB, then click Open. |
| 216 | + |
| 217 | +  |
| 218 | + |
| 219 | +1. In the menu, click _Device > Select..._ |
| 220 | + |
| 221 | +  |
| 222 | + |
| 223 | +1. Click _File > Load HEX File..._ |
| 224 | + |
| 225 | +1. Select your driver `.hex` file and click 'OK'. |
| 226 | + |
| 227 | +1. For Operational Flow, check check **Erase**, **Program**, and **Verify** (this is the default setting). |
| 228 | + |
| 229 | +  |
| 230 | + |
| 231 | +1. Click on the 'Program Target Device Memory' button. |
| 232 | + |
| 233 | +  |
| 234 | + |
| 235 | +1. The firmware will be flashed, which may happen very quickly. A "Programming done" message should be displayed in the bottom-left corner. |
| 236 | + |
| 237 | +  |
| 238 | + |
| 239 | +1. Disconnect and reconnect the board to your computer. |
| 240 | + |
| 241 | +## Install the libusb-win32 driver in Device Manager {#install-libusb-win32} |
| 242 | + |
| 243 | +1. Look for an **Unknown Device** under 'Other Devices'. Disconnect all devices except the board if multiple unknown devices are available. |
| 244 | + |
| 245 | +2. Right-click and select **Update driver**. |
| 246 | + |
| 247 | +  |
| 248 | + |
| 249 | +3. Point to `C:\Program Files (x86)\Atmel\Flip 3.4.7` |
| 250 | + |
| 251 | +4. Click 'Install' and wait for the installation to complete. |
| 252 | + |
| 253 | +  |
| 254 | + |
| 255 | +5. The device should now be recognized, under 'libusb-win32-devices' |
| 256 | + |
| 257 | +  |
0 commit comments