]> git.donarmstrong.com Git - qmk_firmware.git/blob - docs/flashing.md
18ae6364d42efdcc6c968097167866d16cab8f56
[qmk_firmware.git] / docs / flashing.md
1 # Flashing Instructions and Bootloader Information
2
3 There are quite a few different types of bootloaders that keyboards use, and just about all of the use a different flashing method. Luckily, projects like the [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) aim to be compatible with all the different types without having to think about it much, but this article will describe the different types of bootloaders, and available methods for flashing them.
4
5 If you have a bootloader selected with the `BOOTLOADER` variable in your `rules.mk`, QMK will automatically calculate if your .hex file is the right size to be flashed to the device, and output the total size in bytes (along with the max). To run this process manually, compile with the target `check-size`, eg `make planck/rev4:default:check-size`.
6
7 ## DFU
8
9 Atmel's DFU bootloader comes on all atmega32u4 chips by default, and is used by many keyboards that have their own ICs on their PCBs (Older OLKB boards, Clueboards). Some keyboards may also use LUFA's DFU bootloader (or QMK's fork) (Newer OLKB boards) that adds in additional features specific to that hardware.
10
11 To ensure compatibility with the DFU bootloader, make sure this block is present your `rules.mk` (optionally with `lufa-dfu` or `qmk-dfu` instead):
12
13 ```make
14 # Bootloader selection
15 #   Teensy       halfkay
16 #   Pro Micro    caterina
17 #   Atmel DFU    atmel-dfu
18 #   LUFA DFU     lufa-dfu
19 #   QMK DFU      qmk-dfu
20 #   ATmega32A    bootloadHID
21 #   ATmega328P   USBasp
22 BOOTLOADER = atmel-dfu
23 ```
24
25 Compatible flashers:
26
27 * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
28 * [dfu-programmer](https://github.com/dfu-programmer/dfu-programmer) / `:dfu` in QMK (recommended command line)
29 * [Atmel's Flip](http://www.microchip.com/developmenttools/productdetails.aspx?partno=flip) (not recommended)
30
31 Flashing sequence:
32
33 1. Press the `RESET` keycode, or tap the RESET button (or short RST to GND).
34 2. Wait for the OS to detect the device
35 3. Erase the memory (may be done automatically)
36 4. Flash a .hex file
37 5. Reset the device into application mode (may be done automatically)
38
39 or:
40
41     make <keyboard>:<keymap>:dfu
42
43 ### QMK DFU
44
45 QMK has a fork of the LUFA DFU bootloader that allows for a simple matrix scan for exiting the bootloader and returning to the application, as well as flashing an LED/making a ticking noise with a speaker when things are happening. To enable these features, use this block in your `config.h` (The key that exits the bootloader needs to be hooked-up to the INPUT and OUTPUT defined here):
46
47     #define QMK_ESC_OUTPUT F1 // usually COL
48     #define QMK_ESC_INPUT D5 // usually ROW
49     #define QMK_LED E6
50     #define QMK_SPEAKER C6
51
52 The Manufacturer and Product names are automatically pulled from your `config.h`, and "Bootloader" is added to the product.
53
54 To generate this bootloader, use the `bootloader` target, eg `make planck/rev4:default:bootloader`.
55
56 To generate a production-ready .hex file (containing the application and the bootloader), use the `production` target, eg `make planck/rev4:default:production`.
57
58 ### DFU commands
59
60 There are a number of DFU commands that you can use to flash firmware to a DFU device:
61
62 * `:dfu` - This is the normal option and waits until a DFU device is available, and then flashes the firmware. This will check every 5 seconds, to see if a DFU device has appeared.
63 * `:dfu-ee` - This flashes an `eep` file instead of the normal hex.  This is uncommon. 
64 * `:dfu-split-left` - This flashes the normal firmware, just like the default option (`:dfu`). However, this also flashes the "Left Side" EEPROM file for split keyboards. _This is ideal for Elite C based split keyboards._
65 * `:dfu-split-right` - This flashes the normal firmware, just like the default option (`:dfu`). However, this also flashes the "Right Side" EEPROM file for split keyboards. _This is ideal for Elite C based split keyboards._
66
67 ## Caterina
68
69 Arduino boards and their clones use the [Caterina bootloader](https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/caterina) (any keyboard built with a Pro Micro, or clone), and uses the avr109 protocol to communicate through virtual serial. Bootloaders like [A-Star](https://www.pololu.com/docs/0J61/9) are based on Caterina.
70
71 To ensure compatibility with the Caterina bootloader, make sure this block is present your `rules.mk`:
72
73 ```make
74 # Bootloader selection
75 #   Teensy       halfkay
76 #   Pro Micro    caterina
77 #   Atmel DFU    atmel-dfu
78 #   LUFA DFU     lufa-dfu
79 #   QMK DFU      qmk-dfu
80 #   ATmega32A    bootloadHID
81 #   ATmega328P   USBasp
82 BOOTLOADER = caterina
83 ```
84
85 Compatible flashers:
86
87 * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
88 * [avrdude](http://www.nongnu.org/avrdude/) with avr109 / `:avrdude` (recommended command line)
89 * [AVRDUDESS](https://github.com/zkemble/AVRDUDESS)
90
91 Flashing sequence:
92
93 1. Press the `RESET` keycode, or short RST to GND quickly (you only have 7 seconds to flash once it enters)
94 2. Wait for the OS to detect the device
95 3. Flash a .hex file
96 4. Wait for the device to reset automatically
97
98 or
99
100     make <keyboard>:<keymap>:avrdude
101
102 or if you want to flash multiple boards, use the following command
103
104     make <keyboard>:<keymap>:avrdude-loop
105
106 When you're done flashing boards, you'll need to hit Ctrl + C or whatever the correct keystroke is for your operating system to break the loop.
107
108
109 ## Halfkay
110
111 Halfkay is a super-slim protocol developed by PJRC that uses HID, and come on all Teensys (namely the 2.0).
112
113 To ensure compatibility with the Halfkay bootloader, make sure this block is present your `rules.mk`:
114
115 ```make
116 # Bootloader selection
117 #   Teensy       halfkay
118 #   Pro Micro    caterina
119 #   Atmel DFU    atmel-dfu
120 #   LUFA DFU     lufa-dfu
121 #   QMK DFU      qmk-dfu
122 #   ATmega32A    bootloadHID
123 #   ATmega328P   USBasp
124 BOOTLOADER = halfkay
125 ```
126
127 Compatible flashers:
128
129 * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
130 * [Teensy Loader](https://www.pjrc.com/teensy/loader.html)
131 * [Teensy Loader Command Line](https://www.pjrc.com/teensy/loader_cli.html) (recommended command line)
132
133 Flashing sequence:
134
135 1. Press the `RESET` keycode, or short RST to GND quickly (you only have 7 seconds to flash once it enters)
136 2. Wait for the OS to detect the device
137 3. Flash a .hex file
138 4. Reset the device into application mode (may be done automatically)
139
140 ## USBasploader
141
142 USBasploader is a bootloader developed by matrixstorm. It is used in some non-USB AVR chips such as the ATmega328P, which run V-USB.
143
144 To ensure compatibility with the USBasploader bootloader, make sure this block is present in your `rules.mk`:
145
146 ```make
147 # Bootloader selection
148 #   Teensy       halfkay
149 #   Pro Micro    caterina
150 #   Atmel DFU    atmel-dfu
151 #   LUFA DFU     lufa-dfu
152 #   QMK DFU      qmk-dfu
153 #   ATmega32A    bootloadHID
154 #   ATmega328P   USBasp
155 BOOTLOADER = USBasp
156 ```
157
158 Compatible flashers:
159
160 * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
161 * [avrdude](http://www.nongnu.org/avrdude/) with the `usbasp` programmer
162 * [AVRDUDESS](https://github.com/zkemble/AVRDUDESS)
163
164 Flashing sequence:
165
166 1. Press the `RESET` keycode, or keep the boot pin shorted to GND while quickly shorting RST to GND
167 2. Wait for the OS to detect the device
168 3. Flash a .hex file
169 4. Reset the device into application mode (may be done automatically)
170
171 ## BootloadHID
172
173 BootloadHID is a USB bootloader for AVR microcontrollers. The uploader tool requires no kernel level driver on Windows and can therefore be run without installing any DLLs.
174
175 To ensure compatibility with the bootloadHID bootloader, make sure this block is present your `rules.mk`:
176
177 ```make
178 # Bootloader selection
179 #   Teensy       halfkay
180 #   Pro Micro    caterina
181 #   Atmel DFU    atmel-dfu
182 #   LUFA DFU     lufa-dfu
183 #   QMK DFU      qmk-dfu
184 #   ATmega32A    bootloadHID
185 #   ATmega328P   USBasp
186 BOOTLOADER = bootloadHID
187 ```
188
189 Compatible flashers:
190
191 * [HIDBootFlash](http://vusb.wikidot.com/project:hidbootflash) (recommended Windows GUI)
192 * [bootloadhid Command Line](https://www.obdev.at/products/vusb/bootloadhid.html) / `:BootloadHID` in QMK (recommended command line)
193
194 Flashing sequence:
195
196 1. Enter the bootloader using any of the following methods:
197     * Tap the `RESET` keycode (may not work on all devices)
198     * Hold the salt key while plugging the keyboard in (usually documented within keyboard readme) 
199 2. Wait for the OS to detect the device
200 3. Flash a .hex file
201 4. Reset the device into application mode (may be done automatically)
202
203 or:
204
205     make <keyboard>:<keymap>:bootloadHID
206
207 ## STM32
208
209 All STM32 chips come preloaded with a factory bootloader that cannot be modified nor deleted. Some STM32 chips have bootloaders that do not come with USB programming (e.g. STM32F103) but the process is still the same.
210
211 At the moment, no `BOOTLOADER` variable is needed on `rules.mk` for STM32.
212
213 Compatible flashers:
214
215 * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
216 * [dfu-util](https://github.com/Stefan-Schmidt/dfu-util) / `:dfu-util` (recommended command line)
217
218 Flashing sequence:
219
220 1. Enter the bootloader using any of the following methods:
221     * Tap the `RESET` keycode (may not work on STM32F042 devices)
222     * If a reset circuit is present, tap the RESET button
223     * Otherwise, you need to bridge BOOT0 to VCC (via BOOT0 button or bridge), short RESET to GND (via RESET button or bridge), and then let go of the BOOT0 bridge
224 2. Wait for the OS to detect the device
225 3. Flash a .bin file
226     * You will receive a warning about the DFU signature; Just ignore it
227 4. Reset the device into application mode (may be done automatically)
228     * If you are building from command line (e.g. `make planck/rev6:default:dfu-util`), make sure that `:leave` is passed to the `DFU_ARGS` variable inside your `rules.mk` (e.g. `DFU_ARGS = -d 0483:df11 -a 0 -s 0x08000000:leave`) so that your device resets after flashing
229
230 ### STM32 Commands
231
232 There are a number of DFU commands that you can use to flash firmware to a STM32 device:
233
234 * `:dfu-util` - The default command for flashing to STM32 devices.
235 * `:dfu-util-split-left` - This flashes the normal firmware, just like the default option (`:dfu-util`). However, this also configures the "Left Side" EEPROM setting for split keyboards.
236 * `:dfu-util-split-right` - This flashes the normal firmware, just like the default option (`:dfu-util`). However, this also configures the "Right Side" EEPROM setting for split keyboards.
237 * `:st-link-cli` - This allows you to flash the firmware via ST-LINK's CLI utility, rather than dfu-util.