forked from Archive/PX4-Autopilot
A little more STM32 USB host logic
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5029 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
dd681d7fff
commit
5a8984c800
|
@ -314,7 +314,8 @@ static void stm32_disconnect(FAR struct usbhost_driver_s *drvr);
|
||||||
|
|
||||||
/* Initialization **************************************************************/
|
/* 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
|
* Private Data
|
||||||
|
@ -2434,6 +2435,25 @@ static inline void stm32_ep0init(struct stm32_usbhost_s *priv)
|
||||||
stm32_putreg(regval, STM32_USBHOST_CTRL);
|
stm32_putreg(regval, STM32_USBHOST_CTRL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
* Public Functions
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
/****************************************************************************************************
|
/****************************************************************************************************
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue