Paul told me it was difficult, but not impossible, to make an AVR USB bootloader that fits in
512 256 words of Flash (coincidentally, the size of the smallest configurable boot block on most of the USB-enabled AVR chips). So of course I had to try. But along the way, I needed an AVR serial programmer (to burn the boot block) but I didn't have one. However, I did have the broken Teensy Paul gave me (which had a few spare GPIOs after the Avago Yow! project) and Ward has been showing off his Txtzyme interpreter, so...
Add a little Perl, and viola:
a Teensy running Txtzyme that can flash an AT90USB1287 on my Atmel ATUSBKey dev board! Once I get my own USB bootloader running, I'll be able to go the other direction: load Txtzyme on the ATUSBKey and use it to flash my bootloader back onto the Teensy.
BTW, Ward, I had to increase the size of the line buffer in Txtzyme to 1K (plus a few other changes to make that work). Each Serial Programmer command takes about 600 bytes of Txtzyme code to send/receive, and I wanted to do it at a steady pace, rather than mixing the SPI wiggling with USB I/O.
Comments
It's difficult, but not
It's difficult, but not impossible, to fit into 256 words (512 bytes). I know it's possible because I did it....
Whoops! (What's a power of
Whoops! (What's a power of two among friends?)
Of course I meant 256 words (512 bytes). Although the smallest configurable boot block size on the AT90USB64 and AT90USB128 is 512 words (1024 bytes). The smallest size is 256 on the ATMegaXXU2 and -U4.
So anyway, I have my code crunched down sub-256 words, and I can read Flash and chip info over USB. It'll take a little doing to get reading AND writing, but now that I have a serial programmer, I'm almost out of excuses for not finishing it!
Txtzyme Packet Size
Awesome work.
I chose 64 bytes for the buffer because it was a good match with the USB packet size. Your idea of getting the USB io out of the way makes sense too.
I hope you found the interpreter easy to modify. That was the original intent.
Not out of excuses yet...
Almost, but not quite out of excuses. I wasted some time learning how to use Qt, then put together this:
It takes a couple of seconds to load 128K of Flash, but displays pretty smoothly. I still have to figure out how to feed the data to objdump to construct a disassembly. Plus figure out how to support multiple processors easily. But it's a start, anyway.
(No doubt I'm reproducing some well-known program that I ought to just download and figure out how to use. Whatever...this project is actually supposed to teach me how USB works, but it's learnin' me some contemporary GUI know-how, too.)
Posted code at AVRFreaks
I posted a recent screenshot and the bootloader & GUI code at AVRFreaks:
http://www.avrfreaks.net/index.php?module=Freaks%20Academy&func=viewItem&item_id=2739&item_type=project
...in case anybody wants to look at it.