diff --git a/configs/nucleus2g/README.txt b/configs/nucleus2g/README.txt index 654fd90894c777a8d9a94d39afbe525bee927f0a..8e75cbedcab92bcc34aade7c3a661485be94e3a4 100755 --- a/configs/nucleus2g/README.txt +++ b/configs/nucleus2g/README.txt @@ -14,6 +14,7 @@ Contents NuttX buildroot Toolchain LEDs Nucleus 2G Configuration Options + USB Host Configuration Configurations Nucleus 2G Board @@ -432,6 +433,38 @@ Nucleus 2G Configuration Options CONFIG_LPC17_USBDEV_DMA 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 ^^^^^^^^^^^^^^ diff --git a/configs/nucleus2g/nsh/defconfig b/configs/nucleus2g/nsh/defconfig index 447df77ba32346f79980e34644b8e368ea6501ae..408fdbc1ff71b13f90426e672f027ca06fc262b9 100755 --- a/configs/nucleus2g/nsh/defconfig +++ b/configs/nucleus2g/nsh/defconfig @@ -102,6 +102,7 @@ CONFIG_LPC17_BUILDROOT=y # # Individual subsystems can be enabled: # (MAINOSC, PLL0, PLL1 and FLASH are controlled in board.h) +# CONFIG_LPC17_ETHERNET=n CONFIG_LPC17_USBHOST=n CONFIG_LPC17_USBOTG=n @@ -194,6 +195,8 @@ CONFIG_UART3_2STOP=0 # CONFIG_NET_PRIORITY - Ethernet interrupt priority. The is default is # the higest priority. # 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_DEBUG. # CONFIG_NET_HASH - Enable receipt of near-perfect match frames. @@ -329,8 +332,8 @@ CONFIG_RR_INTERVAL=200 CONFIG_SCHED_INSTRUMENTATION=n CONFIG_TASK_NAME_SIZE=0 CONFIG_START_YEAR=2010 -CONFIG_START_MONTH=6 -CONFIG_START_DAY=20 +CONFIG_START_MONTH=12 +CONFIG_START_DAY=22 CONFIG_GREGORIAN_TIME=n CONFIG_JULIAN_TIME=n CONFIG_DEV_CONSOLE=y @@ -456,6 +459,7 @@ CONFIG_PREALLOC_TIMERS=4 # CONFIG_FS_FAT - Enable FAT filesystem support # CONFIG_FAT_SECTORSIZE - Max supported sector size # CONFIG_FS_ROMFS - Enable ROMFS filesystem support +# CONFIG_FS_FAT=y CONFIG_FS_ROMFS=n @@ -583,7 +587,18 @@ CONFIG_USBDEV_TRACE=n 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 # Handle USB Start-Of-Frame events. @@ -604,6 +619,27 @@ CONFIG_LPC17_USBDEV_DMA=n CONFIG_LPC17_USBDEV_NDMADESCRIPTORS=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 # @@ -688,6 +724,19 @@ CONFIG_EXAMPLE_UIP_DHCPC=n # # 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_PERFORMANCE=n CONFIG_EXAMPLE_NETTEST_NOMAC=n diff --git a/configs/nucleus2g/src/up_nsh.c b/configs/nucleus2g/src/up_nsh.c index 3cd3515fe5a6d00007d8bd4acdf1a1018f482891..301057be0c1ade50c3a7142298114136412a643f 100755 --- a/configs/nucleus2g/src/up_nsh.c +++ b/configs/nucleus2g/src/up_nsh.c @@ -46,6 +46,10 @@ #include <nuttx/spi.h> #include <nuttx/mmcsd.h> +#include <nuttx/usb/usbhost.h> + +#include "lpc17_internal.h" +#include "nucleus2g_internal.h" /**************************************************************************** * Pre-Processor Definitions @@ -58,6 +62,7 @@ #ifdef CONFIG_ARCH_BOARD_NUCLEUS2G # define CONFIG_EXAMPLES_NSH_HAVEUSBDEV 1 # define CONFIG_EXAMPLES_NSH_HAVEMMCSD 1 +# define CONFIG_EXAMPLES_NSH_HAVEUSBHOST 1 # if !defined(CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO) || CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO != 0 # error "The Nucleus-2G MMC/SD is on SSP0" # undef CONFIG_EXAMPLES_NSH_MMCSDSPIPORTNO @@ -75,9 +80,10 @@ # error "Unrecognized board" # undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV # undef CONFIG_EXAMPLES_NSH_HAVEMMCSD +# undef CONFIG_EXAMPLES_NSH_HAVEUSBHOST #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 # undef CONFIG_EXAMPLES_NSH_HAVEUSBDEV @@ -93,6 +99,33 @@ # define CONFIG_EXAMPLES_NSH_MMCSDMINOR 0 #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 ********************************************************************/ #ifdef CONFIG_CPP_HAVE_VARARGS @@ -109,6 +142,97 @@ # 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 ****************************************************************************/ @@ -151,5 +275,15 @@ int nsh_archinitialize(void) message("Successfuly bound SSP port %d to MMC/SD slot %d\n", 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; } diff --git a/configs/olimex-lpc1766stk/README.txt b/configs/olimex-lpc1766stk/README.txt index 7618766b02c87f1d952256775964d377437a6c29..822ae98bb7b0fef94129599b3177f7bee9c541a7 100755 --- a/configs/olimex-lpc1766stk/README.txt +++ b/configs/olimex-lpc1766stk/README.txt @@ -14,6 +14,7 @@ Contents LEDs Using OpenOCD and GDB with an FT2232 JTAG emulator Olimex LPC1766-STK Configuration Options + USB Host Configuration Configurations Olimex LPC1766-STK development board @@ -678,6 +679,38 @@ Olimex LPC1766-STK Configuration Options CONFIG_LPC17_USBDEV_DMA 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 ^^^^^^^^^^^^^^