From e34ca3285259da54b1441d1836662ab57b9a3e22 Mon Sep 17 00:00:00 2001
From: Gregory Nutt <gnutt@nuttx.org>
Date: Thu, 30 Apr 2015 07:28:30 -0600
Subject: [PATCH] Fix some errors in initial re-verification of USB host on the
 STM32F4-Discovery

---
 arch/arm/src/efm32/efm32_usbhost.c   | 109 +++++++++++++--------------
 arch/arm/src/stm32/stm32_otgfshost.c |  45 +++++------
 arch/arm/src/stm32/stm32_otghshost.c |  45 +++++------
 configs/stm32f4discovery/README.txt  |  35 ++++++---
 4 files changed, 114 insertions(+), 120 deletions(-)

diff --git a/arch/arm/src/efm32/efm32_usbhost.c b/arch/arm/src/efm32/efm32_usbhost.c
index 8d60d530fe..edc8babeea 100644
--- a/arch/arm/src/efm32/efm32_usbhost.c
+++ b/arch/arm/src/efm32/efm32_usbhost.c
@@ -350,9 +350,9 @@ static int efm32_in_setup(FAR struct efm32_usbhost_s *priv, int chidx);
 static int efm32_in_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
                              FAR uint8_t *buffer, size_t buflen);
 #ifdef CONFIG_USBHOST_ASYNCH
-static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
-                          FAR struct stm32_chan_s *chan);
-static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+static void efm32_in_next(FAR struct efm32_usbhost_s *priv,
+                          FAR struct efm32_chan_s *chan);
+static int efm32_in_asynch(FAR struct efm32_usbhost_s *priv, int chidx,
                            FAR uint8_t *buffer, size_t buflen,
                            usbhost_asynch_t callback, FAR void *arg);
 #endif
@@ -360,9 +360,9 @@ static int efm32_out_setup(FAR struct efm32_usbhost_s *priv, int chidx);
 static int efm32_out_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
                               FAR uint8_t *buffer, size_t buflen);
 #ifdef CONFIG_USBHOST_ASYNCH
-static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
-                           FAR struct stm32_chan_s *chan);
-static int stm32_out_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+static void efm32_out_next(FAR struct efm32_usbhost_s *priv,
+                           FAR struct efm32_chan_s *chan);
+static int efm32_out_asynch(FAR struct efm32_usbhost_s *priv, int chidx,
                             FAR uint8_t *buffer, size_t buflen,
                             usbhost_asynch_t callback, FAR void *arg);
 #endif
@@ -432,9 +432,6 @@ static int efm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 static int efm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer);
-static int efm32_transfer_common(FAR struct efm32_usbhost_s *priv,
-                                 FAR struct efm32_ed_s *ed,FAR  uint8_t *buffer,
-                                 size_t buflen);
 static int efm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
                           FAR uint8_t *buffer, size_t buflen);
 #ifdef CONFIG_USBHOST_ASYNCH
@@ -1164,11 +1161,11 @@ static void efm32_chan_wakeup(FAR struct efm32_usbhost_s *priv,
 
           if (priv->in)
             {
-              stm32_in_next(priv, chan);
+              efm32_in_next(priv, chan);
             }
           else
             {
-              stm32_out_next(priv, chan);
+              efm32_out_next(priv, chan);
             }
         }
 #endif
@@ -1297,7 +1294,7 @@ static int efm32_ctrlep_alloc(FAR struct efm32_usbhost_s *priv,
   /* Return a pointer to the control pipe container as the pipe "handle" */
 
   *ep = (usbhost_ep_t)ctrlep;
-  ret = OK;
+  return OK;
 }
 
 /************************************************************************************
@@ -1328,7 +1325,6 @@ static int efm32_xfrep_alloc(FAR struct efm32_usbhost_s *priv,
   struct usbhost_hubport_s *hport;
   FAR struct efm32_chan_s *chan;
   int chidx;
-  int ret;
 
   /* Sanity check.  NOTE that this method should only be called if a device is
    * connected (because we need a valid low speed indication).
@@ -1756,7 +1752,6 @@ static int efm32_ctrl_recvdata(FAR struct efm32_usbhost_s *priv,
 static int efm32_in_setup(FAR struct efm32_usbhost_s *priv, int chidx)
 {
   FAR struct efm32_chan_s *chan;
-  int ret = OK;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -1888,7 +1883,7 @@ static int efm32_in_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
 }
 
 /*******************************************************************************
- * Name: stm32_in_next
+ * Name: efm32_in_next
  *
  * Description:
  *   Initiate the next of a sequence of asynchronous transfers.
@@ -1899,8 +1894,8 @@ static int efm32_in_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
  *******************************************************************************/
 
 #ifdef CONFIG_USBHOST_ASYNCH
-static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
-                          FAR struct stm32_chan_s *chan)
+static void efm32_in_next(FAR struct efm32_usbhost_s *priv,
+                          FAR struct efm32_chan_s *chan)
 {
   usbhost_asynch_t callback;
   FAR void *arg;
@@ -1916,13 +1911,13 @@ static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
        * endpoint type
        */
 
-      ret = stm32_in_setup(priv, chidx);
+      ret = efm32_in_setup(priv, chidx);
       if (ret >= 0)
         {
           return;
         }
 
-      udbg("ERROR: stm32_in_setup failed: %d\n", ret);
+      udbg("ERROR: efm32_in_setup failed: %d\n", ret);
       result = ret;
     }
 
@@ -1944,7 +1939,7 @@ static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
 #endif
 
 /*******************************************************************************
- * Name: stm32_in_asynch
+ * Name: efm32_in_asynch
  *
  * Description:
  *   Initiate the first of a sequence of asynchronous transfers.
@@ -1955,11 +1950,11 @@ static void stm32_in_next(FAR struct stm32_usbhost_s *priv,
  *******************************************************************************/
 
 #ifdef CONFIG_USBHOST_ASYNCH
-static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+static int efm32_in_asynch(FAR struct efm32_usbhost_s *priv, int chidx,
                            FAR uint8_t *buffer, size_t buflen,
                            usbhost_asynch_t callback, FAR void *arg)
 {
-  FAR struct stm32_chan_s *chan;
+  FAR struct efm32_chan_s *chan;
   int ret;
 
   /* Set up for the transfer data and callback BEFORE starting the first transfer */
@@ -1968,19 +1963,19 @@ static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
   chan->buffer = buffer;
   chan->buflen = buflen;
 
-  ret = stm32_chan_asynchsetup(priv, chan, callback, arg);
+  ret = efm32_chan_asynchsetup(priv, chan, callback, arg);
   if (ret < 0)
     {
-      udbg("ERROR: stm32_chan_asynchsetup failed: %d\n", ret);
+      udbg("ERROR: efm32_chan_asynchsetup failed: %d\n", ret);
       return ret;
     }
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
-  ret = stm32_in_setup(priv, chidx);
+  ret = efm32_in_setup(priv, chidx);
   if (ret < 0)
     {
-      udbg("ERROR: stm32_in_setup failed: %d\n", ret);
+      udbg("ERROR: efm32_in_setup failed: %d\n", ret);
     }
 
   /* And return with the transfer pending */
@@ -2000,7 +1995,6 @@ static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
 static int efm32_out_setup(FAR struct efm32_usbhost_s *priv, int chidx)
 {
   FAR struct efm32_chan_s *chan;
-  int ret;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -2160,7 +2154,7 @@ static int efm32_out_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
 }
 
 /*******************************************************************************
- * Name: stm32_out_next
+ * Name: efm32_out_next
  *
  * Description:
  *   Initiate the next of a sequence of asynchronous transfers.
@@ -2171,8 +2165,8 @@ static int efm32_out_transfer(FAR struct efm32_usbhost_s *priv, int chidx,
  *******************************************************************************/
 
 #ifdef CONFIG_USBHOST_ASYNCH
-static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
-                           FAR struct stm32_chan_s *chan)
+static void efm32_out_next(FAR struct efm32_usbhost_s *priv,
+                           FAR struct efm32_chan_s *chan)
 {
   usbhost_asynch_t callback;
   FAR void *arg;
@@ -2188,13 +2182,13 @@ static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
        * endpoint type
        */
 
-      ret = stm32_out_setup(priv, chidx);
+      ret = efm32_out_setup(priv, chidx);
       if (ret >= 0)
         {
           return;
         }
 
-      udbg("ERROR: stm32_out_setup failed: %d\n", ret);
+      udbg("ERROR: efm32_out_setup failed: %d\n", ret);
       result = ret;
     }
 
@@ -2216,7 +2210,7 @@ static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
 #endif
 
 /*******************************************************************************
- * Name: stm32_out_asynch
+ * Name: efm32_out_asynch
  *
  * Description:
  *   Initiate the first of a sequence of asynchronous transfers.
@@ -2227,11 +2221,11 @@ static void stm32_out_next(FAR struct stm32_usbhost_s *priv,
  *******************************************************************************/
 
 #ifdef CONFIG_USBHOST_ASYNCH
-static int stm32_out_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
+static int efm32_out_asynch(FAR struct efm32_usbhost_s *priv, int chidx,
                             FAR uint8_t *buffer, size_t buflen,
                             usbhost_asynch_t callback, FAR void *arg)
 {
-  FAR struct stm32_chan_s *chan;
+  FAR struct efm32_chan_s *chan;
   int ret;
 
   /* Set up for the transfer data and callback BEFORE starting the first transfer */
@@ -2240,19 +2234,19 @@ static int stm32_out_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
   chan->buffer = buffer;
   chan->buflen = buflen;
 
-  ret = stm32_chan_asynchsetup(priv, chan, callback, arg);
+  ret = efm32_chan_asynchsetup(priv, chan, callback, arg);
   if (ret < 0)
     {
-      udbg("ERROR: stm32_chan_asynchsetup failed: %d\n", ret);
+      udbg("ERROR: efm32_chan_asynchsetup failed: %d\n", ret);
       return ret;
     }
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
-  ret = stm32_out_setup(priv, chidx);
+  ret = efm32_out_setup(priv, chidx);
   if (ret < 0)
     {
-      udbg("ERROR: stm32_out_setup failed: %d\n", ret);
+      udbg("ERROR: efm32_out_setup failed: %d\n", ret);
     }
 
   /* And return with the transfer pending */
@@ -3774,7 +3768,7 @@ static int efm32_rh_enumerate(FAR struct efm32_usbhost_s *priv,
   regval = efm32_getreg(EFM32_USB_HPRT);
   if ((regval & _USB_HPRT_PRTSPD_MASK) == USB_HPRT_PRTSPD_LS)
     {
-      priv->rhport.hport.speed = USB_SPEED_LOW.
+      priv->rhport.hport.speed = USB_SPEED_LOW;
     }
   else
     {
@@ -3883,7 +3877,7 @@ static int efm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 OUT channel */
 
-  chan            = priv->&riv->chan[ep0info->outndx];
+  chan            = &priv->chan[ep0info->outndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -3892,7 +3886,7 @@ static int efm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 IN channel */
 
-  chan            = priv->&riv->chan[ep0info->inndx];
+  chan            = &priv->chan[ep0info->inndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -3988,7 +3982,6 @@ static int efm32_epalloc(FAR struct usbhost_driver_s *drvr,
 static int efm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
 {
   FAR struct efm32_usbhost_s *priv = (FAR struct efm32_usbhost_s *)drvr;
-  FAR struct efm32_ctrlinfo_s *ctrlep;
 
   DEBUGASSERT(priv);
 
@@ -4010,7 +4003,7 @@ static int efm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
     {
       /* Halt both control channel and mark the channels available */
 
-      FAR struct efm32_ctrlinfo_s *ctrlep = ( FAR struct efm32_ctrlinfo_s *)ep;
+      FAR struct efm32_ctrlinfo_s *ctrlep = (FAR struct efm32_ctrlinfo_s *)ep;
       efm32_chan_free(priv, ctrlep->inndx);
       efm32_chan_free(priv, ctrlep->outndx);
 
@@ -4228,14 +4221,15 @@ static int efm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                         FAR const struct usb_ctrlreq_s *req,
                         FAR uint8_t *buffer)
 {
-  struct efm32_usbhost_s *priv = (struct efm32_usbhost_s *)drvr;
+  FAR struct efm32_usbhost_s *priv = (FAR struct efm32_usbhost_s *)drvr;
+  FAR struct efm32_ctrlinfo_s *ep0info = (FAR struct efm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGFS_VTRACE2_CTRLIN, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4255,7 +4249,7 @@ static int efm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      ret = efm32_ctrl_sendsetup(priv, ep0, req);
+      ret = efm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
        {
           usbhost_trace1(USB_TRACE1_SENDSETUP, -ret);
@@ -4271,7 +4265,7 @@ static int efm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (buflen > 0)
             {
-              ret = efm32_ctrl_recvdata(priv, ep0, buffer, buflen);
+              ret = efm32_ctrl_recvdata(priv, ep0info, buffer, buflen);
               if (ret < 0)
                 {
                   usbhost_trace1(USB_TRACE1_RECVDATA, -ret);
@@ -4282,8 +4276,8 @@ static int efm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              priv->chan[ep0->outndx].outdata1 ^= true;
-              ret = efm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 ^= true;
+              ret = efm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactions exit here */
@@ -4312,14 +4306,15 @@ static int efm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer)
 {
-  struct efm32_usbhost_s *priv = (struct efm32_usbhost_s *)drvr;
+  FAR struct efm32_usbhost_s *priv = (FAR struct efm32_usbhost_s *)drvr;
+  FAR struct efm32_ctrlinfo_s *ep0info = (FAR struct efm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGFS_VTRACE2_CTRLOUT, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4339,9 +4334,7 @@ static int efm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      /* Send the SETUP request */
-
-      ret = efm32_ctrl_sendsetup(priv, ep0, req);
+      ret = efm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
         {
           usbhost_trace1(USB_TRACE1_SENDSETUP, -ret);
@@ -4359,8 +4352,8 @@ static int efm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
             {
               /* Start DATA out transfer (only one DATA packet) */
 
-              priv->chan[ep0->outndx].outdata1 = true;
-              ret = efm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 = true;
+              ret = efm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret < 0)
                 {
                   usbhost_trace1(USB_TRACE1_SENDDATA, -ret);
@@ -4371,7 +4364,7 @@ static int efm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              ret = efm32_ctrl_recvdata(priv, ep0, NULL, 0);
+              ret = efm32_ctrl_recvdata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactins exit here */
diff --git a/arch/arm/src/stm32/stm32_otgfshost.c b/arch/arm/src/stm32/stm32_otgfshost.c
index 8747c01c2f..c5886c3c08 100644
--- a/arch/arm/src/stm32/stm32_otgfshost.c
+++ b/arch/arm/src/stm32/stm32_otgfshost.c
@@ -439,9 +439,6 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer);
-static int stm32_transfer_common(FAR struct stm32_usbhost_s *priv,
-                                 FAR struct stm32_ed_s *ed,FAR  uint8_t *buffer,
-                                 size_t buflen);
 static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
                           FAR uint8_t *buffer, size_t buflen);
 #ifdef CONFIG_USBHOST_ASYNCH
@@ -1302,7 +1299,7 @@ static int stm32_ctrlep_alloc(FAR struct stm32_usbhost_s *priv,
   /* Return a pointer to the control pipe container as the pipe "handle" */
 
   *ep = (usbhost_ep_t)ctrlep;
-  ret = OK;
+  return OK;
 }
 
 /************************************************************************************
@@ -1333,7 +1330,6 @@ static int stm32_xfrep_alloc(FAR struct stm32_usbhost_s *priv,
   struct usbhost_hubport_s *hport;
   FAR struct stm32_chan_s *chan;
   int chidx;
-  int ret;
 
   /* Sanity check.  NOTE that this method should only be called if a device is
    * connected (because we need a valid low speed indication).
@@ -1761,7 +1757,6 @@ static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv,
 static int stm32_in_setup(FAR struct stm32_usbhost_s *priv, int chidx)
 {
   FAR struct stm32_chan_s *chan;
-  int ret = OK;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -2005,7 +2000,6 @@ static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
 static int stm32_out_setup(FAR struct stm32_usbhost_s *priv, int chidx)
 {
   FAR struct stm32_chan_s *chan;
-  int ret;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -3826,7 +3820,7 @@ static int stm32_rh_enumerate(FAR struct stm32_usbhost_s *priv,
   regval = stm32_getreg(STM32_OTGFS_HPRT);
   if ((regval & OTGFS_HPRT_PSPD_MASK) == OTGFS_HPRT_PSPD_LS)
     {
-      priv->rhport.hport.speed = USB_SPEED_LOW.
+      priv->rhport.hport.speed = USB_SPEED_LOW;
     }
   else
     {
@@ -3935,7 +3929,7 @@ static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 OUT channel */
 
-  chan            = priv->&riv->chan[ep0info->outndx];
+  chan            = &priv->chan[ep0info->outndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -3944,7 +3938,7 @@ static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 IN channel */
 
-  chan            = priv->&riv->chan[ep0info->inndx];
+  chan            = &priv->chan[ep0info->inndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -4036,7 +4030,6 @@ static int stm32_epalloc(FAR struct usbhost_driver_s *drvr,
 static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
 {
   FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
-  FAR struct stm32_ctrlinfo_s *ctrlep;
 
   DEBUGASSERT(priv);
 
@@ -4058,7 +4051,7 @@ static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
     {
       /* Halt both control channel and mark the channels available */
 
-      FAR struct stm32_ctrlinfo_s *ctrlep = ( FAR struct stm32_ctrlinfo_s *)ep;
+      FAR struct stm32_ctrlinfo_s *ctrlep = (FAR struct stm32_ctrlinfo_s *)ep;
       stm32_chan_free(priv, ctrlep->inndx);
       stm32_chan_free(priv, ctrlep->outndx);
 
@@ -4276,14 +4269,15 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                         FAR const struct usb_ctrlreq_s *req,
                         FAR uint8_t *buffer)
 {
-  struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGFS_VTRACE2_CTRLIN, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4303,7 +4297,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      ret = stm32_ctrl_sendsetup(priv, ep0, req);
+      ret = stm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
        {
           usbhost_trace1(OTGFS_TRACE1_SENDSETUP, -ret);
@@ -4319,7 +4313,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (buflen > 0)
             {
-              ret = stm32_ctrl_recvdata(priv, ep0, buffer, buflen);
+              ret = stm32_ctrl_recvdata(priv, ep0info, buffer, buflen);
               if (ret < 0)
                 {
                   usbhost_trace1(OTGFS_TRACE1_RECVDATA, -ret);
@@ -4330,8 +4324,8 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              priv->chan[ep0->outndx].outdata1 ^= true;
-              ret = stm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 ^= true;
+              ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactions exit here */
@@ -4360,14 +4354,15 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer)
 {
-  struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGFS_VTRACE2_CTRLOUT, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4387,9 +4382,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      /* Send the SETUP request */
-
-      ret = stm32_ctrl_sendsetup(priv, ep0, req);
+      ret = stm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
         {
           usbhost_trace1(OTGFS_TRACE1_SENDSETUP, -ret);
@@ -4407,8 +4400,8 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
             {
               /* Start DATA out transfer (only one DATA packet) */
 
-              priv->chan[ep0->outndx].outdata1 = true;
-              ret = stm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 = true;
+              ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret < 0)
                 {
                   usbhost_trace1(OTGFS_TRACE1_SENDDATA, -ret);
@@ -4419,7 +4412,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              ret = stm32_ctrl_recvdata(priv, ep0, NULL, 0);
+              ret = stm32_ctrl_recvdata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactins exit here */
diff --git a/arch/arm/src/stm32/stm32_otghshost.c b/arch/arm/src/stm32/stm32_otghshost.c
index 145daf2de6..431781cd34 100644
--- a/arch/arm/src/stm32/stm32_otghshost.c
+++ b/arch/arm/src/stm32/stm32_otghshost.c
@@ -439,9 +439,6 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer);
-static int stm32_transfer_common(FAR struct stm32_usbhost_s *priv,
-                                 FAR struct stm32_ed_s *ed,FAR  uint8_t *buffer,
-                                 size_t buflen);
 static int stm32_transfer(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep,
                           FAR uint8_t *buffer, size_t buflen);
 #ifdef CONFIG_USBHOST_ASYNCH
@@ -1302,7 +1299,7 @@ static int stm32_ctrlep_alloc(FAR struct stm32_usbhost_s *priv,
   /* Return a pointer to the control pipe container as the pipe "handle" */
 
   *ep = (usbhost_ep_t)ctrlep;
-  ret = OK;
+  return OK;
 }
 
 /************************************************************************************
@@ -1333,7 +1330,6 @@ static int stm32_xfrep_alloc(FAR struct stm32_usbhost_s *priv,
   struct usbhost_hubport_s *hport;
   FAR struct stm32_chan_s *chan;
   int chidx;
-  int ret;
 
   /* Sanity check.  NOTE that this method should only be called if a device is
    * connected (because we need a valid low speed indication).
@@ -1761,7 +1757,6 @@ static int stm32_ctrl_recvdata(FAR struct stm32_usbhost_s *priv,
 static int stm32_in_setup(FAR struct stm32_usbhost_s *priv, int chidx)
 {
   FAR struct stm32_chan_s *chan;
-  int ret = OK;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -2005,7 +2000,6 @@ static int stm32_in_asynch(FAR struct stm32_usbhost_s *priv, int chidx,
 static int stm32_out_setup(FAR struct stm32_usbhost_s *priv, int chidx)
 {
   FAR struct stm32_chan_s *chan;
-  int ret;
 
   /* Set up for the transfer based on the direction and the endpoint type */
 
@@ -3826,7 +3820,7 @@ static int stm32_rh_enumerate(FAR struct stm32_usbhost_s *priv,
   regval = stm32_getreg(STM32_OTGHS_HPRT);
   if ((regval & OTGHS_HPRT_PSPD_MASK) == OTGHS_HPRT_PSPD_LS)
     {
-      priv->rhport.hport.speed = USB_SPEED_LOW.
+      priv->rhport.hport.speed = USB_SPEED_LOW;
     }
   else
     {
@@ -3935,7 +3929,7 @@ static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 OUT channel */
 
-  chan            = priv->&riv->chan[ep0info->outndx];
+  chan            = &priv->chan[ep0info->outndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -3944,7 +3938,7 @@ static int stm32_ep0configure(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep
 
   /* Configure the EP0 IN channel */
 
-  chan            = priv->&riv->chan[ep0info->inndx];
+  chan            = &priv->chan[ep0info->inndx];
   chan->funcaddr  = funcaddr;
   chan->speed     = speed;
   chan->maxpacket = maxpacketsize;
@@ -4036,7 +4030,6 @@ static int stm32_epalloc(FAR struct usbhost_driver_s *drvr,
 static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
 {
   FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
-  FAR struct stm32_ctrlinfo_s *ctrlep;
 
   DEBUGASSERT(priv);
 
@@ -4058,7 +4051,7 @@ static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
     {
       /* Halt both control channel and mark the channels available */
 
-      FAR struct stm32_ctrlinfo_s *ctrlep = ( FAR struct stm32_ctrlinfo_s *)ep;
+      FAR struct stm32_ctrlinfo_s *ctrlep = (FAR struct stm32_ctrlinfo_s *)ep;
       stm32_chan_free(priv, ctrlep->inndx);
       stm32_chan_free(priv, ctrlep->outndx);
 
@@ -4276,14 +4269,15 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                         FAR const struct usb_ctrlreq_s *req,
                         FAR uint8_t *buffer)
 {
-  struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGHS_VTRACE2_CTRLIN, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4303,7 +4297,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      ret = stm32_ctrl_sendsetup(priv, ep0, req);
+      ret = stm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
        {
           usbhost_trace1(OTGHS_TRACE1_SENDSETUP, -ret);
@@ -4319,7 +4313,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (buflen > 0)
             {
-              ret = stm32_ctrl_recvdata(priv, ep0, buffer, buflen);
+              ret = stm32_ctrl_recvdata(priv, ep0info, buffer, buflen);
               if (ret < 0)
                 {
                   usbhost_trace1(OTGHS_TRACE1_RECVDATA, -ret);
@@ -4330,8 +4324,8 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              priv->chan[ep0->outndx].outdata1 ^= true;
-              ret = stm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 ^= true;
+              ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactions exit here */
@@ -4360,14 +4354,15 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
                          FAR const struct usb_ctrlreq_s *req,
                          FAR const uint8_t *buffer)
 {
-  struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_usbhost_s *priv = (FAR struct stm32_usbhost_s *)drvr;
+  FAR struct stm32_ctrlinfo_s *ep0info = (FAR struct stm32_ctrlinfo_s *)ep0;
   uint16_t buflen;
   uint32_t start;
   uint32_t elapsed;
   int retries;
   int ret;
 
-  DEBUGASSERT(drvr && req);
+  DEBUGASSERT(priv != NULL && ep0info != NULL && req != NULL);
   usbhost_vtrace2(OTGHS_VTRACE2_CTRLOUT, req->type, req->req);
   uvdbg("type:%02x req:%02x value:%02x%02x index:%02x%02x len:%02x%02x\n",
         req->type, req->req, req->value[1], req->value[0],
@@ -4387,9 +4382,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
     {
       /* Send the SETUP request */
 
-      /* Send the SETUP request */
-
-      ret = stm32_ctrl_sendsetup(priv, ep0, req);
+      ret = stm32_ctrl_sendsetup(priv, ep0info, req);
       if (ret < 0)
         {
           usbhost_trace1(OTGHS_TRACE1_SENDSETUP, -ret);
@@ -4407,8 +4400,8 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
             {
               /* Start DATA out transfer (only one DATA packet) */
 
-              priv->chan[ep0->outndx].outdata1 = true;
-              ret = stm32_ctrl_senddata(priv, ep0, NULL, 0);
+              priv->chan[ep0info->outndx].outdata1 = true;
+              ret = stm32_ctrl_senddata(priv, ep0info, NULL, 0);
               if (ret < 0)
                 {
                   usbhost_trace1(OTGHS_TRACE1_SENDDATA, -ret);
@@ -4419,7 +4412,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
 
           if (ret == OK)
             {
-              ret = stm32_ctrl_recvdata(priv, ep0, NULL, 0);
+              ret = stm32_ctrl_recvdata(priv, ep0info, NULL, 0);
               if (ret == OK)
                 {
                   /* All success transactins exit here */
diff --git a/configs/stm32f4discovery/README.txt b/configs/stm32f4discovery/README.txt
index c591b500cb..67dce3c7d3 100644
--- a/configs/stm32f4discovery/README.txt
+++ b/configs/stm32f4discovery/README.txt
@@ -1603,16 +1603,31 @@ Where <subdir> is one of the following:
        a USB host on the STM32F4Discovery, including support for a mass storage
        class driver:
 
-       CONFIG_USBDEV=n          : Make sure tht USB device support is disabled
-       CONFIG_USBHOST=y         : Enable USB host support
-       CONFIG_USBHOST_MSC=y     : Enable the mass storage class
-       CONFIG_STM32_OTGFS=y     : Enable the STM32 USB OTG FS block
-       CONFIG_STM32_SYSCFG=y    : Needed for all USB OTF FS support
-       CONFIG_SCHED_WORKQUEUE=y : High priority worker thread support is required
-       CONFIG_SCHED_HPWORK=y    :   for the mass storage class driver.
-       CONFIG_NSH_ARCHINIT=y    : Architecture specific USB initialization
-                                  is needed for NSH
-       CONFIG_FS_FAT=y          : Needed by the USB host mass storage class.
+       Device Drivers ->
+         CONFIG_USBDEV=n          : Make sure tht USB device support is disabled
+         CONFIG_USBHOST=y         : Enable USB host support
+         CONFIG_USBHOST_ISOC_DISABLE=y
+
+       Device Drivers -> USB Host Driver Support
+         CONFIG_USBHOST_MSC=y     : Enable the mass storage class
+
+       System Type -> STM32 Peripheral Support
+         CONFIG_STM32_OTGFS=y     : Enable the STM32 USB OTG FS block
+         CONFIG_STM32_SYSCFG=y    : Needed for all USB OTF FS support
+
+       RTOS Features -> Work Queue Support
+         CONFIG_SCHED_WORKQUEUE=y : High priority worker thread support is required
+         CONFIG_SCHED_HPWORK=y    :   for the mass storage class driver.
+
+       File Systems ->
+         CONFIG_FS_FAT=y          : Needed by the USB host mass storage class.
+
+       Board Selection ->
+         CONFIG_LIB_BOARDCTL=y    : Needed for CONFIG_NSH_ARCHINIT
+
+       Application Configuration -> NSH Library
+         CONFIG_NSH_ARCHINIT=y    : Architecture specific USB initialization
+                                  : is needed for NSH
 
        With those changes, you can use NSH with a FLASH pen driver as shown
        belong.  Here NSH is started with nothing in the USB host slot: