Add USB host support to Nucleus2G

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3217 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2010-12-23 00:49:46 +00:00
parent 29492d87e0
commit a20e12e3c4
4 changed files with 254 additions and 5 deletions
+33
View File
@@ -14,6 +14,7 @@ Contents
NuttX buildroot Toolchain NuttX buildroot Toolchain
LEDs LEDs
Nucleus 2G Configuration Options Nucleus 2G Configuration Options
USB Host Configuration
Configurations Configurations
Nucleus 2G Board Nucleus 2G Board
@@ -432,6 +433,38 @@ Nucleus 2G Configuration Options
CONFIG_LPC17_USBDEV_DMA CONFIG_LPC17_USBDEV_DMA
Enable lpc17xx-specific DMA support Enable lpc17xx-specific DMA support
USB Host Configuration
^^^^^^^^^^^^^^^^^^^^^^
The NuttShell (NSH) Nucleus 2G can be modified in order to support
USB host operations. To make these modifications, do the following:
1. First configure to build the NSH configuration from the top-level
NuttX directory:
cd tools
./configure nucleus2g/nsh
cd ..
2. Then edit the top-level .config file to enable USB host. Make the
following changes:
CONFIG_LPC17_USBHOST=n
CONFIG_USBHOST=n
CONFIG_SCHED_WORKQUEUE=y
When this change is made, NSH should be extended to support USB flash
devices. When a FLASH device is inserted, you should see a device
appear in the /dev (psuedo) directory. The device name should be
like /dev/sda, /dev/sdb, etc. The USB mass storage device, is present
it can be mounted from the NSH command line like:
ls /dev
mount -t vfat /dev/sda /mnt/flash
Files on the connect USB flash device should then be accessible under
the mountpoint /mnt/flash.
Configurations Configurations
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^
+52 -3
View File
@@ -102,6 +102,7 @@ CONFIG_LPC17_BUILDROOT=y
# #
# Individual subsystems can be enabled: # Individual subsystems can be enabled:
# (MAINOSC, PLL0, PLL1 and FLASH are controlled in board.h) # (MAINOSC, PLL0, PLL1 and FLASH are controlled in board.h)
#
CONFIG_LPC17_ETHERNET=n CONFIG_LPC17_ETHERNET=n
CONFIG_LPC17_USBHOST=n CONFIG_LPC17_USBHOST=n
CONFIG_LPC17_USBOTG=n CONFIG_LPC17_USBOTG=n
@@ -194,6 +195,8 @@ CONFIG_UART3_2STOP=0
# CONFIG_NET_PRIORITY - Ethernet interrupt priority. The is default is # CONFIG_NET_PRIORITY - Ethernet interrupt priority. The is default is
# the higest priority. # the higest priority.
# CONFIG_NET_WOL - Enable Wake-up on Lan (not fully implemented). # CONFIG_NET_WOL - Enable Wake-up on Lan (not fully implemented).
# CONFIG_NET_DUMPPACKET - Dump all received and transmitted packets.
# Also needs CONFIG_DEBUG.
# CONFIG_NET_REGDEBUG - Enabled low level register debug. Also needs # CONFIG_NET_REGDEBUG - Enabled low level register debug. Also needs
# CONFIG_DEBUG. # CONFIG_DEBUG.
# CONFIG_NET_HASH - Enable receipt of near-perfect match frames. # CONFIG_NET_HASH - Enable receipt of near-perfect match frames.
@@ -329,8 +332,8 @@ CONFIG_RR_INTERVAL=200
CONFIG_SCHED_INSTRUMENTATION=n CONFIG_SCHED_INSTRUMENTATION=n
CONFIG_TASK_NAME_SIZE=0 CONFIG_TASK_NAME_SIZE=0
CONFIG_START_YEAR=2010 CONFIG_START_YEAR=2010
CONFIG_START_MONTH=6 CONFIG_START_MONTH=12
CONFIG_START_DAY=20 CONFIG_START_DAY=22
CONFIG_GREGORIAN_TIME=n CONFIG_GREGORIAN_TIME=n
CONFIG_JULIAN_TIME=n CONFIG_JULIAN_TIME=n
CONFIG_DEV_CONSOLE=y CONFIG_DEV_CONSOLE=y
@@ -456,6 +459,7 @@ CONFIG_PREALLOC_TIMERS=4
# CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FS_FAT - Enable FAT filesystem support
# CONFIG_FAT_SECTORSIZE - Max supported sector size # CONFIG_FAT_SECTORSIZE - Max supported sector size
# CONFIG_FS_ROMFS - Enable ROMFS filesystem support # CONFIG_FS_ROMFS - Enable ROMFS filesystem support
#
CONFIG_FS_FAT=y CONFIG_FS_FAT=y
CONFIG_FS_ROMFS=n CONFIG_FS_ROMFS=n
@@ -583,7 +587,18 @@ CONFIG_USBDEV_TRACE=n
CONFIG_USBDEV_TRACE_NRECORDS=128 CONFIG_USBDEV_TRACE_NRECORDS=128
# #
# LPC17xx USB Configuration # USB Host Configuration
#
# CONFIG_USBHOST
# Enables USB host support
# CONFIG_USBHOST_NPREALLOC
# Number of pre-allocated class instances
#
CONFIG_USBHOST=n
CONFIG_USBHOST_NPREALLOC=0
#
# LPC17xx USB Device Configuration
# #
# CONFIG_LPC17_USBDEV_FRAME_INTERRUPT # CONFIG_LPC17_USBDEV_FRAME_INTERRUPT
# Handle USB Start-Of-Frame events. # Handle USB Start-Of-Frame events.
@@ -604,6 +619,27 @@ CONFIG_LPC17_USBDEV_DMA=n
CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=0 CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=0
CONFIG_LPC17_USBDEV_DMAINTMASK=0 CONFIG_LPC17_USBDEV_DMAINTMASK=0
#
# LPC17xx USB Host Configuration
#
# OHCI RAM layout:
# CONFIG_USBHOST_OHCIRAM_SIZE
# Total size of OHCI RAM (in AHB SRAM Bank 1)
# CONFIG_USBHOST_NEDS
# Number of endpoint descriptors
# CONFIG_USBHOST_TDBUFFERS
# Number of transfer descriptor buffers
# CONFIG_USBHOST_TDBUFSIZE
# Size of one transfer descriptor buffer
# CONFIG_USBHOST_IOBUFSIZE
# Size of one end-user I/O buffer
#
CONFIG_USBHOST_OHCIRAM_SIZE=1280
CONFIG_USBHOST_NEDS=2
CONFIG_USBHOST_TDBUFFERS=3
CONFIG_USBHOST_TDBUFSIZE=128
CONFIG_USBHOST_IOBUFSIZE=512
# #
# USB Serial Device Configuration # USB Serial Device Configuration
# #
@@ -688,6 +724,19 @@ CONFIG_EXAMPLE_UIP_DHCPC=n
# #
# Settings for examples/nettest # Settings for examples/nettest
# CONFIG_EXAMPLE_NETTEST_SERVER - The target board can act
# as either the client side or server side of the test
# CONFIG_EXAMPLE_NETTEST_PERFORMANCE - If set, then the
# client side simply receives messages forever, allowing
# measurement of throughput
# CONFIG_EXAMPLE_NETTEST_NOMAC - Set if the hardware has
# no MAC address; one will be assigned
# CONFIG_EXAMPLE_NETTEST_IPADDR - Target board IP address
# CONFIG_EXAMPLE_NETTEST_DRIPADDR - Default router address
# CONFIG_EXAMPLE_NETTEST_NETMASK - Network mask
# CONFIG_EXAMPLE_NETTEST_CLIENTIP - IP address of the
# client side of the test (may be target or host)
#
CONFIG_EXAMPLE_NETTEST_SERVER=n CONFIG_EXAMPLE_NETTEST_SERVER=n
CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n CONFIG_EXAMPLE_NETTEST_PERFORMANCE=n
CONFIG_EXAMPLE_NETTEST_NOMAC=n CONFIG_EXAMPLE_NETTEST_NOMAC=n
+136 -2
View File
@@ -46,6 +46,10 @@
#include <nuttx/spi.h> #include <nuttx/spi.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#include <nuttx/usb/usbhost.h>
#include "lpc17_internal.h"
#include "nucleus2g_internal.h"
/**************************************************************************** /****************************************************************************
* Pre-Processor Definitions * Pre-Processor Definitions
@@ -58,6 +62,7 @@
#ifdef CONFIG_ARCH_BOARD_NUCLEUS2G #ifdef CONFIG_ARCH_BOARD_NUCLEUS2G
# define CONFIG_EXAMPLES_NSH_HAVEUSBDEV 1 # define CONFIG_EXAMPLES_NSH_HAVEUSBDEV 1
# define CONFIG_EXAMPLES_NSH_HAVEMMCSD 1 # define CONFIG_EXAMPLES_NSH_HAVEMMCSD 1
# define CONFIG_EXAMPLES_NSH_HAVEUSBHOST 1
# if !defined(CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO) || CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO != 0 # if !defined(CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO) || CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO != 0
# error "The Nucleus-2G MMC/SD is on SSP0" # error "The Nucleus-2G MMC/SD is on SSP0"
# undef CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO # undef CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO
@@ -75,9 +80,10 @@
# error "Unrecognized board" # error "Unrecognized board"
# undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV # undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV
# undef CONFIG_EXAMPLES_NSH_HAVEMMCSD # undef CONFIG_EXAMPLES_NSH_HAVEMMCSD
# undef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
#endif #endif
/* Can't support USB features if USB is not enabled */ /* Can't support USB device features if USB device is not enabled */
#ifndef CONFIG_USBDEV #ifndef CONFIG_USBDEV
# undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV # undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV
@@ -93,6 +99,33 @@
# define CONFIG_EXAMPLES_NSH_MMCSDMINOR 0 # define CONFIG_EXAMPLES_NSH_MMCSDMINOR 0
#endif #endif
/* USB Host */
#ifdef CONFIG_USBHOST
# ifndef CONFIG_LPC17_USBHOST
# error "CONFIG_LPC17_USBHOST is not selected"
# endif
#endif
#ifdef CONFIG_LPC17_USBHOST
# ifndef CONFIG_USBHOST
# warning "CONFIG_USBHOST is not selected"
# endif
#endif
#if !defined(CONFIG_USBHOST) || !defined(CONFIG_LPC17_USBHOST)
# undef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
#endif
#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
# ifndef CONFIG_USBHOST_DEFPRIO
# define CONFIG_USBHOST_DEFPRIO 50
# endif
# ifndef CONFIG_USBHOST_STACKSIZE
# define CONFIG_USBHOST_STACKSIZE 1024
# endif
#endif
/* Debug ********************************************************************/ /* Debug ********************************************************************/
#ifdef CONFIG_CPP_HAVE_VARARGS #ifdef CONFIG_CPP_HAVE_VARARGS
@@ -109,6 +142,97 @@
# endif # endif
#endif #endif
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
static struct usbhost_driver_s *g_drvr;
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nsh_waiter
*
* Description:
* Wait for USB devices to be connected.
*
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
static int nsh_waiter(int argc, char *argv[])
{
bool connected = false;
int ret;
message("nsh_waiter: Running\n");
for (;;)
{
/* Wait for the device to change state */
ret = DRVR_WAIT(g_drvr, connected);
DEBUGASSERT(ret == OK);
connected = !connected;
message("nsh_waiter: %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
/****************************************************************************
* Name: nsh_usbhostinitialize
*
* Description:
* Initialize SPI-based microSD.
*
****************************************************************************/
#ifdef CONFIG_EXAMPLES_NSH_HAVEUSBHOST
static int nsh_usbhostinitialize(void)
{
int pid;
/* First, get an instance of the USB host interface */
g_drvr = usbhost_initialize(0);
if (g_drvr)
{
/* Start a thread to handle device connection. */
message("nsh_usbhostinitialize: Start nsh_waiter\n");
#ifndef CONFIG_CUSTOM_STACK
pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO,
CONFIG_USBHOST_STACKSIZE,
(main_t)nsh_waiter, (const char **)NULL);
#else
pid = task_create("usbhost", CONFIG_USBHOST_DEFPRIO,
(main_t)nsh_waiter, (const char **)NULL);
#endif
return pid < 0 ? -ENOEXEC : OK;
}
return -ENODEV;
}
#else
# define nsh_usbhostinitialize() (OK)
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -151,5 +275,15 @@ int nsh_archinitialize(void)
message("Successfuly bound SSP port %d to MMC/SD slot %d\n", message("Successfuly bound SSP port %d to MMC/SD slot %d\n",
CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO, CONFIG_EXAMPLES_NSH_MMCSDSLOTNO); CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO, CONFIG_EXAMPLES_NSH_MMCSDSLOTNO);
return OK;
/* Initialize USB host */
ret = nsh_usbhostinitialize();
if (ret == OK)
{
message("USB host successfuly initialized!\n");
}
return ret;
} }
+33
View File
@@ -14,6 +14,7 @@ Contents
LEDs LEDs
Using OpenOCD and GDB with an FT2232 JTAG emulator Using OpenOCD and GDB with an FT2232 JTAG emulator
Olimex LPC1766-STK Configuration Options Olimex LPC1766-STK Configuration Options
USB Host Configuration
Configurations Configurations
Olimex LPC1766-STK development board Olimex LPC1766-STK development board
@@ -678,6 +679,38 @@ Olimex LPC1766-STK Configuration Options
CONFIG_LPC17_USBDEV_DMA CONFIG_LPC17_USBDEV_DMA
Enable lpc17xx-specific DMA support Enable lpc17xx-specific DMA support
USB Host Configuration
^^^^^^^^^^^^^^^^^^^^^^
The NuttShell (NSH) Nucleus 2G can be modified in order to support
USB host operations. To make these modifications, do the following:
1. First configure to build the NSH configuration from the top-level
NuttX directory:
cd tools
./configure nucleus2g/nsh
cd ..
2. Then edit the top-level .config file to enable USB host. Make the
following changes:
CONFIG_LPC17_USBHOST=n
CONFIG_USBHOST=n
CONFIG_SCHED_WORKQUEUE=y
When this change is made, NSH should be extended to support USB flash
devices. When a FLASH device is inserted, you should see a device
appear in the /dev (psuedo) directory. The device name should be
like /dev/sda, /dev/sdb, etc. The USB mass storage device, is present
it can be mounted from the NSH command line like:
ls /dev
mount -t vfat /dev/sda /mnt/flash
Files on the connect USB flash device should then be accessible under
the mountpoint /mnt/flash.
Configurations Configurations
^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^