You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

467 lines
20 KiB

  1. # Flashing Instructions and Bootloader Information
  2. There are quite a few different types of bootloaders that keyboards use, and almost all of them use their own flashing method and tools. Luckily, projects like the [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) aim to support as many of them as possible, but this article will describe the different types of bootloaders, and available methods for flashing them.
  3. For AVR-based keyboards, QMK will automatically calculate if your `.hex` file is the right size to be flashed to the device based on the `BOOTLOADER` value set in `rules.mk`, and output the total size in bytes (along with the max).
  4. You will also be able to use the CLI to flash your keyboard, by running:
  5. ```
  6. $ qmk flash -kb <keyboard> -km <keymap>
  7. ```
  8. See the [`qmk flash`](cli_commands.md#qmk-flash) documentation for more information.
  9. ## Atmel DFU
  10. Atmel's DFU bootloader comes on all USB AVRs by default (except for 16/32U4RC), 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 of it (newer OLKB boards), that adds in additional features specific to that hardware.
  11. To ensure compatibility with the DFU bootloader, make sure this block is present in your `rules.mk` (optionally with `lufa-dfu` or `qmk-dfu` instead):
  12. ```make
  13. # Bootloader selection
  14. BOOTLOADER = atmel-dfu
  15. ```
  16. Compatible flashers:
  17. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  18. * [dfu-programmer](https://github.com/dfu-programmer/dfu-programmer) / `:dfu` target in QMK (recommended command line)
  19. ```
  20. dfu-programmer <mcu> erase --force
  21. dfu-programmer <mcu> flash --force <filename>
  22. dfu-programmer <mcu> reset
  23. ```
  24. Flashing sequence:
  25. 1. Enter the bootloader using any of the following methods:
  26. * Press the `QK_BOOT` keycode
  27. * Press the `RESET` button on the PCB if available
  28. * Short RST to GND quickly
  29. 2. Wait for the OS to detect the device
  30. 3. Erase the flash memory (will be done automatically if using the Toolbox or CLI/`make` command)
  31. 4. Flash a .hex file
  32. 5. Reset the device into application mode (will be done automatically as above)
  33. ### QMK DFU
  34. QMK maintains [a fork of the LUFA DFU bootloader](https://github.com/qmk/lufa/tree/master/Bootloaders/DFU) that additionally performs 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, add the following defines to your `config.h`:
  35. ```c
  36. #define QMK_ESC_OUTPUT F1 // COL pin if COL2ROW
  37. #define QMK_ESC_INPUT D5 // ROW pin if COL2ROW
  38. // Optional:
  39. //#define QMK_LED E6
  40. //#define QMK_SPEAKER C6
  41. ```
  42. Currently we do not recommend making `QMK_ESC` the same key as the one designated for [Bootmagic Lite](feature_bootmagic.md), as holding it down will cause the MCU to loop back and forth between entering and exiting the bootloader.
  43. The manufacturer and product strings are automatically pulled from `config.h`, with " Bootloader" appended to the product string.
  44. To generate this bootloader, use the `bootloader` target, eg. `make planck/rev4:default:bootloader`. To generate a production-ready .hex file (combining QMK and the bootloader), use the `production` target, eg. `make planck/rev4:default:production`.
  45. ### `make` Targets
  46. * `:dfu`: Checks every 5 seconds until a DFU device is available, and then flashes the firmware.
  47. * `:dfu-split-left` and `:dfu-split-right`: Flashes the firmware as with `:dfu`, but also sets the handedness setting in EEPROM. This is ideal for Elite-C-based split keyboards.
  48. ## Caterina
  49. Arduino boards and their clones use the [Caterina bootloader](https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/caterina) or a variant of it (any keyboard built with a Pro Micro or clone, and the Pololu A-Star), and uses the AVR109 protocol to communicate through virtual serial.
  50. To ensure compatibility with the Caterina bootloader, make sure this block is present in your `rules.mk`:
  51. ```make
  52. # Bootloader selection
  53. BOOTLOADER = caterina
  54. ```
  55. Compatible flashers:
  56. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  57. * [AVRDUDESS](https://github.com/zkemble/AVRDUDESS)
  58. * [avrdude](https://www.nongnu.org/avrdude/) with the `avr109` programmer / `:avrdude` target in QMK (recommended command line)
  59. ```
  60. avrdude -p <mcu> -c avr109 -P <serialport> -U flash:w:<filename>:i
  61. ```
  62. Flashing sequence:
  63. 1. Enter the bootloader using any of the following methods (you only have 7 seconds to flash once it enters; some variants may require you to reset twice within 750 milliseconds):
  64. * Press the `QK_BOOT` keycode
  65. * Press the `RESET` button on the PCB if available
  66. * Short RST to GND quickly
  67. 2. Wait for the OS to detect the device
  68. 3. Flash a .hex file
  69. 4. Wait for the device to reset automatically
  70. ### `make` Targets
  71. * `:avrdude`: Checks every 5 seconds until a Caterina device is available (by detecting a new COM port), and then flashes the firmware.
  72. * `:avrdude-loop`: Flashes the firmware as with `:avrdude`, but after each device is flashed, will attempt to flash again. This is useful for bulk flashing. Hit Ctrl+C to escape the loop.
  73. * `:avrdude-split-left` and `:avrdude-split-right`: Flashes the firmware as with `:avrdude`, but also sets the handedness setting in EEPROM. This is ideal for Pro Micro-based split keyboards.
  74. ## HalfKay
  75. HalfKay is a super-slim bootloader developed by PJRC that presents itself as an HID device (which requires no additional driver), and comes preflashed on all Teensys, namely the 2.0. It is currently closed-source, and thus once overwritten (eg. via ISP flashing another bootloader), cannot be restored.
  76. To ensure compatibility with the Halfkay bootloader, make sure this block is present in your `rules.mk`:
  77. ```make
  78. # Bootloader selection
  79. BOOTLOADER = halfkay
  80. ```
  81. Compatible flashers:
  82. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  83. * [Teensy Loader](https://www.pjrc.com/teensy/loader.html)
  84. * [Teensy Loader Command Line](https://www.pjrc.com/teensy/loader_cli.html) / `:teensy` target in QMK (recommended command line)
  85. ```
  86. teensy_loader_cli -v -mmcu=<mcu> <filename>
  87. ```
  88. Flashing sequence:
  89. 1. Enter the bootloader using any of the following methods (you only have 7 seconds to flash once it enters):
  90. * Press the `QK_BOOT` keycode
  91. * Press the `RESET` button on the Teensy or PCB if available
  92. * short RST to GND quickly
  93. 2. Wait for the OS to detect the device
  94. 3. Flash a .hex file
  95. 4. Reset the device into application mode (may be done automatically)
  96. ## USBasploader
  97. USBasploader is a bootloader originally by [Objective Development](https://www.obdev.at/products/vusb/usbasploader.html). It emulates a USBasp ISP programmer and is used in some non-USB AVR chips such as the ATmega328P, which run V-USB.
  98. To ensure compatibility with the USBasploader bootloader, make sure this block is present in your `rules.mk`:
  99. ```make
  100. # Bootloader selection
  101. BOOTLOADER = usbasploader
  102. ```
  103. Compatible flashers:
  104. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  105. * [AVRDUDESS](https://github.com/zkemble/AVRDUDESS)
  106. * [avrdude](https://www.nongnu.org/avrdude/) with the `usbasp` programmer / `:usbasp` target in QMK (recommended command line)
  107. ```
  108. avrdude -p <mcu> -c usbasp -U flash:w:<filename>:i
  109. ```
  110. Flashing sequence:
  111. 1. Enter the bootloader using any of the following methods:
  112. * Press the `QK_BOOT` keycode
  113. * Keep the `BOOT` button held while quickly tapping the `RESET` button on the PCB
  114. 2. Wait for the OS to detect the device
  115. 3. Flash a .hex file
  116. 4. Press the `RESET` button on the PCB or short RST to GND
  117. ## BootloadHID
  118. BootloadHID is a USB bootloader for AVR microcontrollers. It presents itself as an HID input device, much like HalfKay, and can therefore be run without installing any driver on Windows.
  119. To ensure compatibility with the bootloadHID bootloader, make sure this block is present in your `rules.mk`:
  120. ```make
  121. # Bootloader selection
  122. BOOTLOADER = bootloadhid
  123. ```
  124. Compatible flashers:
  125. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  126. * [HIDBootFlash](http://vusb.wikidot.com/project:hidbootflash)
  127. * [bootloadHID CLI](https://www.obdev.at/products/vusb/bootloadhid.html) / `:bootloadhid` target in QMK (recommended command line)
  128. ```
  129. bootloadHID -r <filename>
  130. ```
  131. Flashing sequence:
  132. 1. Enter the bootloader using any of the following methods:
  133. * Tap the `QK_BOOT` keycode
  134. * Hold the salt key while plugging the keyboard in - for PS2AVRGB boards, this is usually the key connected to MCU pins A0 and B0, otherwise it will be documented in your keyboard's readme
  135. 2. Wait for the OS to detect the device
  136. 3. Flash a .hex file
  137. 4. Reset the device into application mode (may be done automatically)
  138. ### QMK HID
  139. QMK maintains [a fork of the LUFA HID bootloader](https://github.com/qmk/lufa/tree/master/Bootloaders/HID), which uses a USB HID Endpoint for flashing in the way that the PJRC's Teensy Loader flasher and HalfKay bootloader work. Additionally, it performs 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.
  140. To ensure compatibility with the QMK HID bootloader, make sure this block is present in your `rules.mk`:
  141. ```make
  142. # Bootloader selection
  143. BOOTLOADER = qmk-hid
  144. ```
  145. To enable the additional features, add the following defines to your `config.h`:
  146. ```c
  147. #define QMK_ESC_OUTPUT F1 // COL pin if COL2ROW
  148. #define QMK_ESC_INPUT D5 // ROW pin if COL2ROW
  149. // Optional:
  150. //#define QMK_LED E6
  151. //#define QMK_SPEAKER C6
  152. ```
  153. Currently we do not recommend making `QMK_ESC` the same key as the one designated for [Bootmagic Lite](feature_bootmagic.md), as holding it down will cause the MCU to loop back and forth between entering and exiting the bootloader.
  154. The manufacturer and product strings are automatically pulled from `config.h`, with " Bootloader" appended to the product string.
  155. To generate this bootloader, use the `bootloader` target, eg. `make planck/rev4:default:bootloader`. To generate a production-ready .hex file (combining QMK and the bootloader), use the `production` target, eg. `make planck/rev4:default:production`.
  156. Compatible flashers:
  157. * TBD
  158. * Currently, you need to either use the [Python script](https://github.com/qmk/lufa/tree/master/Bootloaders/HID/HostLoaderApp_python), or compile [`hid_bootloader_cli`](https://github.com/qmk/lufa/tree/master/Bootloaders/HID/HostLoaderApp), from the LUFA repo. Homebrew may (will) have support for this directly (via `brew install qmk/qmk/hid_bootloader_cli`).
  159. Flashing sequence:
  160. 1. Enter the bootloader using any of the following methods:
  161. * Press the `QK_BOOT` keycode
  162. * Press the `RESET` button on the PCB if available
  163. * short RST to GND quickly
  164. 2. Wait for the OS to detect the device
  165. 3. Flash a .hex file
  166. 4. Reset the device into application mode (may be done automatically)
  167. ### `make` Targets
  168. * `:qmk-hid`: Checks every 5 seconds until a DFU device is available, and then flashes the firmware.
  169. ## STM32/APM32 DFU
  170. All USB-capable STM32 and APM32 MCUs, except for a small handful (such as STM32F103 -- see the [STM32duino section](#stm32duino)) come preloaded with a factory bootloader that cannot be modified nor deleted.
  171. To ensure compatibility with the STM32-DFU bootloader, make sure this block is present in your `rules.mk` (optionally with `apm32-dfu` instead):
  172. ```make
  173. # Bootloader selection
  174. BOOTLOADER = stm32-dfu
  175. ```
  176. Compatible flashers:
  177. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  178. * [dfu-util](https://dfu-util.sourceforge.net/) / `:dfu-util` target in QMK (recommended command line)
  179. ```
  180. dfu-util -a 0 -d 0483:DF11 -s 0x8000000:leave -D <filename>
  181. ```
  182. Flashing sequence:
  183. 1. Enter the bootloader using any of the following methods:
  184. * Tap the `QK_BOOT` keycode (may not work on STM32F042 devices)
  185. * If a reset circuit is present, tap the `RESET` button on the PCB; some boards may also have a toggle switch that must be flipped
  186. * Otherwise, you need to bridge `BOOT0` to VCC (via `BOOT0` button or jumper), short `RESET` to GND (via `RESET` button or jumper), and then let go of the `BOOT0` bridge
  187. 2. Wait for the OS to detect the device
  188. 3. Flash a .bin file
  189. 4. Reset the device into application mode (may be done automatically)
  190. ### `make` Targets
  191. * `:dfu-util`: Waits until an STM32 bootloader device is available, and then flashes the firmware.
  192. * `:dfu-util-split-left` and `:dfu-util-split-right`: Flashes the firmware as with `:dfu-util`, but also sets the handedness setting in EEPROM. This is ideal for Proton-C-based split keyboards.
  193. * `:st-link-cli`: Allows you to flash the firmware via the ST-Link CLI utility, rather than dfu-util. Requires an ST-Link dongle.
  194. * `:st-flash`: Allows you to flash the firmware via the `st-flash` utility from [STLink Tools](https://github.com/stlink-org/stlink), rather than dfu-util. Requires an ST-Link dongle.
  195. ## STM32duino
  196. This bootloader is used almost exclusively for STM32F103 boards, as they do not come with a USB DFU bootloader. The source code and prebuilt binaries can be found [here](https://github.com/rogerclarkmelbourne/STM32duino-bootloader).
  197. To ensure compatibility with the STM32duino bootloader, make sure this block is present in your `rules.mk`:
  198. ```make
  199. # Bootloader selection
  200. BOOTLOADER = stm32duino
  201. ```
  202. Compatible flashers:
  203. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  204. * [dfu-util](https://dfu-util.sourceforge.net/) / `:dfu-util` target in QMK (recommended command line)
  205. ```
  206. dfu-util -a 2 -d 1EAF:0003 -D <filename>
  207. ```
  208. Flashing sequence:
  209. 1. Enter the bootloader using any of the following methods:
  210. * Tap the `QK_BOOT` keycode
  211. * If a reset circuit is present, tap the `RESET` button on the PCB
  212. * Otherwise, you need to bridge `BOOT0` to VCC (via `BOOT0` button or jumper), short `RESET` to GND (via `RESET` button or jumper), and then let go of the `BOOT0` bridge
  213. 2. Wait for the OS to detect the device
  214. 3. Flash a .bin file
  215. 4. Reset the device into application mode (may be done automatically)
  216. ## Kiibohd DFU
  217. Keyboards produced by Input Club use NXP Kinetis microcontrollers rather than STM32, and come with their own [custom bootloader](https://github.com/kiibohd/controller/tree/master/Bootloader), however the process and protocol is largely the same.
  218. The `rules.mk` setting for this bootloader is `kiibohd`, but since this bootloader is limited to Input Club boards, it should not be necessary to set at keymap or user level.
  219. Compatible flashers:
  220. * [QMK Toolbox](https://github.com/qmk/qmk_toolbox/releases) (recommended GUI)
  221. * [dfu-util](https://dfu-util.sourceforge.net/) / `:dfu-util` target in QMK (recommended command line)
  222. ```
  223. dfu-util -a 0 -d 1C11:B007 -D <filename>
  224. ```
  225. Flashing sequence:
  226. 1. Enter the bootloader using any of the following methods:
  227. * Tap the `QK_BOOT` keycode
  228. * Press the `RESET` button on the PCB
  229. 2. Wait for the OS to detect the device
  230. 3. Flash a .bin file
  231. 4. Reset the device into application mode (may be done automatically)
  232. ## WB32 DFU
  233. Some keyboards produced for several commercial brands (GMMK, Akko, MonsGeek, Inland) use this bootloader. The `wb32-dfu-updater` utility is bundled with [QMK MSYS](https://msys.qmk.fm/) and [Glorious's build of QMK Toolbox](https://www.gloriousgaming.com/blogs/guides-resources/gmmk-2-qmk-installation-guide). If neither of these flashing methods is available for your OS, you will likely need to [compile the CLI version from source](https://github.com/WestberryTech/wb32-dfu-updater).
  234. The `info.json` setting for this bootloader is `wb32-dfu`.
  235. Compatible flashers:
  236. * [Glorious's build of QMK Toolbox](https://www.gloriousgaming.com/blogs/guides-resources/gmmk-2-qmk-installation-guide) (recommended GUI)
  237. * [wb32-dfu-updater_cli](https://github.com/WestberryTech/wb32-dfu-updater) / `:flash` target in QMK (recommended command line)
  238. ```
  239. wb32-dfu-updater_cli -t -s 0x8000000 -D <filename>
  240. ```
  241. Flashing sequence:
  242. 1. Enter the bootloader using any of the following methods:
  243. * Tap the `QK_BOOT` keycode
  244. * Press the `RESET` button on the PCB
  245. 2. Wait for the OS to detect the device
  246. 3. Flash a .bin file
  247. 4. Reset the device into application mode (may be done automatically)
  248. ## tinyuf2
  249. Keyboards may opt into supporting the tinyuf2 bootloader. This is currently only supported on F303/F401/F411.
  250. The `rules.mk` setting for this bootloader is `tinyuf2`, and can be specified at the keymap or user level.
  251. To ensure compatibility with the tinyuf2 bootloader, make sure this block is present in your `rules.mk`:
  252. ```make
  253. # Bootloader selection
  254. BOOTLOADER = tinyuf2
  255. ```
  256. Compatible flashers:
  257. * Any application able to copy a file from one place to another, such as _macOS Finder_ or _Windows Explorer_.
  258. Flashing sequence:
  259. 1. Enter the bootloader using any of the following methods:
  260. * Tap the `QK_BOOT` keycode
  261. * Double-tap the `nRST` button on the PCB.
  262. 2. Wait for the OS to detect the device
  263. 3. Copy the .uf2 file to the new USB disk
  264. 4. Wait for the keyboard to become available
  265. or
  266. CLI Flashing sequence:
  267. 1. Enter the bootloader using any of the following methods:
  268. * Tap the `QK_BOOT` keycode
  269. * Double-tap the `nRST` button on the PCB.
  270. 2. Wait for the OS to detect the device
  271. 3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/blackpill_f411_tinyuf2 --keymap default`
  272. 4. Wait for the keyboard to become available
  273. ### `make` Targets
  274. * `:uf2-split-left` and `:uf2-split-right`: Flashes the firmware but also sets the handedness setting in EEPROM by generating a side specific firmware.
  275. ## uf2boot
  276. Keyboards may opt into supporting the uf2boot bootloader. This is currently only supported on F103.
  277. The `rules.mk` setting for this bootloader is `uf2boot`, and can be specified at the keymap or user level.
  278. To ensure compatibility with the uf2boot bootloader, make sure this block is present in your `rules.mk`:
  279. ```make
  280. # Bootloader selection
  281. BOOTLOADER = uf2boot
  282. ```
  283. Compatible flashers:
  284. * Any application able to copy a file from one place to another, such as _macOS Finder_ or _Windows Explorer_.
  285. Flashing sequence:
  286. 1. Enter the bootloader using any of the following methods:
  287. * Tap the `QK_BOOT` keycode
  288. * Double-tap the `nRST` button on the PCB.
  289. 2. Wait for the OS to detect the device
  290. 3. Copy the .uf2 file to the new USB disk
  291. 4. Wait for the keyboard to become available
  292. or
  293. CLI Flashing sequence:
  294. 1. Enter the bootloader using any of the following methods:
  295. * Tap the `QK_BOOT` keycode
  296. * Double-tap the `nRST` button on the PCB.
  297. 2. Wait for the OS to detect the device
  298. 3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/bluepill_uf2boot --keymap default`
  299. 4. Wait for the keyboard to become available
  300. ### `make` Targets
  301. * `:uf2-split-left` and `:uf2-split-right`: Flashes the firmware but also sets the handedness setting in EEPROM by generating a side specific firmware.
  302. ## Raspberry Pi RP2040 UF2
  303. The `rules.mk` setting for this bootloader is `rp2040`, and can be specified at the keymap or user level.
  304. To ensure compatibility with the rp2040 bootloader, make sure this block is present in your `rules.mk`:
  305. ```make
  306. # Bootloader selection
  307. BOOTLOADER = rp2040
  308. ```
  309. Compatible flashers:
  310. * Any application able to copy a file from one place to another, such as _macOS Finder_ or _Windows Explorer_.
  311. Flashing sequence:
  312. 1. Enter the bootloader using any of the following methods:
  313. * Tap the `QK_BOOT` keycode
  314. * Hold the `BOOTSEL` button on the PCB while plugin in the usb cable.
  315. * Double-tap the `RESET` button on the PCB<sup>1</sup>.
  316. 2. Wait for the OS to detect the device
  317. 3. Copy the .uf2 file to the new USB disk
  318. 4. Wait for the keyboard to become available
  319. or
  320. CLI Flashing sequence:
  321. 1. Enter the bootloader using any of the following methods:
  322. * Tap the `QK_BOOT` keycode
  323. * Hold the `BOOTSEL` button on the PCB while plugin in the usb cable.
  324. * Double-tap the `RESET` button on the PCB<sup>1</sup>.
  325. 2. Wait for the OS to detect the device
  326. 3. Flash via QMK CLI eg. `qmk flash --keyboard handwired/onekey/rpi_pico --keymap default`
  327. 4. Wait for the keyboard to become available
  328. <sup>1</sup>: This works only if the controller has been flashed with QMK Firmware with `RP2040_BOOTLOADER_DOUBLE_TAP_RESET` defined.