aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-11-05 03:42:36 +0000
committerQMK Bot <hello@qmk.fm>2021-11-05 03:42:36 +0000
commit2ebf587ebf9c81ecc3874ddfebedbedce76ddd33 (patch)
treec0809f6dc811a7f42fb43fda1112687f529922fc /docs
parent66e9925e8b6d844cce20ecd1568ce20016316f8a (diff)
parentcc5a38e7873ee184394b577b12b3b4578611b772 (diff)
downloadqmk_firmware-2ebf587ebf9c81ecc3874ddfebedbedce76ddd33.tar.gz
qmk_firmware-2ebf587ebf9c81ecc3874ddfebedbedce76ddd33.zip
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'docs')
-rw-r--r--docs/isp_flashing_guide.md341
1 files changed, 160 insertions, 181 deletions
diff --git a/docs/isp_flashing_guide.md b/docs/isp_flashing_guide.md
index 7efcd9ee3..384aaf722 100644
--- a/docs/isp_flashing_guide.md
+++ b/docs/isp_flashing_guide.md
@@ -1,263 +1,242 @@
1# ISP Flashing Guide 1# ISP Flashing Guide
2 2
3ISP flashing (also known as ICSP flashing) is the process of programming a microcontroller directly. This allows you to replace the bootloader, or change the "fuses" on the controller, which control a number of hardware- and software-related functions, such as the speed of the controller, how it boots, and other options. 3In order to flash a microcontroller over USB, it needs something called a bootloader. This bootloader lives in a specific section of the flash memory, and allows you to load the actual application firmware (in this case, QMK) into the rest of the flash.
4 4
5The main use of ISP flashing for QMK is flashing or replacing the bootloader on your AVR-based controller (Pro Micros, or V-USB chips). 5However, it can sometimes happen that the bootloader becomes corrupted and needs reflashing, or you may want to change the bootloader to another one. It's not possible to do this with the existing bootloader, because, of course, it is already running, and cannot overwrite itself. Instead, you will need to ISP flash the microcontroller.
6 6
7?> This is only for programming AVR based boards, such as the Pro Micro or other ATmega controllers. It is not for Arm controllers, such as the Proton C. 7There are several different kinds of bootloaders available for AVR microcontrollers. Most STM32 ARM-based microcontrollers already have a USB-capable bootloader in ROM, so generally do not need to be ISP flashed.
8 8
9## Dealing with Corrupted Bootloaders 9## Hardware
10 10
11If you're having trouble flashing/erasing your board, and running into cryptic error messages like any of the following for a DFU based controller: 11One of the following devices is required to perform the ISP flashing. The product links are to the official versions, however you can certainly source them elsewhere.
12 12
13 libusb: warning [darwin_transfer_status] transfer error: timed out 13You'll also need some jumper wires to connect the ISP flasher and the target board. Some boards have an ISP header with the necessary pins broken out. If not, then you will need to temporarily solder the wires to the PCB -- usually to switch pins or directly to the MCU.
14 dfu.c:844: -ETIMEDOUT: Transfer timed out, NAK 0xffffffc4 (-60) 14The wiring is fairly straightforward; for the most part, you'll be connecting like to like. Refer to the target MCU's datasheet for the exact `RESET`, `SCLK`, `MOSI` and `MISO` pins.
15 atmel.c:1627: atmel_flash: flash data dfu_download failed.
16 atmel.c:1629: Expected message length of 1072, got -60.
17 atmel.c:1434: Error flashing the block: err -2.
18 ERROR
19 Memory write error, use debug for more info.
20 commands.c:360: Error writing memory data. (err -4)
21 15
22 dfu.c:844: -EPIPE: a) Babble detect or b) Endpoint stalled 0xffffffe0 (-32) 16### Pro Micro as ISP
23 Device is write protected.
24 dfu.c:252: dfu_clear_status( 0x7fff4fc2ea80 )
25 atmel.c:1434: Error flashing the block: err -2.
26 ERROR
27 Memory write error, use debug for more info.
28 commands.c:360: Error writing memory data. (err -4)
29 17
30Or, if you see this sort of message for a Pro Micro based controller: 18[SparkFun Pro Micro](https://www.sparkfun.com/products/12640)
31 19
32 avrdude: butterfly_recv(): programmer is not responding 20To use a 5V/16MHz Pro Micro as an ISP flashing tool, you will first need to load a [special firmware](https://github.com/qmk/qmk_firmware/blob/master/util/pro_micro_ISP_B6_10.hex) onto it that emulates a hardware ISP flasher.
33 avrdude: butterfly_recv(): programmer is not responding
34 avrdude: verification error, first mismatch at byte 0x002a
35 0x2b != 0x75
36 avrdude: verification error; content mismatch
37 avrdude: verification error; content mismatch
38 21
22**AVRDUDE Programmer**: `avrisp`
23**AVRDUDE Port**: Serial
39 24
40You're likely going to need to ISP flash your board/device to get it working again. 25#### Wiring
41 26
42## Hardware Needed 27|Pro Micro |Keyboard|
28|-----------|--------|
29|`VCC` |`VCC` |
30|`GND` |`GND` |
31|`10` (`B6`)|`RESET` |
32|`15` (`B1`)|`SCLK` |
33|`16` (`B2`)|`MOSI` |
34|`14` (`B3`)|`MISO` |
43 35
44You'll need one of the following to actually perform the ISP flashing (followed by the protocol they use): 36!> Note that the `10` pin on the Pro Micro should be wired to the `RESET` pin on the keyboard's controller. ***DO NOT*** connect the `RESET` pin on the Pro Micro to the `RESET` on the keyboard.
45 37
46* [SparkFun PocketAVR](https://www.sparkfun.com/products/9825) - (USB Tiny) 38### Teensy 2.0 as ISP
47* [USBtinyISP AVR Programmer Kit](https://www.adafruit.com/product/46) - (USB Tiny)
48* [USBasp](https://www.fischl.de/usbasp/) - (usbasp)
49* [Teensy 2.0](https://www.pjrc.com/store/teensy.html) - (avrisp)
50* [Pro Micro](https://www.sparkfun.com/products/12640) - (avrisp)
51* [Bus Pirate](https://www.adafruit.com/product/237) - (buspirate)
52 39
53There are other devices that can be used to ISP flash, but these are the main ones. Also, all product links are to the official versions. You can source them elsewhere. 40[PJRC Teensy 2.0](https://www.pjrc.com/store/teensy.html)
54 41
55You'll also need something to wire your "ISP Programmer" to the device that you're programming. Some PCBs may have ISP headers that you can use directly, but this often isn't the case, so you'll likely need to solder to the controller itself or to different switches or other components. 42To use a Teensy 2.0 as an ISP flashing tool, you will first need to load a [special firmware](https://github.com/qmk/qmk_firmware/blob/master/util/teensy_2.0_ISP_B0.hex) onto it that emulates a hardware ISP flasher.
56 43
57### The ISP Firmware 44**AVRDUDE Programmer**: `avrisp`
45**AVRDUDE Port**: Serial
58 46
59The Teensy and Pro Micro controllers will need you to flash the ISP firmware to the controllers before you can use them as an ISP programmer. The rest of the hardware should come preprogrammed. So, for these controllers, download the correct hex file, and flash it first. 47#### Wiring
60 48
61* Teensy 2.0: [`util/teensy_2.0_ISP_B0.hex`](https://github.com/qmk/qmk_firmware/blob/master/util/teensy_2.0_ISP_B0.hex) (`B0`) 49|Teensy|Keyboard|
62* Pro Micro: [`util/pro_micro_ISP_B6_10.hex`](https://github.com/qmk/qmk_firmware/blob/master/util/pro_micro_ISP_B6_10.hex) (`10/B6`) 50|------|--------|
51|`VCC` |`VCC` |
52|`GND` |`GND` |
53|`B0` |`RESET` |
54|`B1` |`SCLK` |
55|`B2` |`MOSI` |
56|`B3` |`MISO` |
63 57
64Once you've flashed your controller, you won't need this hex file anymore. 58!> Note that the `B0` pin on the Teensy should be wired to the `RESET` pin on the keyboard's controller. ***DO NOT*** connect the `RESET` pin on the Teensy to the `RESET` on the keyboard.
65 59
66## Software Needed 60### SparkFun PocketAVR / USBtinyISP / USBasp
67 61
68The QMK Toolbox can be used for most (all) of this. 62[SparkFun PocketAVR](https://www.sparkfun.com/products/9825)
63[Adafruit USBtinyISP](https://www.adafruit.com/product/46)
64[Thomas Fischl's USBasp](https://www.fischl.de/usbasp/)
69 65
70However, you can grab the [Teensy Loader](https://www.pjrc.com/teensy/loader.html) to flash your Teensy 2.0 board, if you are using that. Or you can use `avrdude` (installed as part of `qmk_install.sh`), or [AVRDUDESS](https://blog.zakkemble.net/avrdudess-a-gui-for-avrdude/) (for Windows) to flash the Pro Micro, and the ISP flashing. 66**AVRDUDE Programmer**: `usbtiny` / `usbasp`
67**AVRDUDE Port**: `usb`
71 68
69#### Wiring
72 70
73## Wiring 71|ISP |Keyboard|
72|---------|--------|
73|`VCC` |`VCC` |
74|`GND` |`GND` |
75|`RST` |`RESET` |
76|`SCLK` |`SCLK` |
77|`MOSI` |`MOSI` |
78|`MISO` |`MISO` |
74 79
75This is pretty straight-forward - we'll be connecting like-things to like-things in the following manner.
76 80
77### SparkFun Pocket AVR 81### Bus Pirate
78 82
79 PocketAVR RST <-> Keyboard RESET 83[Adafruit Bus Pirate](https://www.adafruit.com/product/237)
80 PocketAVR SCLK <-> Keyboard B1 (SCLK)
81 PocketAVR MOSI <-> Keyboard B2 (MOSI)
82 PocketAVR MISO <-> Keyboard B3 (MISO)
83 PocketAVR VCC <-> Keyboard VCC
84 PocketAVR GND <-> Keyboard GND
85 84
86### USBasp 85!> The 5-pin "ICSP" header is for ISP flashing the PIC microcontroller of the Bus Pirate. Connect your target board to the 10-pin header opposite the USB connector instead.
87 86
88 USBasp RST <-> Keyboard RESET 87**AVRDUDE Programmer**: `buspirate`
89 USBasp SCLK <-> Keyboard B1 (SCLK) 88**AVRDUDE Port**: Serial
90 USBasp MOSI <-> Keyboard B2 (MOSI)
91 USBasp MISO <-> Keyboard B3 (MISO)
92 USBasp VCC <-> Keyboard VCC
93 USBasp GND <-> Keyboard GND
94 89
95### Teensy 2.0 90#### Wiring
96 91
97 Teensy B0 <-> Keyboard RESET 92|Bus Pirate|Keyboard|
98 Teensy B1 <-> Keyboard B1 (SCLK) 93|----------|--------|
99 Teensy B2 <-> Keyboard B2 (MOSI) 94|`+5V` |`VCC` |
100 Teensy B3 <-> Keyboard B3 (MISO) 95|`GND` |`GND` |
101 Teensy VCC <-> Keyboard VCC 96|`RST` |`RESET` |
102 Teensy GND <-> Keyboard GND 97|`CLK` |`SCLK` |
103 98|`MOSI` |`MOSI` |
104!> Note that the B0 pin on the Teensy is wired to the RESET/RST pin on the keyboard's controller. ***DO NOT*** wire the RESET pin on the Teensy to the RESET on the keyboard. 99|`MISO` |`MISO` |
105
106### Pro Micro
107
108 Pro Micro 10 (B6) <-> Keyboard RESET
109 Pro Micro 15 (B1) <-> Keyboard B1 (SCLK)
110 Pro Micro 16 (B2) <-> Keyboard B2 (MOSI)
111 Pro Micro 14 (B3) <-> Keyboard B3 (MISO)
112 Pro Micro VCC <-> Keyboard VCC
113 Pro Micro GND <-> Keyboard GND
114
115!> Note that the 10/B6 pin on the Pro Micro is wired to the RESET/RST pin on the keyboard's controller. ***DO NOT*** wire the RESET pin on the Pro Micro to the RESET on the keyboard.
116
117
118## Flashing Your Keyboard
119
120After you have your ISP programmer set up, and wired to your keyboard, it's time to flash your keyboard.
121
122### The Bootloader File
123
124The simplest and quickest way to get things back to normal is to flash only a bootloader to the keyboard. Once this is done, you can connect the keyboard normally and flash the keyboard like you normally would.
125
126You can find the stock bootloaders in the [`util/` folder](https://github.com/qmk/qmk_firmware/tree/master/util). Be sure to flash the correct bootloader for your chip:
127
128* **Atmel DFU**
129 * [ATmega16U4](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega16u4_1.0.1.hex)
130 * [ATmega32U4](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32u4_1.0.0.hex)
131 * [AT90USB64](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb64_1.0.0.hex)
132 * [AT90USB128](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb128_1.0.1.hex)
133* **Caterina**
134 * [Pro Micro (5V/16MHz)](https://github.com/sparkfun/Arduino_Boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina-promicro16.hex)
135 * [Pro Micro (3.3V/8MHz)](https://github.com/sparkfun/Arduino_Boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina-promicro8.hex)
136* **BootloadHID (PS2AVRGB)**
137 * [ATmega32A](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_ps2avrgb_bootloadhid_1.0.1.hex)
138
139If you're not sure what your board uses, look in the `rules.mk` file for the keyboard in QMK. The `MCU` and `BOOTLOADER` lines will have the value you need. It may differ between different versions of the board.
140
141### Production Techniques
142
143If you'd like to flash both the bootloader **and** the regular firmware at the same time, there are two options to do so. Manually, or with the `:production` target when compiling.
144
145To do this manually:
146
1471. Open the original firmware .hex file in a text editor
1482. Remove the last line (which should be `:00000001FF` - this is an EOF message)
1493. Copy the entire bootloader's contents onto a new line (with no empty lines between) and paste it at the end of the original file
1504. Save it as a new file by naming it `<keyboard>_<keymap>_production.hex`
151 100
152?> It's possible to use other bootloaders here in the same way, but __you need a bootloader__, otherwise you'll have to use ISP again to write new firmware to your keyboard. 101## Software
153 102
154#### Create QMK DFU Bootloader and Production images 103[QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) supports flashing both the ISP firmware and bootloader, but note that it cannot (currently) set the AVR fuse bytes for the actual ISP flashing step, so you may want to work with `avrdude` directly instead.
155 104
156You can create the firmware, the QMK DFU Bootloader and the production firmware images for the board using the `:production` target when compiling. Once this is done, you'll see three files: 105Setting up the [QMK environment](newbs.md) is highly recommended, as it automatically installs `avrdude` along with a host of other tools.
157* `<keyboard>_<keymap>.hex`
158* `<keyboard>_<keymap>_bootloader.hex`
159* `<keyboard>_<keymap>_production.hex`
160 106
161The QMK DFU bootloader has only really been tested on `atmega32u4` controllers (such as the AVR based Planck boards, and the Pro Micro), and hasn't been tested on other controllers. However, it will definitely not work on V-USB controllers, such as the `atmega32a` or `atmega328p`. 107## Bootloader Firmware
162 108
163You can flash either the bootloader or the production firmware file. The production firmware file will take a lot longer to flash, since it's flashing a lot more data. 109One of these files is what you will be ISP flashing onto the board. The default fuses are also listed.
164 110
165?> Note: You should stay with the same bootloader. If you're using DFU already, switching to QMK DFU is fine. But flashing QMK DFU onto a Pro Micro, for instance, has additional steps needed. 111If you're not sure what your board uses, look in the `rules.mk` file for the keyboard in QMK. The `MCU` and `BOOTLOADER` lines will have the values you need. It may differ between different versions of the board.
166 112
167## Flashing Your Bootloader/Production File 113### Atmel DFU
168 114
169Make sure your keyboard is unplugged from any device, and plug in your ISP Programmer. 115These are the [factory default bootloaders](https://www.microchip.com/content/dam/mchp/documents/OTH/ProductDocuments/SoftwareLibraries/Firmware/megaUSB_DFU_Bootloaders.zip) shipped by Atmel (now Microchip). Note that the AT90USB64 and AT90USB128 bootloaders are [slightly modified](https://github.com/qmk/qmk_firmware/pull/14064), due to a bug causing them to not enumerate properly in Windows 8 and later.
170 116
171If you want to change bootloader types, You'll need to use the command line. 117|MCU |Low |High |Extended|USB ID |
118|--------------------------------------------------------------------------------------------------|------|-------------------------------|--------|-----------|
119|[ATmega16U4](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega16u4_1.0.1.hex)|`0x5E`|`0x99` / `0xD9` (JTAG disabled)|`0xF3` |`03EB:2FF3`|
120|[ATmega32U4](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32u4_1.0.0.hex)|`0x5E`|`0x99` / `0xD9` (JTAG disabled)|`0xF3` |`03EB:2FF4`|
121|[AT90USB64](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb64_1.0.0.hex) |`0x5E`|`0x9B` / `0xDB` (JTAG disabled)|`0xF3` |`03EB:2FF9`|
122|[AT90USB128](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb128_1.0.1.hex)|`0x5E`|`0x99` / `0xD9` (JTAG disabled)|`0xF3` |`03EB:2FFB`|
172 123
173### QMK Toolbox 124### Caterina
174 125
1751. `AVRISP device connected` or `USB Tiny device connected` will show up in yellow 126This is the default Arduino-style bootloader derived from the [LUFA CDC bootloader](https://github.com/abcminiuser/lufa/tree/master/Bootloaders/CDC), and is only for the ATmega32U4.
1762. Select the correct bootloader/production .hex file with the `Open` dialog (spaces can't be in the path)
1773. Be sure the correct `Microcontroller` option for the keyboard you're flashing (not the ISP programmer) is selected
1784. Hit `Flash`
1795. Wait, as nothing will output for a while, especially with production files
180 127
181If the verification and fuse checks are ok, you're done! Your board may restart automatically, otherwise, unplug your Teensy and plug in your keyboard - you can leave your Teensy wired to your keyboard while testing things, but it's recommended that you desolder it/remove the wiring once you're sure everything works. 128There are several variants depending on the vendor, but they all mostly work the same way. The SparkFun variants, for example, require the `RESET` pin to be [grounded twice quickly](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide#ts-reset) in order to stay in bootloader mode for more than 750 ms.
182 129
183### Command Line 130|MCU |Low |High |Extended|USB ID |
131|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------|--------|-----------|
132|[SparkFun Pro Micro (3V3/8MHz)](https://github.com/sparkfun/Arduino_Boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina-promicro8.hex) |`0xFF`|`0xD8`|`0xFE` |`1B4F:9203`|
133|[SparkFun Pro Micro (5V/16MHz)](https://github.com/sparkfun/Arduino_Boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina-promicro16.hex) |`0xFF`|`0xD8`|`0xFB` |`1B4F:9205`|
134|[SparkFun LilyPadUSB (and some Pro Micro clones)](https://github.com/sparkfun/Arduino_Boards/blob/main/sparkfun/avr/bootloaders/caterina/Caterina-lilypadusb.hex)|`0xFF`|`0xD8`|`0xFE` |`1B4F:9207`|
135|[Pololu A-Star 32U4](https://github.com/pololu/a-star/blob/master/bootloaders/caterina/Caterina-A-Star.hex)* |`0xFF`|`0xD0`|`0xF8` |`1FFB:0101`|
136|[Adafruit Feather 32U4](https://github.com/adafruit/Caterina-Bootloader/blob/master/Built%20Firmwares/Caterina-Feather32u4.hex) |`0xFF`|`0xD8`|`0xFB` |`239A:000C`|
137|[Adafruit ItsyBitsy 32U4 (3V3/8MHz)](https://github.com/adafruit/Caterina-Bootloader/blob/master/Caterina_itsybitsy3V.hex)* |`0xFF`|`0xD8`|`0xFB` |`239A:000D`|
138|[Adafruit ItsyBitsy 32U4 (5V/16MHz)](https://github.com/adafruit/Caterina-Bootloader/blob/master/Caterina_itsybitsy5V.hex) |`0xFF`|`0xD8`|`0xFB` |`239A:000E`|
139|[Arduino Leonardo](https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/caterina/Caterina-Leonardo.hex)* |`0xFF`|`0xD8`|`0xFB` |`2341:0036`|
140|[Arduino Micro](https://github.com/arduino/ArduinoCore-avr/blob/master/bootloaders/caterina/Caterina-Micro.hex)* |`0xFF`|`0xD8`|`0xFB` |`2341:0037`|
184 141
185Open a terminal (`cmd` on Windows, for instance) and navigate to your where your modified .hex file is. We'll pretend this file is called `main.hex`, and that your Teensy 2.0 is on the `COM3` port - if you're unsure, you can open your Device Manager, and look for `Ports > USB Serial Device`. Use that COM port here. You can confirm it's the right port with: 142?> Files marked with a * have combined Arduino sketches, which runs by default and also appears as a serial port. However, this is *not* the bootloader device.
186 143
187 avrdude -c avrisp -P COM3 -p atmega32u4 144### BootloadHID (PS2AVRGB)
188 145
189and you should get something like the following output: 146This bootloader is primarily for keyboards originally designed for the PS2AVRGB firmware and Bootmapper Client. It is not recommended for use in new designs.
190 147
191 avrdude: AVR device initialized and ready to accept instructions 148|MCU |Low |High |USB ID |
149|-----------------------------------------------------------------------------------------------------------|------|------|-----------|
150|[ATmega32A](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_ps2avrgb_bootloadhid_1.0.1.hex)|`0x0F`|`0xD0`|`16C0:05DF`|
192 151
193 Reading | ################################################## | 100% 0.02s 152### USBaspLoader
194 153
195 avrdude: Device signature = 0x1e9587 154USBaspLoader is a bootloader based on V-USB that emulates a hardware USBasp device. It runs on ATmega32A and ATmega328P MCUs.
196 155
197 avrdude: safemode: Fuses OK 156Precompiled `.hex` files are generally not available, but you can compile it yourself by setting up the QMK environment and following Coseyfannitutti's guide for the appropriate MCU:
198 157
199 avrdude done. Thank you. 158|MCU |Low |High |Extended|USB ID |
159|-------------------------------------------------------------------------------------|------|------|--------|-----------|
160|[ATmega32A](https://github.com/coseyfannitutti/discipline/tree/master/doc/bootloader)|`0x1F`|`0xC0`|*n/a* |`16C0:05DC`|
161|[ATmega328P](https://github.com/coseyfannitutti/discipad/tree/master/doc/bootloader) |`0xD7`|`0xD0`|`0x04` |`16C0:05DC`|
200 162
201Since our keyboard uses an `atmega32u4` (common), that is the chip we'll specify. This is the full command: 163Note that some boards may have their own specialized build of this bootloader in a separate repository. This will usually be linked to in the board's readme.
202 164
203 avrdude -c avrisp -P COM3 -p atmega32u4 -U flash:w:main.hex:i 165## Flashing the Bootloader
204 166
205If your board uses an `atmega32a` (e.g. on a jj40), the command is this (the extra code at the end sets the fuses correctly): 167Open a new Terminal window - if you are on Windows, use MSYS2 or QMK MSYS, not the Command Prompt. Navigate to the directory your bootloader `.hex` is in. Now it's time to run the `avrdude` command.
206 168
207 avrdude -c avrisp -P COM3 -p atmega32 -U flash:w:main.hex:i -U hfuse:w:0xD0:m -U lfuse:w:0x0F:m 169The syntax of `avrdude` is:
208 170
209You should see a couple of progress bars, then you should see: 171```
172avrdude -c <programmer> -P <port> -p <mcu> -U flash:w:<filename>:i
173```
210 174
211 avrdude: verifying ... 175 * `<programmer>` corresponds to the programmer type listed for each ISP flasher in the [Hardware](#hardware) section, for example `avrisp`.
212 avrdude: 32768 bytes of flash verified 176 * `<port>` is the serial port that appears when you plug the ISP flasher in, if any. For some programmers this is simply `usb` (or you can omit the `-P` argument completely) since they do not operate as a serial device.
177 * Windows: `COMx` - check Device Manager, under the "Ports (COM & LPT)" section
178 * Linux: `/dev/ttyACMx`
179 * macOS: `/dev/tty.usbmodemXXXXXX`
180 * `<mcu>` should be the lowercase name of the target AVR microcontroller, for example `atmega32u4`.
181 * `<filename>` is the absolute or relative path to the bootloader to be flashed, for example `Caterina-Micro.hex`.
213 182
214 avrdude: safemode: Fuses OK 183You can also run `man avrdude` for more information.
215 184
216 avrdude done. Thank you. 185If all goes well, you should get output similar to the following:
217 186
218Which means everything should be ok! Your board may restart automatically, otherwise, unplug your Teensy and plug in your keyboard - you can leave your Teensy wired to your keyboard while testing things, but it's recommended that you desolder it/remove the wiring once you're sure everything works. 187```
188avrdude: AVR device initialized and ready to accept instructions
219 189
220If you're using a SparkFun PocketAVR Programmer, or another USB Tiny based ISP programmer, you will want to use something like this: 190Reading | ################################################## | 100% 0.00s
221 191
222 avrdude -c usbtiny -P usb -p atmega32u4 192avrdude: Device signature = 0x1e9587 (probably m32u4)
193avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
194 To disable this feature, specify the -D option.
195avrdude: erasing chip
196avrdude: reading input file "Caterina-Micro.hex"
197avrdude: writing flash (32730 bytes):
223 198
224#### Advanced: Changing Fuses 199Writing | ################################################## | 100% 11.58s
225 200
226If you're switching bootloaders, such as flashing QMK DFU on a Pro Micro, you will need to change the fuses, in additional to flashing the bootloader hex file. This is because `caterina` (the Pro Micro bootloader) and `dfu` handle the startup routines differently, and that behavior is controlled by the fuses. 201avrdude: 32730 bytes of flash written
202avrdude: verifying flash memory against Caterina-Micro.hex:
203avrdude: load data flash data from input file Caterina-Micro.hex:
204avrdude: input file Caterina-Micro.hex contains 32730 bytes
205avrdude: reading on-chip flash data:
227 206
228!> This is one area that it is very important to be careful, as changing fuses is one of the ways that you can permanently brick your controller. 207Reading | ################################################## | 100% 10.33s
229 208
230For this, we are assuming the 5V 16MHz versions of the `atmega32u4` (such as the 5V Pro Micro). 209avrdude: verifying ...
210avrdude: 32730 bytes of flash verified
231 211
232For DFU on the `atmega32u4`, these are the fuse settings that you want: 212avrdude: safemode: Fuses OK (E:CB, H:D8, L:FF)
233 213
234| Fuse | Setting | 214avrdude done. Thank you.
235|----------|------------------| 215```
236| Low | `0x5E` |
237| High | `0xD9` or `0x99` |
238| Extended | `0xC3` |
239 216
240The High fuse can be 0xD9 or 0x99. The difference is that 0xD9 disables JTAG, which QMK Firmware disables via software as well, while 0x99 doesn't disable JTAG. 217### Setting the Fuses
241 218
242To set this add `-U lfuse:w:0x5E:m -U hfuse:w:0xD9:m -U efuse:w:0xC3:m` to your command. So the final command should look something like: 219This is a slightly more advanced topic, but may be necessary if you are switching from one bootloader to another (for example, Caterina to Atmel/QMK DFU on a Pro Micro). Fuses control some of the low-level functionality of the AVR microcontroller, such as clock speed, whether JTAG is enabled, and the size of the section of flash memory reserved for the bootloader, among other things. You can find a fuse calculator for many AVR parts [here](https://www.engbedded.com/conffuse/).
243 220
244 avrdude -c avrisp -P COM3 -p atmega32u4 -U flash:w:main.hex:i -U lfuse:w:0x5E:m -U hfuse:w:0xD9:m -U efuse:w:0xC3:m 221!> **WARNING:** Setting incorrect fuse values, in particular the clock-related bits, may render the MCU practically unrecoverable without high voltage programming (not covered here)! Make sure to double check the commands you enter before you execute them.
245 222
246For Caterina on the `atmega32u4`, these are the fuse settings that you want: 223To set the fuses, add the following to the `avrdude` command:
247 224
248| Fuse | Setting| 225```
249|----------|--------| 226-U lfuse:w:0xXX:m -U hfuse:w:0xXX:m -U efuse:w:0xXX:m
250| Low | `0xFF` | 227```
251| High | `0xD8` |
252| Extended | `0xCB` |
253 228
254To set this add `-U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xCB:m` to your command. So the final command should look something like: 229where the `lfuse`, `hfuse` and `efuse` arguments represent the low, high and extended fuse bytes as listed in the [Hardware](#hardware) section.
255 230
256 avrdude -c avrisp -P COM3 -p atmega32u4 -U flash:w:main.hex:i -U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xCB:m 231?> You may get a warning from `avrdude` that the extended fuse byte does not match what you provided when reading it back. If the second hex digit matches, this can usually be safely ignored, because the top four bits of this fuse do not actually exist on many AVR parts, and may read back as anything.
257 232
233## Creating a "Production" Firmware
258 234
259If you are using a different controller or want different configuration, you can use [this AVR Fuse Calculator](https://www.engbedded.com/fusecalc/) to find a better value for you. 235For mass production purposes, it is possible to join the bootloader and QMK firmware together into a single file, due to the way the [Intel Hex format](https://en.wikipedia.org/wiki/Intel_HEX) works:
260 236
261## Help 237 1. Open the QMK firmware and bootloader `.hex` files in a text editor.
238 2. Remove the last line of the QMK firmware (which should be `:00000001FF` - this is just an "end of file" marker).
239 3. Paste the contents of the bootloader `.hex` file onto a new line at the end of the QMK firmware file, with no empty lines between.
240 4. Save it as a new file, for example `<keyboard>_<keymap>_production.hex`.
262 241
263If you have any questions/problems, feel free to [open an issue](https://github.com/qmk/qmk_firmware/issues/new)! 242You can then ISP flash this combined firmware instead, which allows you to skip the extra step of flashing the QMK firmware over USB.