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.
This commit is contained in:
Karl Palsson 2015-09-19 21:41:41 +00:00
parent 53c1d2c8d9
commit f49cbee683
2 changed files with 15 additions and 0 deletions

View File

@ -124,6 +124,7 @@
#define OTG_GRSTCTL_AHBIDL (1 << 31)
/* Bits 30:11 - Reserved */
#define OTG_GRSTCTL_TXFNUM_MASK (0x1f << 6)
#define OTG_GRSTCTL_TXFNUM_ALL (0x10 << 6)
#define OTG_GRSTCTL_TXFFLSH (1 << 5)
#define OTG_GRSTCTL_RXFFLSH (1 << 4)
/* Bit 3 - Reserved */

View File

@ -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)