Several more bug fixes for STM32 OTG FS host driver

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5044 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2012-08-21 20:14:42 +00:00
parent 42d23b06d9
commit 451e17f183
8 changed files with 56 additions and 27 deletions

View File

@ -1,9 +1,9 @@
/******************************************************************************* /*******************************************************************************
* arch/arm/src/lpc17xx/lpc17_usbhost.c * arch/arm/src/lpc17xx/lpc17_usbhost.c
* *
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
* Authors: Rafael Noronha <rafael@pdsolucoes.com.br> * Authors: Rafael Noronha <rafael@pdsolucoes.com.br>
* Gregory Nutt <spudmonkey@racsa.co.cr> * Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -1898,7 +1898,7 @@ static int lpc17_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface was optimized under a particular assumption. It was assumed * This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor * that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -1952,7 +1952,7 @@ static int lpc17_alloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to free that * be accessed more efficiently. This method provides a mechanism to free that
* request/descriptor memory. If the underlying hardware does not support * request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to free(). * such "special" memory, this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
@ -1988,7 +1988,7 @@ static int lpc17_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
* Some hardware supports special memory in which larger IO buffers can * Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized. * This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
* *
@ -2036,7 +2036,7 @@ static int lpc17_ioalloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which IO data can be accessed more * Some hardware supports special memory in which IO data can be accessed more
* efficiently. This method provides a mechanism to free that IO buffer * efficiently. This method provides a mechanism to free that IO buffer
* memory. If the underlying hardware does not support such "special" memory, * memory. If the underlying hardware does not support such "special" memory,
* this functions may simply map to free(). * this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to

View File

@ -49,6 +49,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/kmalloc.h>
#include <nuttx/usb/usb.h> #include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h> #include <nuttx/usb/usbhost.h>
@ -89,6 +90,8 @@
* want to do that? * want to do that?
* CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access * CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
* debug. Depends on CONFIG_DEBUG. * debug. Depends on CONFIG_DEBUG.
* CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
* packets. Depends on CONFIG_DEBUG.
*/ */
/* Pre-requistites (partial) */ /* Pre-requistites (partial) */
@ -119,6 +122,7 @@
#ifndef CONFIG_DEBUG #ifndef CONFIG_DEBUG
# undef CONFIG_STM32_USBHOST_REGDEBUG # undef CONFIG_STM32_USBHOST_REGDEBUG
# undef CONFIG_STM32_USBHOST_PKTDUMP
#endif #endif
/* HCD Setup *******************************************************************/ /* HCD Setup *******************************************************************/
@ -253,6 +257,12 @@ static void stm32_putreg(uint32_t addr, uint32_t value);
static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits, static inline void stm32_modifyreg(uint32_t addr, uint32_t clrbits,
uint32_t setbits); uint32_t setbits);
#ifdef CONFIG_STM32_USBHOST_PKTDUMP
# define stm32_pktdump(m,b,n) lib_dumpbuffer(m,b,n)
#else
# define stm32_pktdump(m,b,n)
#endif
/* Semaphores ******************************************************************/ /* Semaphores ******************************************************************/
static void stm32_takesem(sem_t *sem); static void stm32_takesem(sem_t *sem);
@ -1298,6 +1308,8 @@ static void stm32_gint_wrpacket(FAR struct stm32_usbhost_s *priv,
uint32_t fifo; uint32_t fifo;
int buflen32; int buflen32;
stm32_pktdump("Sending", buffer, buflen);
/* Get the number of 32-byte words associated with this byte size */ /* Get the number of 32-byte words associated with this byte size */
buflen32 = (buflen + 3) >> 2; buflen32 = (buflen + 3) >> 2;
@ -1958,6 +1970,8 @@ static inline void stm32_gint_rxflvlisr(FAR struct stm32_usbhost_s *priv)
*dest++ = stm32_getreg(fifo); *dest++ = stm32_getreg(fifo);
} }
stm32_pktdump("Received", priv->chan[chidx].buffer, bcnt);
/* Manage multiple packet transfers */ /* Manage multiple packet transfers */
priv->chan[chidx].buffer += bcnt; priv->chan[chidx].buffer += bcnt;
@ -2924,7 +2938,7 @@ static int stm32_epfree(FAR struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface was optimized under a particular assumption. It was assumed * This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor * that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -2958,12 +2972,15 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
/* There is no special memory requirement */ /* There is no special memory requirement */
alloc = (FAR uint8_t *)malloc(*maxlen); alloc = (FAR uint8_t *)kmalloc(*maxlen);
if (!alloc) if (!alloc)
{ {
return -ENOMEM; return -ENOMEM;
} }
/* Return the allocated buffer */
*buffer = alloc;
return OK; return OK;
} }
@ -2974,7 +2991,7 @@ static int stm32_alloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to free that * be accessed more efficiently. This method provides a mechanism to free that
* request/descriptor memory. If the underlying hardware does not support * request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to free(). * such "special" memory, this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
@ -2995,7 +3012,7 @@ static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
/* There is no special memory requirement */ /* There is no special memory requirement */
DEBUGASSERT(drvr && buffer); DEBUGASSERT(drvr && buffer);
free(buffer); kfree(buffer);
return OK; return OK;
} }
@ -3006,7 +3023,7 @@ static int stm32_free(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
* Some hardware supports special memory in which larger IO buffers can * Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized. * This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
* *
@ -3035,12 +3052,15 @@ static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
/* There is no special memory requirement */ /* There is no special memory requirement */
alloc = (FAR uint8_t *)malloc(buflen); alloc = (FAR uint8_t *)kmalloc(buflen);
if (!alloc) if (!alloc)
{ {
return -ENOMEM; return -ENOMEM;
} }
/* Return the allocated buffer */
*buffer = alloc;
return OK; return OK;
} }
@ -3051,7 +3071,7 @@ static int stm32_ioalloc(FAR struct usbhost_driver_s *drvr,
* Some hardware supports special memory in which IO data can be accessed more * Some hardware supports special memory in which IO data can be accessed more
* efficiently. This method provides a mechanism to free that IO buffer * efficiently. This method provides a mechanism to free that IO buffer
* memory. If the underlying hardware does not support such "special" memory, * memory. If the underlying hardware does not support such "special" memory,
* this functions may simply map to free(). * this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
@ -3072,7 +3092,7 @@ static int stm32_iofree(FAR struct usbhost_driver_s *drvr, FAR uint8_t *buffer)
/* There is no special memory requirement */ /* There is no special memory requirement */
DEBUGASSERT(drvr && buffer); DEBUGASSERT(drvr && buffer);
free(buffer); kfree(buffer);
return OK; return OK;
} }
@ -3161,7 +3181,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
/* Handle the status OUT phase */ /* Handle the status OUT phase */
priv->chan[priv->ep0out].outdata1 ^= true; priv->chan[priv->ep0out].outdata1 ^= true;
ret = stm32_ctrl_senddata(priv, buffer, buflen); ret = stm32_ctrl_senddata(priv, NULL, 0);
if (ret == OK) if (ret == OK)
{ {
break; break;

View File

@ -689,6 +689,8 @@ STM3220G-EVAL-specific Configuration Options
want to do that? want to do that?
CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
debug. Depends on CONFIG_DEBUG. debug. Depends on CONFIG_DEBUG.
CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
packets. Depends on CONFIG_DEBUG.
Configurations Configurations
============== ==============

View File

@ -1047,6 +1047,8 @@ CONFIG_USBDEV_TRACE_NRECORDS=128
# want to do that? # want to do that?
# CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access # CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
# debug. Depends on CONFIG_DEBUG. # debug. Depends on CONFIG_DEBUG.
# CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
# packets. Depends on CONFIG_DEBUG.
# #
CONFIG_USBHOST=n CONFIG_USBHOST=n
# ONFIG_STM32_OTGFS_RXFIFO_SIZE # ONFIG_STM32_OTGFS_RXFIFO_SIZE
@ -1054,6 +1056,7 @@ CONFIG_USBHOST=n
#CONFIG_STM32_OTGFS_PTXFIFO_SIZE #CONFIG_STM32_OTGFS_PTXFIFO_SIZE
CONFIG_STM32_OTGFS_SOFINTR=n CONFIG_STM32_OTGFS_SOFINTR=n
CONFIG_STM32_USBHOST_REGDEBUG=n CONFIG_STM32_USBHOST_REGDEBUG=n
CONFIG_STM32_USBHOST_PKTDUMP=n
# #
# USB Serial Device Configuration # USB Serial Device Configuration

View File

@ -852,6 +852,8 @@ STM3240G-EVAL-specific Configuration Options
want to do that? want to do that?
CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
debug. Depends on CONFIG_DEBUG. debug. Depends on CONFIG_DEBUG.
CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
packets. Depends on CONFIG_DEBUG.
Configurations Configurations
============== ==============

View File

@ -905,6 +905,8 @@ STM32F4Discovery-specific Configuration Options
want to do that? want to do that?
CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access
debug. Depends on CONFIG_DEBUG. debug. Depends on CONFIG_DEBUG.
CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB
packets. Depends on CONFIG_DEBUG.
Configurations Configurations
============== ==============

View File

@ -1,8 +1,8 @@
/******************************************************************************* /*******************************************************************************
* drivers/usbhost/usbhost_enumerate.c * drivers/usbhost/usbhost_enumerate.c
* *
* Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <spudmonkey@racsa.co.cr> * Authors: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -1,7 +1,7 @@
/************************************************************************************ /************************************************************************************
* include/nuttx/usb/usbhost.h * include/nuttx/usb/usbhost.h
* *
* Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. * Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* References: * References:
@ -284,7 +284,7 @@
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface was optimized under a particular assumption. It was assumed * This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor * that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -317,7 +317,7 @@
* Some hardware supports special memory in which request and descriptor data can * Some hardware supports special memory in which request and descriptor data can
* be accessed more efficiently. This method provides a mechanism to free that * be accessed more efficiently. This method provides a mechanism to free that
* request/descriptor memory. If the underlying hardware does not support * request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to free(). * such "special" memory, this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
@ -342,7 +342,7 @@
* Some hardware supports special memory in which larger IO buffers can * Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized. * This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
* *
@ -371,7 +371,7 @@
* Some hardware supports special memory in which IO data can be accessed more * Some hardware supports special memory in which IO data can be accessed more
* efficiently. This method provides a mechanism to free that IO buffer * efficiently. This method provides a mechanism to free that IO buffer
* memory. If the underlying hardware does not support such "special" memory, * memory. If the underlying hardware does not support such "special" memory,
* this functions may simply map to free(). * this functions may simply map to kfree().
* *
* Input Parameters: * Input Parameters:
* drvr - The USB host driver instance obtained as a parameter from the call to * drvr - The USB host driver instance obtained as a parameter from the call to
@ -615,7 +615,7 @@ struct usbhost_driver_s
* be accessed more efficiently. The following methods provide a mechanism * be accessed more efficiently. The following methods provide a mechanism
* to allocate and free the transfer descriptor memory. If the underlying * to allocate and free the transfer descriptor memory. If the underlying
* hardware does not support such "special" memory, these functions may * hardware does not support such "special" memory, these functions may
* simply map to malloc and free. * simply map to kmalloc and kfree.
* *
* This interface was optimized under a particular assumption. It was assumed * This interface was optimized under a particular assumption. It was assumed
* that the driver maintains a pool of small, pre-allocated buffers for descriptor * that the driver maintains a pool of small, pre-allocated buffers for descriptor
@ -630,7 +630,7 @@ struct usbhost_driver_s
/* Some hardware supports special memory in which larger IO buffers can /* Some hardware supports special memory in which larger IO buffers can
* be accessed more efficiently. This method provides a mechanism to allocate * be accessed more efficiently. This method provides a mechanism to allocate
* the request/descriptor memory. If the underlying hardware does not support * the request/descriptor memory. If the underlying hardware does not support
* such "special" memory, this functions may simply map to malloc. * such "special" memory, this functions may simply map to kmalloc.
* *
* This interface differs from DRVR_ALLOC in that the buffers are variable-sized. * This interface differs from DRVR_ALLOC in that the buffers are variable-sized.
*/ */