From eeb3af6a03adb83ae4b1200b1a9da8580277eb6d Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 9 May 2011 21:13:41 -0300 Subject: [PATCH] atusb/fw: fixed USB bus reset handling by software - usb/atu2.c (ep_init): moved before usb_poll - usb/atu2.c (usb_poll): register bit was used as mask, not as shift - usb/atu2.c (usb_poll): call ep_init on USB bus reset - usb/atu2.c (usb_reset): don't make USB bus reset force a hardware reset - Makefile (.PHONY, dfu): new target to upload the application with DFU --- atusb/fw/Makefile | 5 ++++- atusb/fw/usb/atu2.c | 39 ++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/atusb/fw/Makefile b/atusb/fw/Makefile index 1e2ddf9..96cb1d6 100644 --- a/atusb/fw/Makefile +++ b/atusb/fw/Makefile @@ -58,7 +58,7 @@ endif # ----- Rules ----------------------------------------------------------------- -.PHONY: all clean upload prog version.c +.PHONY: all clean upload prog dfu version.c .PHONY: prog-app prog-read on off reset all: $(NAME).bin boot.hex @@ -143,6 +143,9 @@ prog-read: ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \ -U flash:r:mcu.bin:r +dfu: $(NAME).bin + dfu-util -d 20b7:1540 -D $(NAME).bin + on: ssh $(HOST) poke 0x10010318 4 diff --git a/atusb/fw/usb/atu2.c b/atusb/fw/usb/atu2.c index 917b680..6ab9146 100644 --- a/atusb/fw/usb/atu2.c +++ b/atusb/fw/usb/atu2.c @@ -167,24 +167,6 @@ stall: } -void usb_poll(void) -{ - uint8_t flags, i; - - flags = UDINT; - if (flags & EORSTI) { - UDINT &= ~(1 << EORSTI); - if (user_reset) - user_reset(); - } - flags = UEINT; - for (i = 0; i != NUM_EPS; i++) - if (1 || flags & (1 << i)) - handle_ep(i); - /* @@@ USB bus reset */ -} - - static void ep_init(void) { UENUM = 0; @@ -200,6 +182,25 @@ static void ep_init(void) } +void usb_poll(void) +{ + uint8_t flags, i; + + flags = UDINT; + if (flags & (1 << EORSTI)) { + if (user_reset) + user_reset(); + ep_init(); + UDINT &= ~(1 << EORSTI); + } + flags = UEINT; + for (i = 0; i != NUM_EPS; i++) + if (1 || flags & (1 << i)) + handle_ep(i); + /* @@@ USB bus reset */ +} + + void usb_reset(void) { UDCON |= 1 << DETACH; /* detach the pull-up */ @@ -222,7 +223,7 @@ void usb_init(void) USBCON &= ~(1 << FRZCLK); /* thaw the clock */ UDCON &= ~(1 << DETACH); /* attach the pull-up */ - UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */ +// UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */ ep_init(); }