diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-15 22:13:50 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-08-15 22:13:50 +0000 |
commit | aafd9e1a14fcb857c9e843c78563a3a935510b9e (patch) | |
tree | cd77d7ff40ed0d637b3fc244ca75f959b353f579 /nuttx/configs/stm3220g-eval/src | |
parent | 165225fde2020b456e0f84e019eba21f6acb3129 (diff) | |
download | px4-nuttx-aafd9e1a14fcb857c9e843c78563a3a935510b9e.tar.gz px4-nuttx-aafd9e1a14fcb857c9e843c78563a3a935510b9e.tar.bz2 px4-nuttx-aafd9e1a14fcb857c9e843c78563a3a935510b9e.zip |
A little more STM32 USB host logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5029 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/configs/stm3220g-eval/src')
-rw-r--r-- | nuttx/configs/stm3220g-eval/src/stm3220g-internal.h | 2 | ||||
-rw-r--r-- | nuttx/configs/stm3220g-eval/src/up_nsh.c | 22 | ||||
-rw-r--r-- | nuttx/configs/stm3220g-eval/src/up_usb.c | 92 |
3 files changed, 106 insertions, 10 deletions
diff --git a/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h b/nuttx/configs/stm3220g-eval/src/stm3220g-internal.h index a93b7cd0e..27f0a004c 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 b296f229b..3b061902b 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 12cb2373f..374d974ff 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 |