From 3604c9bff925d1f87bec66a23fc713071fcebd02 Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 28 Aug 2012 22:28:49 +0000 Subject: Slightly improved delay logic for the USB host git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5064 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/arch/arm/src/stm32/stm32_otgfshost.c | 48 +++++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'nuttx/arch/arm/src/stm32/stm32_otgfshost.c') diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c index d888c52f1..684904925 100644 --- a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c +++ b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c @@ -1474,7 +1474,7 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, FAR uint8_t *buffer, size_t buflen) { FAR struct stm32_chan_s *chan; - int ret; + int ret = OK; /* Loop until the transfer completes (i.e., buflen is decremented to zero) * or a fatal error occurs (any error other than a simple NAK) @@ -1484,6 +1484,17 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, chan->buffer = buffer; chan->buflen = buflen; + /* There is a bug in the code at present. With debug OFF, this driver + * overruns the typical FLASH device and there are many problems with + * NAKS. Sticking a big delay here allows the device (FLASH drive) to + * catch up but sacrifices driver performance. + */ + +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_USB) +#warning "REVISIT this delay" + usleep(50*1000); +#endif + while (chan->buflen > 0) { /* Set up for the wait BEFORE starting the transfer */ @@ -1537,17 +1548,6 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, } } - /* There is a bug in the code at present. With debug OFF, this driver - * overruns the typical FLASH device and there are many problems with - * NAKS sticking a big delay here allows the driver to work but with - * very poor performance when debug is off. - */ - -#if !defined(CONFIG_DEBUG_VERBOSE) && !defined(CONFIG_DEBUG_USB) -#warning "REVISIT this delay" - usleep(100*1000); -#endif - /* Start the transfer */ stm32_transfer_start(priv, chidx); @@ -1557,18 +1557,30 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx, ret = stm32_chan_wait(priv, chan); /* EAGAIN indicates that the device NAKed the transfer and we need - * do try again. Anything else (success or other errors) will - * cause use to return + * do try again. NAK retries are not yet supported for OUT transfers + * so any unsuccessful response will cause us to abort the OUT + * transfer. */ if (ret != OK) { udbg("Transfer failed: %d\n", ret); - return ret; + break; } } - return OK; + /* There is a bug in the code at present. With debug OFF, this driver + * overruns the typical FLASH device and there are many problems with + * NAKS. Sticking a big delay here allows the device (FLASH drive) to + * catch up but sacrifices driver performance. + */ + +#if !defined(CONFIG_DEBUG_VERBOSE) || !defined(CONFIG_DEBUG_USB) +#warning "REVISIT this delay" + usleep(50*1000); +#endif + + return ret; } /******************************************************************************* @@ -3086,9 +3098,9 @@ static int stm32_enumerate(FAR struct usbhost_driver_s *drvr) priv->chan[chidx].indata1 = false; priv->chan[chidx].outdata1 = false; - /* USB 2.0 spec says at least 50ms delay before port reset */ + /* USB 2.0 spec says at least 50ms delay before port reset. We wait 100ms. */ - up_mdelay(100); + usleep(100*1000); /* Reset the host port */ -- cgit v1.2.3