Skip to content

Appendix E: Flashing a Bootloader

ploopyco edited this page Nov 22, 2021 · 5 revisions

Introduction

You only need to flash a bootloader if you're building a Ploopy Nano Trackball from scratch, or if your bootloader has become corrupted in some way.

This guide will cover a method for flashing a bootloader onto the Ploopy Nano Trackball. Note, however, that there are alternative methods available; this simply covers one such method.

Before you begin

Programming a bootloader is much different than programming QMK or any other firmware. To do so, we need to use a special connector on the Ploopy PCB called the ICSP header. Your PCB will probably just have six holes in the PCB, with no plastic connector prongs jutting out of the board. That's perfectly usable, and you won't need to add a connector in order to proceed.

You'll need a programmer. A "programmer" can be many different things. We use an Arduino Nano and six pieces of jumper wire (copper wire, nothing fancy) to program bootloaders, but many different kinds of programmers can be used. See this list for more examples.

The remainder of this guide will assume that you're using an Arduino Nano to reprogram your Ploopy device. If you're using another programmer, you may need to make adjustments to these steps.

Get the necessary tools

  • The Arduino IDE
  • An Arduino Nano (I get them on Amazon)
  • A USB mini-B to USB A cable (something like this)
  • Hookup wire (something like this; any breadboard jumper wire or 24AWG hookup wire will do fine)
  • A 10uF capacitor (something like this)

Get a copy of the bootloader file

You can find a copy of the necessary bootloader here. Download and save it. For the purposes of this guide, it will be assumed that you saved the file as bootloader_atmega32u4_1.0.0.hex.

Install avrdude

avrdude is the software that we'll use to flash the bootloader. It runs on Windows, Mac, and Linux, so you should be good to go.

Verify that it's installed by opening up a terminal window (cmd on Windows machines). Typing in avrdude should show that it's installed.

Program the programmer, if necessary

If you've got an Arduino Nano, you'll need to program the Arduino Nano with the ArduinoISP sketch so that it can program the Ploopy PCB.

You'll only need to do this step once. If your Arduino Nano is already programmed to be an ArduinoISP, skip this step.

  1. Plug your Arduino Nano into your computer (via its USB mini-B port).
    • The Arduino Nano should have a few status LEDs that illuminate when it's powered on.
    • You don't need the Ploopy PCBs for this step. You can put them aside for now.
  2. Fire up the Arduino IDE (install it if you don't already have it installed).
  3. Open up the ArduinoISP sketch in Arduino IDE (in File -> Examples -> 11.ArduinoISP -> ArduinoISP).
  4. Upload the ArduinoISP sketch onto the Arduino Nano.
    • Make sure that, in the Arduino IDE, Tools > Board is set to Arduino Nano and Tools > Programmer is set to AVRISP mk II.

If the Arduino IDE reports that you successfully flashed the firmware onto the Arduino Nano, then you're done.

Connect the programmer to the Ploopy PCB

The Ploopy PCB ICSP header consists of six holes (or six pins, if you've added a connector). The pins are numbered like this:

 1 -> ■  o <- 2
 3 -> o  o <- 4
 5 -> o  o <- 6

Note that pin 1 is a square pad on the board. Also, this is the way the header looks when viewed from the top of the board (i.e. when the microcontroller is visible). Here's a picture of what it looks like.

Hook up the ICSP connector on the Ploopy PCB to the programmer. If you're using an Arduino Nano, make the following connections:

ICSP Pin 1 -> Arduino Pin D12   (MISO)
ICSP Pin 2 -> Arduino 5V        (V_USB)
ICSP Pin 3 -> Arduino Pin D13   (SCLK)
ICSP Pin 4 -> Arduino Pin D11   (MOSI)
ICSP Pin 5 -> Arduino Pin D10   (RST/CS)
ICSP Pin 6 -> Arduion GND       (GND)

If your board doesn't have a header soldered to it (i.e. there are holes that go straight through the board instead of pins that jut out of the board), you'll need to ensure good physical contact between the wire and the pin holes in order for the programming step to work.

Take a 10uF capacitor and hook it up to the Arduino Nano, between the RST and GND pin.

Flash the bootloader

Once the programmer is connected to your computer and the Ploopy PCB is connected to the programmer, it's time to flash the bootloader.

Open up a terminal, and navigate to the location where your bootloader hex file is located. Use the following command to flash the bootloader onto the device via avrdude:

avrdude -p m32u4 -c avrisp -b 19200 -U flash:w:bootloader_atmega32u4_1.0.0.hex -U lfuse:w:0x5e:m -U hfuse:w:0x99:m -U efuse:w:0xc3:m -P /dev/ttyUSB3

/dev/ttyUSB3 is just a placeholder. You'll need to verify which USB port your programmer is connected to.

If programming with Windows, you'll replace /dev/ttyUSB3 with something like COM3.

It's done!

Once successfully flashed, the only thing running on the ATmega32u4 is the bootloader code. Effectively, it's in bootloader mode.

You can now use the regular technique of flashing new QMK firmware onto the Ploopy PCB. You can check that out at Appendix D: QMK Firmware Programming.

If something is clear, check out the QMK ISP programming guide.