Static Advancement

MyUSB Library, Projects Add comments

*** It’s very late and I’m dead tired, so please excuse the following rambling mess in advance. ***

I do like a set of small, well defined specifications. A huge spec such as SCSI, USB, etc is damn hard to read and understand all at once, and can leave you feeling overwhelmed and confused — especially on what parts exactly you need to implement. The USB DFU Class and Atmel’s DFU Bootloader Datasheet are both small, concise and actually fun to implement.

After a bit of head scratching and investigation, I’ve found a bug in the current avr-lib-c library, in the watchdog reset routine wdt_reset() of <avr/wdt.h>. The problem is that it fails silently on the AT90USB1287, because of the choice of instructions. The AVR architecture gives three ways to access the contents of registers — short IO space, longer extended IO space, and slow RAM-mapped access. The wdt_disable() routine uses the assembly instructions IN and OUT (for extended IO mapped space) to access one of the watchdog configuration registers which, due to the number of features in the AT90USB1287 requiring registers (and thus addresses), resides in the memory mapped space only.

My fix is currently a small custom routine to disable the watchdog in the bootloader only. All the other demos use the avr-lib-c routine, which should be patched soon by one of the developers. The DFU bootloader can jump to the application space using both the watchdog and an actual jump, so adding the custom routine to all the demos isn’t needed.

I’ve also enhanced the USB portion of the MyUSB library a bit, by adding the ability to statically specify USB options (normally passed in dynamically by the Options parameter of the USB_Init() routine) via the makefile. This results in a decent flash space savings, with the downside that the options cannot be altered while the program is running - a feature not needed on most apps. The USB_Init() routine’s parameters now also alter depending on the compile time options — specifying USB_DEVICE_ONLY or USB_HOST_ONLY removes the “Mode” parameter, and specifying the new USE_STATIC_OPTIONS parameter removes the “Options” parameter.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in