My Not-so-Secret Project
Quick bit of related news: it seems the University of Queensland’s approved my LUFA library for student use!
This last week I’ve been working on a little LUFA side project, for inclusion into the next release. Actually, it’s something I previously thought impossible with the USB AVRs, but after (quite) a bit of experimentation it turns out the little USB AVRs are more useful than I previously thought.
Things all began while I was chatting on Freenode IRC in #avr, #bumbleb and #dorkbotpdx (fun fact, I’m usually there under the guise of abcminiuser, come and say hi!) last week and wondered if it was worth trying to make an AVRISP-MKII with the USB AVRs. Don Delmar “you’re only here because we like your library” Davis was rather taken by this idea – after all, it would mean “real” $20 ISP programmers with infinite customisation and AVRStudio integration, and so at his encouragement I started work.
Now, to be fair, this isn’t a new idea — I was asked if the same thing was possible by another user whose name I can’t seem to dig up last year and I replied in the negative. Times have changed and my knowledge of what the chips can do has improved; since then I’ve discovered that the larger USB AVRs can support bidirectional endpoints while in host mode by freezing, changing the token and unfreezing a pipe. That made me wonder if the same was possible in device mode with the USB endpoints.
Turns out, yes, it’s possible, and there’s a new Endpoint macro to do just that in the latest SVN revisions. The trick is to set the endpoint as OUT until data is needed to be sent to the host – if so, change the direction, write your data, send it, wait for the IN bank to be ready again and switch back to the OUT direction. This means the communication is half-duplex, but it also means that for low-bandwidth applications one of the precious few endpoints can be saved for other uses. Since the largest USB AVRs have only a single bank capable of 256 byte packets, this means very fast half-duplex transfers in either direction.
This is monumental — it means that all sorts of neat applications can be made, starting with the AVRISP-MKII clone using the Atmel USB AVRs. And that’s what I’ve been doing – writing my own firmware from scratch. You can try it out in the latest SVN revisions under Projects/Incomplete/AVRISP, which is almost complete; everything except FLASH and EEPROM writing now works. I realise the latter is a rather big drawback for a programmer device, but I’m getting there and I’m happy with the week’s work. By next week, everything should be in place for a cheap knock-off of the official AVR-ISP using anything from a lowly AT90USB82 all the way up to a big AT90USB1287.
I’ve got big plans for this project once I’ve got the initial version (and all the other LUFA features that have been queuing up for the next release) complete – such as a one-touch mode to toggle between AVRISP programmer and CDC class USART/I2C/SPI debugger. Stay tuned.