If you're having trouble flashing/erasing your board, and running into cryptic error messages like any of the following:
libusb: warning [darwin_transfer_status] transfer error: timed out dfu.c:844: -ETIMEDOUT: Transfer timed out, NAK 0xffffffc4 (-60) atmel.c:1627: atmel_flash: flash data dfu_download failed. atmel.c:1629: Expected message length of 1072, got -60. atmel.c:1434: Error flashing the block: err -2. ERROR Memory write error, use debug for more info. commands.c:360: Error writing memory data. (err -4) dfu.c:844: -EPIPE: a) Babble detect or b) Endpoint stalled 0xffffffe0 (-32) Device is write protected. dfu.c:252: dfu_clear_status( 0x7fff4fc2ea80 ) atmel.c:1434: Error flashing the block: err -2. ERROR Memory write error, use debug for more info. commands.c:360: Error writing memory data. (err -4)
You'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!
avrdudevia WinAVR (for Teensy & Pro Micro)
This is pretty straight-forward - we'll be connecting like-things to like-things in the following manner:
Teensy B0 <-> Keyboard RESET Teensy B1 <-> Keyboard B1 (SCLK) Teensy B2 <-> Keyboard B2 (MOSI) Teensy B3 <-> Keyboard B3 (MISO) Teensy VCC <-> Keyboard VCC Teensy GND <-> Keyboard GND
Pro Micro 10 (B6) <-> Keyboard RESET Pro Micro 15 (B1) <-> Keyboard B1 (SCLK) Pro Micro 16 (B2) <-> Keyboard B2 (MOSI) Pro Micro 14 (B3) <-> Keyboard B3 (MISO) Pro Micro VCC <-> Keyboard VCC Pro Micro GND <-> Keyboard GND
The 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, and we can generate one for you!
Flash your Teenys/Pro Micro with one of these and continue - you won't need the file after flashing your ISP device.
If you just want to get things back to normal, you can flash only a bootloader from
util/ folder, and use your normal process to flash the firmware afterwards. Be sure to flash the correct bootloader for your chip:
atmega32u4- Most keyboards, Planck Rev 1-5, Preonic Rev 1-2
at90usb1286- Planck Light Rev 1
If 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.
If you'd like to flash both the bootloader and the regular firmware at the same time, you need to combine the files.
:00000001FF- this is an EOF message)
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.
Make sure your keyboard is unplugged from any device, and plug in your Teensy.
AVRISP device connectedwill show up in yellow
Opendialog (spaces can't be in the path)
Microcontrolleroption is selected
If 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.
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:
avrdude -c avrisp -P COM3 -p atmega32u4
and you should get something like the following output:
avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.02s avrdude: Device signature = 0x1e9587 avrdude: safemode: Fuses OK avrdude done. Thank you.
Since our keyboard uses an
atmega32u4 (common), that is the chip we'll specify. This is the full command:
avrdude -c avrisp -P COM3 -p atmega32u4 -U flash:w:main.hex:i
If your board uses an
atmega32a (e.g. on a jj40), the command is this (the extra code at the end sets the fuses correctly):
avrdude -c avrisp -P COM3 -p atmega32 -U flash:w:main.hex:i -U hfuse:w:0xD0:m -U lfuse:w:0x0F:m
You should see a couple of progress bars, then you should see:
avrdude: verifying ... avrdude: 32768 bytes of flash verified avrdude: safemode: Fuses OK avrdude done. Thank you.
Which 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.
If you have any questions/problems, feel free to open an issue!