diff options
author | Karl Palsson <karlp@tweak.net.au> | 2015-09-20 00:41:41 +0300 |
---|---|---|
committer | Karl Palsson <karlp@tweak.net.au> | 2015-09-23 01:28:02 +0300 |
commit | f49cbee6834031dc2e5406d6735ecc178e1c265d (patch) | |
tree | 5831ca7b9eb3d752fc4864425b990c688daa88fd /lib/usb | |
parent | 53c1d2c8d92e055f02b56e589e9f098a42a1e76c (diff) |
usb: otg-dev: disable and flush endpoints on reset
Only resetting the fifo memory pointers can result in corrupt data.
Tested on f4 disco board with the gadget0 test suite.
Diffstat (limited to 'lib/usb')
-rw-r--r-- | lib/usb/usb_fx07_common.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/usb/usb_fx07_common.c b/lib/usb/usb_fx07_common.c index a3be368d..ffb46f11 100644 --- a/lib/usb/usb_fx07_common.c +++ b/lib/usb/usb_fx07_common.c @@ -117,8 +117,22 @@ void stm32fx07_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type, void stm32fx07_endpoints_reset(usbd_device *usbd_dev) { + int i; /* The core resets the endpoints automatically on reset. */ usbd_dev->fifo_mem_top = usbd_dev->fifo_mem_top_ep0; + + /* Disable any currently active endpoints */ + for (i = 1; i < 4; i++) { + if (REBASE(OTG_DOEPCTL(i)) & OTG_DOEPCTL0_EPENA) { + REBASE(OTG_DOEPCTL(i)) |= OTG_DOEPCTL0_EPDIS; + } + if (REBASE(OTG_DIEPCTL(i)) & OTG_DIEPCTL0_EPENA) { + REBASE(OTG_DIEPCTL(i)) |= OTG_DIEPCTL0_EPDIS; + } + } + + /* Flush all tx/rx fifos */ + REBASE(OTG_GRSTCTL) = OTG_GRSTCTL_TXFFLSH | OTG_GRSTCTL_TXFNUM_ALL | OTG_GRSTCTL_RXFFLSH; } void stm32fx07_ep_stall_set(usbd_device *usbd_dev, uint8_t addr, uint8_t stall) |