summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-08-15 22:13:50 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2012-08-15 22:13:50 +0000
commit62fc459beb3f3f39d02e781d126daef58fd5c66c (patch)
treecd77d7ff40ed0d637b3fc244ca75f959b353f579
parent959ba74831ee6f6c253f345f6db3e920d7a7bbcc (diff)
A little more STM32 USB host logic
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5029 7fd9a85b-ad96-42d3-883c-3090e2eb8679
-rw-r--r--nuttx/arch/arm/src/stm32/stm32_otgfshost.c22
-rw-r--r--nuttx/configs/stm3220g-eval/src/stm3220g-internal.h2
-rw-r--r--nuttx/configs/stm3220g-eval/src/up_nsh.c22
-rw-r--r--nuttx/configs/stm3220g-eval/src/up_usb.c92
4 files changed, 127 insertions, 11 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
index 75283107e3..57161088a7 100644
--- a/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
+++ b/nuttx/arch/arm/src/stm32/stm32_otgfshost.c
@@ -314,7 +314,8 @@ static void stm32_disconnect(FAR struct usbhost_driver_s *drvr);
/* Initialization **************************************************************/
-static inline void stm32_ep0init(struct stm32_usbhost_s *priv);
+static inline void stm32_ep0init(FAR struct stm32_usbhost_s *priv);
+static inline int stm32_hcdinitialize(FAR struct stm32_usbhost_s *priv);
/*******************************************************************************
* Private Data
@@ -2435,6 +2436,25 @@ static inline void stm32_ep0init(struct stm32_usbhost_s *priv)
}
/*******************************************************************************
+ * Name: stm32_hcdinitialize
+ *
+ * Description:
+ * Setup the host controller harware for normal operations.
+ *
+ * Input Parameters:
+ * priv -- USB host driver private data structure.
+ *
+ * Returned Value:
+ * Zero on success; a negated errno value on failure.
+ *
+ *******************************************************************************/
+
+static inline int stm32_hcdinitialize(FAR struct stm32_usbhost_s *priv)
+{
+#warning "Missing Logic"
+}
+
+/*******************************************************************************
* Public Functions
*******************************************************************************/
diff --git a/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h b/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h
index a93b7cd0eb..27f0a004c8 100644
--- a/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h
+++ b/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h
@@ -240,7 +240,7 @@ void weak_function stm32_usbinitialize(void);
****************************************************************************************************/
#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
-void stm32_usbhost_initialize(void);
+int stm32_usbhost_initialize(void);
#endif
/****************************************************************************************************
diff --git a/nuttx/configs/stm3220g-eval/src/up_nsh.c b/nuttx/configs/stm3220g-eval/src/up_nsh.c
index b296f229b2..3b061902ba 100644
--- a/nuttx/configs/stm3220g-eval/src/up_nsh.c
+++ b/nuttx/configs/stm3220g-eval/src/up_nsh.c
@@ -148,25 +148,22 @@ int nsh_archinitialize(void)
#ifdef CONFIG_STM32_SPI1
/* Get the SPI port */
- message("nsh_archinitialize: Initializing SPI port 1\n");
spi = up_spiinitialize(1);
if (!spi)
{
message("nsh_archinitialize: Failed to initialize SPI port 0\n");
return -ENODEV;
}
- message("nsh_archinitialize: Successfully initialized SPI port 0\n");
/* Now bind the SPI interface to the M25P64/128 SPI FLASH driver */
- message("nsh_archinitialize: Bind SPI to the SPI flash driver\n");
mtd = m25p_initialize(spi);
if (!mtd)
{
message("nsh_archinitialize: Failed to bind SPI port 0 to the SPI FLASH driver\n");
return -ENODEV;
}
- message("nsh_archinitialize: Successfully bound SPI port 0 to the SPI FLASH driver\n");
+
#warning "Now what are we going to do with this SPI FLASH driver?"
#endif
@@ -187,15 +184,12 @@ int nsh_archinitialize(void)
/* Now bind the SDIO interface to the MMC/SD driver */
- message("nsh_archinitialize: Bind SDIO to the MMC/SD driver, minor=%d\n",
- CONFIG_NSH_MMCSDMINOR);
ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
if (ret != OK)
{
message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
return ret;
}
- message("nsh_archinitialize: Successfully bound SDIO to the MMC/SD driver\n");
/* Then let's guess and say that there is a card in the slot. I need to check to
* see if the STM3220G-EVAL board supports a GPIO to detect if there is a card in
@@ -204,5 +198,19 @@ int nsh_archinitialize(void)
sdio_mediachange(sdio, true);
#endif
+
+ /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread
+ * will monitor for USB connection and disconnection events.
+ */
+
+#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
+ ret = stm32_usbhost_initialize();
+ if (ret != OK)
+ {
+ message("nsh_archinitialize: Failed to initialize USB host: %d\n", ret);
+ return ret;
+ }
+#endif
+
return OK;
}
diff --git a/nuttx/configs/stm3220g-eval/src/up_usb.c b/nuttx/configs/stm3220g-eval/src/up_usb.c
index 12cb2373f0..374d974ffc 100644
--- a/nuttx/configs/stm3220g-eval/src/up_usb.c
+++ b/nuttx/configs/stm3220g-eval/src/up_usb.c
@@ -46,6 +46,7 @@
#include <debug.h>
#include <nuttx/usb/usbdev.h>
+#include <nuttx/usb/usbhost.h>
#include <nuttx/usb/usbdev_trace.h>
#include "up_arch.h"
@@ -65,10 +66,67 @@
# undef HAVE_USB
#endif
+#ifndef CONFIG_USBHOST_DEFPRIO
+# define CONFIG_USBHOST_DEFPRIO 50
+#endif
+
+#ifndef CONFIG_USBHOST_STACKSIZE
+# define CONFIG_USBHOST_STACKSIZE 1024
+#endif
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+
+#ifdef CONFIG_NSH_HAVEUSBHOST
+static struct usbhost_driver_s *g_drvr;
+#endif
+
/************************************************************************************
* Private Functions
************************************************************************************/
+/****************************************************************************
+ * Name: usbhost_waiter
+ *
+ * Description:
+ * Wait for USB devices to be connected.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NSH_HAVEUSBHOST
+static int usbhost_waiter(int argc, char *argv[])
+{
+ bool connected = false;
+ int ret;
+
+ uvdbg("Running\n");
+ for (;;)
+ {
+ /* Wait for the device to change state */
+
+ ret = DRVR_WAIT(g_drvr, connected);
+ DEBUGASSERT(ret == OK);
+
+ connected = !connected;
+ uvdbg("%s\n", connected ? "connected" : "disconnected");
+
+ /* Did we just become connected? */
+
+ if (connected)
+ {
+ /* Yes.. enumerate the newly connected device */
+
+ (void)DRVR_ENUMERATE(g_drvr);
+ }
+ }
+
+ /* Keep the compiler from complaining */
+
+ return 0;
+}
+#endif
+
/************************************************************************************
* Public Functions
************************************************************************************/
@@ -106,9 +164,39 @@ void stm32_usbinitialize(void)
***********************************************************************************/
#ifdef CONFIG_USBHOST
-void stm32_usbhost_initialize(void)
+int stm32_usbhost_initialize(void)
{
-#warning "Missing logic"
+ int pid;
+ int ret;
+
+ /* First, register all of the class drivers needed to support the drivers
+ * that we care about:
+ */
+
+ uvdbg("Register class drivers\n");
+ ret = usbhost_storageinit();
+ if (ret != OK)
+ {
+ udbg("Failed to register the mass storage class\n");
+ }
+
+ /* Then get an instance of the USB host interface */
+
+ uvdbg("Initialize USB host\n");
+ g_drvr = usbhost_initialize(0);
+ if (g_drvr)
+ {
+ /* Start a thread to handle device connection. */
+
+ uvdbg("Start usbhost_waiter\n");
+
+ pid = TASK_CREATE("usbhost", CONFIG_USBHOST_DEFPRIO,
+ CONFIG_USBHOST_STACKSIZE,
+ (main_t)usbhost_waiter, (const char **)NULL);
+ return pid < 0 ? -ENOEXEC : OK;
+ }
+
+ return -ENODEV;
}
#endif