Bootloader Brings USB, Firmware Updating To The ATtiny85

[Jenna] sent in a very cool bootloader she thought people might like. It’s called Micronucleus and it turns the lowly ATtiny 85 into a chip with a USB interface capable of being upgraded via a ‘viral’ uploader program. Micronucleus weighs in at just over 2 kB, making it one of the smallest USB-compatible bootloaders currently available.

The USB support comes from V-USB, a project that puts a virtual USB port on a suite of AVR microcontrollers. With V-USB, it’s easy to turn a Tiny85 into a keyboard, custom joystick, data logger, or computer-attached LED display.

One very interesting feature of Micronucleus is the ‘viral updater’ feature. This feature takes a new piece of firmware, and writes it to a Tiny85, disabling the current bootloader. If you’re designing a project that should have a means of updating the firmware via USB instead of the usual AVR programmer, this might be the bootloader for you.

Not bad for a bootloader that emphasizes small code size. At just over 2 kB, it’s possible to use this bootloader on the similar, smaller, and somewhat cheaper ATtiny45.

14 thoughts on “Bootloader Brings USB, Firmware Updating To The ATtiny85

  1. I recently built/etched a ATtiny85 board based on the USB-Password generator schematic. Perhaps I’ll give this a spin on it.
    My purpose is to be really annoying (turning on shift randomly) but I havent gotten around to writing any of the code yet. It’ll be dead simple so Im not entirely sure why I’ve been so lethargic about doing it.

  2. I suspect that the recently featured DigiSpark (ATtiny85) makes use of this boot loader. I’m left to wonder which ‘viral’ uploader this requires? I like the idea of the uploader being built into the Arduino IDE, but I like the idea of it being a stand-alone tool even better.

  3. I wanted to use USBasploader because you can use avrdude (which means just a Makefile edit for me), but there’s issues with that on the ’85 with Embedded Creations’ version and avrdude, so I think Jenna’s project is the way to go right now, as long as I can build the command line tool for OSX.

  4. It’s never been tested on an ATtiny45, and would need a little bit of rejiggering to work there, but it’d probably be as simple as changing the chip type and BOOTLOADER_ADDRESS in the make file.

  5. As far as I can tell, uisp-bootloader doesn’t work on tiny85 – a chip which has no hardware bootloader support. micronucleus uses embedded-creations’ USBaspLoader-tiny85’s neat interrupt vector table hacks to work around lacking hardware support. It’s inspired by but doesn’t really inherit code from bootloadHID, and isn’t hid based (if the OS polled it as a HID device it could crash the usb connection)

    The DigiSpark is indeed supposed to be using a version of this bootloader – designs you make today with micronucleus should be compatible with DigiSpark’s arduino stuff. Digistump had their own internal bootloaders but were having some trouble with them and asked me to try to complete this project early.

    The commandline upload program works on Mac, Windows, and Linux – just install libusb-compat through mac homebrew then make; make install. If someone wants to add a homebrew recipe for it that would be neat. I haven’t done so as homebrew frowns on software developers creating recipes for their own apps.

    The viral uploader is included in the repo’s /upgrade/ folder – it generates a firmware you can upload to attiny85 chips (via whichever bootloader they have already), then the firmware rewrites it’s own interrupt vector table disabling the existing bootloader so if it looses power half way through it’ll run the upgrade program again, then erases and writes over the existing bootloader with a new version embedded in the upgrade program’s progmem, then once that’s done it once again rewrites it’s vector table to map across all vectors to the new bootloader, so the next time it powers on it’ll run the new bootloader which can take care of adjusting anything and erasing the upgrade program. I call it viral because of the way it hijacks the environment of the chip and unpacks itself over the ‘system’. It was very much inspired by attending a security course at uni. It should work for other bootloaders too – you could convert something from micronucleus to a much smaller UART bootloader, or to USBaspLoader-tiny85 (not sure why you’d want to though) – all you need is a hex file for your bootloader of choice to build another upgrade firmware. The only limitation is the bootloader must exist at the end of progmem – but I think they all do otherwise supporting absolute jumps would be nightmarish.

    USBaspLoader-tiny85 is pretty much obsoleted by micronucleus, unless someone can figure out a way to make it not require the avrdude patch. That seems quite unlikely, so for now both bootloaders require their own special app for uploading. micronucleus has the advantage of being smaller, and launching the user program faster by not requiring the user to manually run avrdude and plug in the device at the same time. micronucleus’ command line app polls the computer’s usb devices to grab the bootloader as soon as it’s enumerated.

  6. Oh and the digistump guys are making a proxy script which pretends to be avrdude and either runs avrdude or micronucleus commandline app. Not sure when they’ll publish that.

  7. “The USB support comes from V-USB, a project that puts a virtual USB port on a suite of AVR microcontrollers.”

    Actually, it puts a *real* USB port on these microcontrollers. It connects to physical USB ports, shows up as normal physical devices, communicates data, and can be endlessly configured on the AVR side.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.