aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2020-03-01 22:29:26 -0800
committerGitHub <noreply@github.com>2020-03-01 22:29:26 -0800
commitabd36de5adbb484695d3500ad790df557d4f5419 (patch)
tree32aa2ab30410a0160d131e8a629e75c7095fad63
parentb72a1aa3fec986bfa7e439b68d6b7546ab1e280b (diff)
downloadqmk_firmware-abd36de5adbb484695d3500ad790df557d4f5419.tar.gz
qmk_firmware-abd36de5adbb484695d3500ad790df557d4f5419.zip
[Docs] Update ISP Flashing guide (#8149)
* [Docs] Update ISP Flashing guide * Apply suggestions from code review AKA why you shouldn't write docs at 2am Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update workding for planck-qmk-dfu Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com>
-rw-r--r--docs/isp_flashing_guide.md153
1 files changed, 133 insertions, 20 deletions
diff --git a/docs/isp_flashing_guide.md b/docs/isp_flashing_guide.md
index 0f786c514..944dd3462 100644
--- a/docs/isp_flashing_guide.md
+++ b/docs/isp_flashing_guide.md
@@ -1,6 +1,14 @@
1# ISP Flashing Guide 1# ISP Flashing Guide
2 2
3If you're having trouble flashing/erasing your board, and running into cryptic error messages like any of the following: 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.
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).
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.
8
9## Dealing with Corrupted Bootloaders
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:
4 12
5 libusb: warning [darwin_transfer_status] transfer error: timed out 13 libusb: warning [darwin_transfer_status] transfer error: timed out
6 dfu.c:844: -ETIMEDOUT: Transfer timed out, NAK 0xffffffc4 (-60) 14 dfu.c:844: -ETIMEDOUT: Transfer timed out, NAK 0xffffffc4 (-60)
@@ -19,16 +27,60 @@ If you're having trouble flashing/erasing your board, and running into cryptic e
19 Memory write error, use debug for more info. 27 Memory write error, use debug for more info.
20 commands.c:360: Error writing memory data. (err -4) 28 commands.c:360: Error writing memory data. (err -4)
21 29
22You're likely going to need to ISP flash your board/device to get it working again. Luckily, this process is pretty straight-forward, provided you have any extra programmable keyboard, Pro Micro, or Teensy 2.0/Teensy 2.0++. There are also dedicated ISP flashers available for this, but most cost >$15, and it's assumed that if you are googling this error, this is the first you've heard about ISP flashing, and don't have one readily available (whereas you might have some other AVR board). __We'll be using a Teensy 2.0 or Pro Micro with Windows 10 in this guide__ - if you are comfortable doing this on another system, please consider editing this guide and contributing those instructions! 30Or, if you see this sort of message for a Pro Micro based controller:
31
32 avrdude: butterfly_recv(): programmer is not responding
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
39
40You're likely going to need to ISP flash your board/device to get it working again.
41
42## Hardware Needed
43
44You'll need one of the following to actually perform the ISP flashing (followed by the protocol they use):
45
46* [SparkFun PocketAVR](https://www.sparkfun.com/products/9825) - (USB Tiny)
47* [USBtinyISP AVR Programmer Kit](https://www.adafruit.com/product/46) - (USB Tiny)
48* [Teensy 2.0](https://www.pjrc.com/store/teensy.html) - (avrisp)
49* [Pro Micro](https://www.sparkfun.com/products/12640) - (avrisp)
50* [Bus Pirate](https://www.adafruit.com/product/237) - (buspirate)
51
52There 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.
53
54You'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.
55
56### The ISP Firmware
57
58The 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.
59
60* 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`)
61* 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`)
62
63Once you've flashed your controller, you won't need this hex file anymore.
23 64
24## Software Needed 65## Software Needed
25 66
26* [Teensy Loader](https://www.pjrc.com/teensy/loader.html) (if using a Teensy) 67The QMK Toolbox can be used for most (all) of this.
27* QMK Toolbox (flash as usual - be sure to select the correct MCU) or `avrdude` via [WinAVR](http://www.ladyada.net/learn/avr/setup-win.html) (for Teensy & Pro Micro) 68
69However, 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.
70
28 71
29## Wiring 72## Wiring
30 73
31This is pretty straight-forward - we'll be connecting like-things to like-things in the following manner: 74This is pretty straight-forward - we'll be connecting like-things to like-things in the following manner.
75
76### SparkFun Pocket AVR
77
78 PocketAVR RST <-> Keyboard RESET
79 PocketAVR SCLK <-> Keyboard B1 (SCLK)
80 PocketAVR MOSI <-> Keyboard B2 (MOSI)
81 PocketAVR MISO <-> Keyboard B3 (MISO)
82 PocketAVR VCC <-> Keyboard VCC
83 PocketAVR GND <-> Keyboard GND
32 84
33### Teensy 2.0 85### Teensy 2.0
34 86
@@ -39,6 +91,8 @@ This is pretty straight-forward - we'll be connecting like-things to like-things
39 Teensy VCC <-> Keyboard VCC 91 Teensy VCC <-> Keyboard VCC
40 Teensy GND <-> Keyboard GND 92 Teensy GND <-> Keyboard GND
41 93
94!> 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.
95
42### Pro Micro 96### Pro Micro
43 97
44 Pro Micro 10 (B6) <-> Keyboard RESET 98 Pro Micro 10 (B6) <-> Keyboard RESET
@@ -48,45 +102,61 @@ This is pretty straight-forward - we'll be connecting like-things to like-things
48 Pro Micro VCC <-> Keyboard VCC 102 Pro Micro VCC <-> Keyboard VCC
49 Pro Micro GND <-> Keyboard GND 103 Pro Micro GND <-> Keyboard GND
50 104
51## The ISP Firmware (now pre-compiled) 105!> 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.
52 106
53The only difference between the .hex files below is which pin is connected to RESET. You can use them on other boards as well, as long as you're aware of the pins being used. If for some reason neither of these pins are available, [create an issue](https://github.com/qmk/qmk_firmware/issues/new), and we can generate one for you!
54 107
55* 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`) 108## Flashing Your Keyboard
56* Pro Micro: [`util/pro_micro_ISP_B6_10.hex`](https://github.com/qmk/qmk_firmware/blob/master/util/pro_micro_ISP_B6_10.hex) (`B6/10`) 109
110After you have your ISP programmer set up, and wired to your keyboard, it's time to flash your keyboard.
57 111
58**Flash your Teenys/Pro Micro with one of these and continue - you won't need the file after flashing your ISP device.** 112### The Bootloader File
59 113
60## Just the Bootloader File 114The 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.
61 115
62If you just want to get things back to normal, you can flash only a bootloader from [`util/` folder](https://github.com/qmk/qmk_firmware/tree/master/util), and use your normal process to flash the firmware afterwards. Be sure to flash the correct bootloader for your chip: 116You 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:
63 117
64* [`atmega32u4`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32u4_1_0_0.hex) - Most keyboards, Planck Rev 1-5, Preonic Rev 1-2 118* [`atmega32u4`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32u4_1_0_0.hex) - Most keyboards, Planck Rev 1-5, Preonic Rev 1-2
119* [`Pro Micro`](https://github.com/sparkfun/Arduino_Boards/blob/master/sparkfun/avr/bootloaders/caterina/Caterina-promicro16.hex) - The default bootloader for Pro Micro controllers
65* [`at90usb1286`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb128x_1_0_1.hex) - Planck Light Rev 1 120* [`at90usb1286`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_at90usb128x_1_0_1.hex) - Planck Light Rev 1
66* [`atmega32a`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32a_1_0_0.hex) - jj40 121* [`atmega32a`](https://github.com/qmk/qmk_firmware/blob/master/util/bootloader_atmega32a_1_0_0.hex) - jj40, and other V-USB/ps2avrGB keyboards
67 122
68If you're not sure what your board uses, look in the `rules.mk` file for the keyboard in QMK. The `MCU =` line will have the value you need. It may differ between different versions of the board. 123If you're not sure what your board uses, look in the `rules.mk` file for the keyboard in QMK. The `MCU =` line will have the value you need. It may differ between different versions of the board.
69 124
70### Advanced/Production Techniques 125### Production Techniques
71 126
72If you'd like to flash both the bootloader **and** the regular firmware at the same time, you need to combine the files. 127If 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.
128
129To do this manually:
73 130
741. Open the original firmware .hex file in a text editor 1311. Open the original firmware .hex file in a text editor
752. Remove the last line (which should be `:00000001FF` - this is an EOF message) 1322. Remove the last line (which should be `:00000001FF` - this is an EOF message)
763. 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 1333. 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
774. Save it as a new file by naming it `<keyboard>_<keymap>_production.hex` 1344. Save it as a new file by naming it `<keyboard>_<keymap>_production.hex`
78 135
79It'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. 136?> 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.
137
138To do this the easy way, you can flash the board using the `:production` target when compiling. This compiles the firmware, then compiles the QMK DFU bootloader, and then creates a combined image. Once this is done, you'll see three files:
139* `<keyboard>_<keymap>.hex`
140* `<keyboard>_<keymap>_bootloader.hex`
141* `<keyboard>_<keymap>_production.hex`
142
143The 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`.
144
145You 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.
146
147?> 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.
80 148
81## Flashing Your Bootloader/Production File 149## Flashing Your Bootloader/Production File
82 150
83Make sure your keyboard is unplugged from any device, and plug in your Teensy. 151Make sure your keyboard is unplugged from any device, and plug in your ISP Programmer.
152
153If you want to change bootloader types, You'll need to use the command line.
84 154
85### QMK Toolbox 155### QMK Toolbox
86 156
871. `AVRISP device connected` will show up in yellow 1571. `AVRISP device connected` or `USB Tiny device connected` will show up in yellow
882. Select the correct bootloader/production .hex file with the `Open` dialog (spaces can't be in the path) 1582. Select the correct bootloader/production .hex file with the `Open` dialog (spaces can't be in the path)
893. Be sure the correct `Microcontroller` option is selected 1593. Be sure the correct `Microcontroller` option for the keyboard you're flashing (not the ISP programmer) is selected
904. Hit `Flash` 1604. Hit `Flash`
915. Wait, as nothing will output for a while, especially with production files 1615. Wait, as nothing will output for a while, especially with production files
92 162
@@ -94,7 +164,7 @@ If the verification and fuse checks are ok, you're done! Your board may restart
94 164
95### Command Line 165### Command Line
96 166
97Open `cmd` 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: 167Open 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:
98 168
99 avrdude -c avrisp -P COM3 -p atmega32u4 169 avrdude -c avrisp -P COM3 -p atmega32u4
100 170
@@ -129,4 +199,47 @@ You should see a couple of progress bars, then you should see:
129 199
130Which 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. 200Which 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.
131 201
202If you're using a SparkFun PocketAVR Programmer, or another USB Tiny based ISP programmer, you will want to use something like this:
203
204 avrdude -c usbtiny -P usb -p atmega32u4
205
206#### Advanced: Changing Fuses
207
208If 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.
209
210!> 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.
211
212For this, we are assuming the 5V 16MHz versions of the `atmega32u4` (such as the 5V Pro Micro).
213
214For DFU on the `atmega32u4`, these are the fuse settings that you want:
215
216| Fuse | Setting |
217|----------|------------------|
218| Low | `0x5E` |
219| High | `0xD9` or `0x99` |
220| Extended | `0xC3` |
221
222The 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.
223
224To 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:
225
226 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
227
228For Caterina on the `atmega32u4`, these are the fuse settings that you want:
229
230| Fuse | Setting|
231|----------|--------|
232| Low | `0xFF` |
233| High | `0xD9` |
234| Extended | `0xC3` |
235
236To set this add `-U lfuse:w:0xFF:m -U hfuse:w:0xD8:m -U efuse:w:0xC3:m` to your command. So the final command should look something like:
237
238 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:0xC3:m
239
240
241If you are using a different controller or want different configuration, you can use [this AVR Fuse Calculator](http://www.engbedded.com/fusecalc/) to find a better value for you.
242
243## Help
244
132If you have any questions/problems, feel free to [open an issue](https://github.com/qmk/qmk_firmware/issues/new)! 245If you have any questions/problems, feel free to [open an issue](https://github.com/qmk/qmk_firmware/issues/new)!