Flashing flashlight firmware with a Raspberry Pi

Everybody everywhere says to use a USBASP to flash your LED drivers, but if you’re someone like me who happens to already own any Raspberry Pi and are too stubborn to even want to touch a USBASP, you already have the flashing tool and a computer ready-to-setup for modding firmware. You just some wires, the right chip clip, a bit of software setup, and some patience. The rest of this post will be a rough guide on using a Raspberry Pi you already own to mod your firmware.

Please don’t buy a Raspberry Pi just to use as a flasher, get a USBASP instead if that’s all you want. But, if you happen to already own several Pis, or if you simply want a cheap device to learn Linux on, or if you want to do some other bizarre project like making a dedicated Bob Ross Joy of Painting HDMI dongle (probably the greatest thing I’ve ever done), then consider this yet another potential use of it.

Hardware you’ll need:

  • Raspberry Pi. Any of their numbered models will work pretty much the exact same. I used a Pi Zero W. Similar minicomputers from different brands should work as long as they have hardware SPI support, but the setup process will be different, and you’re on your own there.
  • MicroSD Card.
  • SOIC-8 clip. I use a Ponoma 5250.
  • Female-Female jumper wires. Or you could solder wires directly to the pi and clip, but I don’t recommend this for many reasons.
  • Power adapter for the pi
  • A flashlight driver to flash firmware onto

Instructions

  • If you have not already set up your pi with Raspberry Pi OS to the point you have terminal access, stop, find a guide to get that far, and come back.
  • Enable SPI
    • sudo raspi-config
      • Select the options: 3 Interface Options -> P4 SPI -> Yes Enable -> Finish. Reboot if prompted to.
  • Install the needed packages
    • sudo apt install build-essential wiringpi bzr gcc-avr avr-libc binutils-avr avrdude
  • Setup Aliases so you don’t have to remember a thousand parameters every time.
    • alias flcc=‘avr-gcc -Os -mmcu=attiny13’ #change attiny13 to the chip your light’s driver is using. All of mine are attiny13-based so far.
    • alias flprep=‘sudo gpio -g mode 24 out;sudo gpio -g write 24 0’ # We’re using Pin 24 for something coming up.
    • alias fldude=‘avrdude -c linuxspi -P /dev/spidev0.0 -b 1000 -p t13’ # you may need to change the baudrate (-b) or AVR partno (-p) appropriately.
    • alias > ~/.bash_aliases # save these aliases
  • Wire Up
    • Clip the SOIC clip to the flashlight driver’s attiny, making note of the notched or marked corner.
    • Open the following references in new tabs.
    • Using these pictures, Connect the following
      • Rpi GPIO 24 (18) to Attiny Reset
      • Rpi SPI0 MOSI to Attiny MOSI
      • Rpi SPI0 MISO to Attiny MISO
      • Rpi SPI0 SCLK to Attiny SCK
      • Rpi Ground (Any) to Attiny GND
      • Rpi 3v3 (Any) to Attiny VCC
  • Test the connection by entering the following two commands into the terminal
    • flprep # Only need to do this once every boot
    • fldude # As long as it reports a serial and doesn’t return error, you’re good. If you do get errors, check connections and reclip.
  • Get some firmware! I recommend just cloning ToyKeeper’s Flashlight Firmware Repository. I did my flashing with STAR_noinit.
    • bzr branch lp:flashlight-firmware
  • cd to the directory containing your firmware
  • Compile the firmware if necessary
    • Example: flcc whatever.c -o whatever.hex #Change whatever.c to the source file name
  • Flash Time
    • If the firmware folder contains a flashing script, you’ll need to edit it. Replace avrdude with fldude, and remove any parameters previously set in the fldude alias.
      • Example: ./flash-script.sh
    • If no script, try the following
      • Example: fldude -U flash:w:whatever.hex
  • Test Time
    • If avrdude reports successfully validated, reassemble your light and give it a test. Should work exactly as the firmware is supposed to.

Troubleshooting

  • This section to be filled in if anyone else tries this and has issues.

Potential improvements to the guide

  • Experiment with different avrdude baudrates to find out which ones work best. When I was doing this in a rush last night before I lost power from a freak storm, I just typed in 1000 and it worked, when before I simply left the parameter empty it kept failing validation.
  • Add pictures if I can come up with any that help

As an aside, the entire process of building my first light out of an old LuxPro 600, discovering the driver I bought had terribad PWM whine, desoldering the wires, replacing them with longer ones and routing them to not obstruct the attiny’s pins when I flip the driver out of the pill, flashing the firmware, realizing I had a solder bridge on the wrong star and deciding to mod the firmware to ignore that star and pretend I soldered the star that needs to be soldered rather than resoldering, making these long run on sentences, and coming back the next day to collect my thoughts into this post has been one of the most fun things I’ve done since we all got locked inside our homes. I’m sure I’ll come up with some other idea to try soon enough, but frankly I’ve put way too much effort into this first post as it is. I hope this rambling mess actually helps someone.

It's nice of you to join us, Crossover Cable!

(And thanks for the guide.)