Date:2011-05-10 02:13:41 (8 years 5 months ago)
Author:Werner Almesberger
Commit:eeb3af6a03adb83ae4b1200b1a9da8580277eb6d
Message: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
Files: atusb/fw/Makefile (2 diffs)
atusb/fw/usb/atu2.c (3 diffs)

Change Details

atusb/fw/Makefile
5858
5959# ----- Rules -----------------------------------------------------------------
6060
61.PHONY: all clean upload prog version.c
61.PHONY: all clean upload prog dfu version.c
6262.PHONY: prog-app prog-read on off reset
6363
6464all: $(NAME).bin boot.hex
...... 
143143        ssh $(HOST) avrdude -F -p $(CHIP) -c nanonote_atusb \
144144          -U flash:r:mcu.bin:r
145145
146dfu: $(NAME).bin
147        dfu-util -d 20b7:1540 -D $(NAME).bin
148
146149on:
147150        ssh $(HOST) poke 0x10010318 4
148151
atusb/fw/usb/atu2.c
167167}
168168
169169
170static void ep_init(void)
171{
172    UENUM = 0;
173    UECONX = (1 << RSTDT) | (1 << EPEN); /* enable */
174    UECFG0X = 0; /* control, direction is ignored */
175    UECFG1X = 3 << EPSIZE0; /* 64 bytes */
176    UECFG1X |= 1 << ALLOC;
177
178    while (!(UESTA0X & (1 << CFGOK)));
179
180    eps[0].state = EP_IDLE;
181    eps[0].size = 64;
182}
183
184
170185void usb_poll(void)
171186{
172187    uint8_t flags, i;
173188
174189    flags = UDINT;
175    if (flags & EORSTI) {
176        UDINT &= ~(1 << EORSTI);
190    if (flags & (1 << EORSTI)) {
177191        if (user_reset)
178192            user_reset();
193        ep_init();
194        UDINT &= ~(1 << EORSTI);
179195    }
180196    flags = UEINT;
181197    for (i = 0; i != NUM_EPS; i++)
...... 
185201}
186202
187203
188static void ep_init(void)
189{
190    UENUM = 0;
191    UECONX = (1 << RSTDT) | (1 << EPEN); /* enable */
192    UECFG0X = 0; /* control, direction is ignored */
193    UECFG1X = 3 << EPSIZE0; /* 64 bytes */
194    UECFG1X |= 1 << ALLOC;
195
196    while (!(UESTA0X & (1 << CFGOK)));
197
198    eps[0].state = EP_IDLE;
199    eps[0].size = 64;
200}
201
202
203204void usb_reset(void)
204205{
205206    UDCON |= 1 << DETACH; /* detach the pull-up */
...... 
222223    USBCON &= ~(1 << FRZCLK); /* thaw the clock */
223224
224225    UDCON &= ~(1 << DETACH); /* attach the pull-up */
225    UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */
226// UDCON |= 1 << RSTCPU; /* reset CPU on bus reset */
226227
227228    ep_init();
228229}

Archive Download the corresponding diff file



interactive