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
This commit is contained in:
patacongo 2012-08-15 22:13:50 +00:00
parent fcf9a415c2
commit 7a6161ac2a
3 changed files with 106 additions and 10 deletions

View File

@ -240,7 +240,7 @@ void weak_function stm32_usbinitialize(void);
****************************************************************************************************/ ****************************************************************************************************/
#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) #if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
void stm32_usbhost_initialize(void); int stm32_usbhost_initialize(void);
#endif #endif
/**************************************************************************************************** /****************************************************************************************************

View File

@ -148,25 +148,22 @@ int nsh_archinitialize(void)
#ifdef CONFIG_STM32_SPI1 #ifdef CONFIG_STM32_SPI1
/* Get the SPI port */ /* Get the SPI port */
message("nsh_archinitialize: Initializing SPI port 1\n");
spi = up_spiinitialize(1); spi = up_spiinitialize(1);
if (!spi) if (!spi)
{ {
message("nsh_archinitialize: Failed to initialize SPI port 0\n"); message("nsh_archinitialize: Failed to initialize SPI port 0\n");
return -ENODEV; return -ENODEV;
} }
message("nsh_archinitialize: Successfully initialized SPI port 0\n");
/* Now bind the SPI interface to the M25P64/128 SPI FLASH driver */ /* 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); mtd = m25p_initialize(spi);
if (!mtd) if (!mtd)
{ {
message("nsh_archinitialize: Failed to bind SPI port 0 to the SPI FLASH driver\n"); message("nsh_archinitialize: Failed to bind SPI port 0 to the SPI FLASH driver\n");
return -ENODEV; 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?" #warning "Now what are we going to do with this SPI FLASH driver?"
#endif #endif
@ -187,15 +184,12 @@ int nsh_archinitialize(void)
/* Now bind the SDIO interface to the MMC/SD driver */ /* 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); ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, sdio);
if (ret != OK) if (ret != OK)
{ {
message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret); message("nsh_archinitialize: Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
return 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 /* 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 * 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); sdio_mediachange(sdio, true);
#endif #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; return OK;
} }

View File

@ -46,6 +46,7 @@
#include <debug.h> #include <debug.h>
#include <nuttx/usb/usbdev.h> #include <nuttx/usb/usbdev.h>
#include <nuttx/usb/usbhost.h>
#include <nuttx/usb/usbdev_trace.h> #include <nuttx/usb/usbdev_trace.h>
#include "up_arch.h" #include "up_arch.h"
@ -65,10 +66,67 @@
# undef HAVE_USB # undef HAVE_USB
#endif #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 * 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 * Public Functions
************************************************************************************/ ************************************************************************************/
@ -106,9 +164,39 @@ void stm32_usbinitialize(void)
***********************************************************************************/ ***********************************************************************************/
#ifdef CONFIG_USBHOST #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 #endif