From 98d0ef6c36fb33301c697552a73e8f3d400a0c20 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 30 Aug 2012 18:18:47 +0000 Subject: Add USB host support for the STM3240G-EVAL board git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5069 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- nuttx/ChangeLog | 6 + nuttx/configs/stm3220g-eval/nsh/defconfig | 2 - nuttx/configs/stm3240g-eval/README.txt | 65 ++++- nuttx/configs/stm3240g-eval/dhcpd/defconfig | 14 +- nuttx/configs/stm3240g-eval/nettest/defconfig | 14 +- nuttx/configs/stm3240g-eval/nsh/defconfig | 14 +- nuttx/configs/stm3240g-eval/nsh2/defconfig | 14 +- nuttx/configs/stm3240g-eval/nxconsole/defconfig | 14 +- nuttx/configs/stm3240g-eval/nxwm/defconfig | 14 +- nuttx/configs/stm3240g-eval/ostest/defconfig | 14 +- nuttx/configs/stm3240g-eval/src/Makefile | 4 +- .../configs/stm3240g-eval/src/stm3240g-internal.h | 70 +++-- nuttx/configs/stm3240g-eval/src/up_boot.c | 11 +- nuttx/configs/stm3240g-eval/src/up_nsh.c | 87 +++--- nuttx/configs/stm3240g-eval/src/up_usb.c | 294 +++++++++++++++++++++ nuttx/configs/stm3240g-eval/src/up_usbdev.c | 103 -------- nuttx/configs/stm3240g-eval/telnetd/defconfig | 14 +- nuttx/configs/stm32f4discovery/nsh/defconfig | 2 - nuttx/configs/stm32f4discovery/nxlines/defconfig | 2 - nuttx/configs/stm32f4discovery/ostest/defconfig | 2 - nuttx/configs/stm32f4discovery/pm/defconfig | 2 - nuttx/configs/stm32f4discovery/src/up_usb.c | 2 + 22 files changed, 578 insertions(+), 186 deletions(-) create mode 100644 nuttx/configs/stm3240g-eval/src/up_usb.c delete mode 100644 nuttx/configs/stm3240g-eval/src/up_usbdev.c diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 5412295783..d628fffbb9 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3215,3 +3215,9 @@ appears to handle NAKing correctly is complete. * configs/stm32f4discovery/*: Added and verifed support for USB OTG FS host on the STM32F4Discovery board. + * configs/*/defconfig: Remove configuration documentation from config + files. It is redundant, error-prone, and difficult to maintain. + Configuration documentation is available in configs/README.txt for + common configurations and in configs/*/README.txt for board and MCU_ + specific configurations. + * configs/stm3240g-eval: Add USB host support. diff --git a/nuttx/configs/stm3220g-eval/nsh/defconfig b/nuttx/configs/stm3220g-eval/nsh/defconfig index 2b7f2c0872..226c65d26f 100644 --- a/nuttx/configs/stm3220g-eval/nsh/defconfig +++ b/nuttx/configs/stm3220g-eval/nsh/defconfig @@ -528,8 +528,6 @@ CONFIG_USBDEV_TRACE_NRECORDS=128 # # STM32 USB OTG FS Host Configuration # -# Pre-requisites -# CONFIG_USBHOST=n #CONFIG_STM32_OTGFS_RXFIFO_SIZE #CONFIG_STM32_OTGFS_NPTXFIFO_SIZE diff --git a/nuttx/configs/stm3240g-eval/README.txt b/nuttx/configs/stm3240g-eval/README.txt index 949db18913..907c8e199d 100755 --- a/nuttx/configs/stm3240g-eval/README.txt +++ b/nuttx/configs/stm3240g-eval/README.txt @@ -853,7 +853,7 @@ STM3240G-EVAL-specific Configuration Options want to do that? CONFIG_STM32_USBHOST_REGDEBUG - Enable very low-level register access debug. Depends on CONFIG_DEBUG. - CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB + CONFIG_STM32_USBHOST_PKTDUMP - Dump all incoming and outgoing USB packets. Depends on CONFIG_DEBUG. Configurations @@ -1028,8 +1028,67 @@ Where is one of the following: CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block CONFIG_STM32_SYSCFG - Needed CONFIG_SCHED_WORKQUEUE - Worker thread support is required - - 9. This configuration requires that jumper JP22 be set to enable RS-232 + + 9. USB OTG FS Host Support. The following changes will enable support for + a USB host on the STM32F4Discovery, including support for a mass storage + class driver: + + CONFIG_USBDEV=n - Make sure tht USB device support is disabled + CONFIG_USBHOST=y - Enable USB host support + CONFIG_STM32_OTGFS=y - Enable the STM32 USB OTG FS block + CONFIG_STM32_SYSCFG=y - Needed for all USB OTF FS support + CONFIG_SCHED_WORKQUEUE=y - Worker thread support is required for the mass + storage class driver. + CONFIG_NSH_ARCHINIT=y - Architecture specific USB initialization + is needed for NSH + CONFIG_FS_FAT=y - Needed by the USB host mass storage class. + + With those changes, you can use NSH with a FLASH pen driver as shown + belong. Here NSH is started with nothing in the USB host slot: + + NuttShell (NSH) NuttX-x.yy + nsh> ls /dev + /dev: + console + null + ttyS0 + + After inserting the FLASH drive, the /dev/sda appears and can be + mounted like this: + + nsh> ls /dev + /dev: + console + null + sda + ttyS0 + nsh> mount -t vfat /dev/sda /mnt/stuff + nsh> ls /mnt/stuff + /mnt/stuff: + -rw-rw-rw- 16236 filea.c + + And files on the FLASH can be manipulated to standard interfaces: + + nsh> echo "This is a test" >/mnt/stuff/atest.txt + nsh> ls /mnt/stuff + /mnt/stuff: + -rw-rw-rw- 16236 filea.c + -rw-rw-rw- 16 atest.txt + nsh> cat /mnt/stuff/atest.txt + This is a test + nsh> cp /mnt/stuff/filea.c fileb.c + nsh> ls /mnt/stuff + /mnt/stuff: + -rw-rw-rw- 16236 filea.c + -rw-rw-rw- 16 atest.txt + -rw-rw-rw- 16236 fileb.c + + To prevent data loss, don't forget to un-mount the FLASH drive + before removing it: + + nsh> umount /mnt/stuff + + 11. This configuration requires that jumper JP22 be set to enable RS-232 operation. nsh2: diff --git a/nuttx/configs/stm3240g-eval/dhcpd/defconfig b/nuttx/configs/stm3240g-eval/dhcpd/defconfig index 8b2c82018b..35a7140e48 100644 --- a/nuttx/configs/stm3240g-eval/dhcpd/defconfig +++ b/nuttx/configs/stm3240g-eval/dhcpd/defconfig @@ -440,7 +440,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -451,6 +451,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/nettest/defconfig b/nuttx/configs/stm3240g-eval/nettest/defconfig index cbc3c7706f..54d5f3fa8b 100644 --- a/nuttx/configs/stm3240g-eval/nettest/defconfig +++ b/nuttx/configs/stm3240g-eval/nettest/defconfig @@ -440,7 +440,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -451,6 +451,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/nsh/defconfig b/nuttx/configs/stm3240g-eval/nsh/defconfig index b21a140e7b..3e27810aa8 100644 --- a/nuttx/configs/stm3240g-eval/nsh/defconfig +++ b/nuttx/configs/stm3240g-eval/nsh/defconfig @@ -519,7 +519,7 @@ CONFIG_STMPE811_THRESHX=26 CONFIG_STMPE811_THRESHY=34 # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -530,6 +530,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/nsh2/defconfig b/nuttx/configs/stm3240g-eval/nsh2/defconfig index 1813fe7def..8e8c0fb8cb 100644 --- a/nuttx/configs/stm3240g-eval/nsh2/defconfig +++ b/nuttx/configs/stm3240g-eval/nsh2/defconfig @@ -490,7 +490,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -501,6 +501,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/nxconsole/defconfig b/nuttx/configs/stm3240g-eval/nxconsole/defconfig index c7a2dbacbc..ec66b3f99e 100644 --- a/nuttx/configs/stm3240g-eval/nxconsole/defconfig +++ b/nuttx/configs/stm3240g-eval/nxconsole/defconfig @@ -489,7 +489,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -500,6 +500,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/nxwm/defconfig b/nuttx/configs/stm3240g-eval/nxwm/defconfig index 3dd4102637..9f93fbf273 100644 --- a/nuttx/configs/stm3240g-eval/nxwm/defconfig +++ b/nuttx/configs/stm3240g-eval/nxwm/defconfig @@ -520,7 +520,7 @@ CONFIG_STMPE811_THRESHX=39 CONFIG_STMPE811_THRESHY=51 # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -531,6 +531,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/ostest/defconfig b/nuttx/configs/stm3240g-eval/ostest/defconfig index 6bfb26afc2..b38005e4dd 100644 --- a/nuttx/configs/stm3240g-eval/ostest/defconfig +++ b/nuttx/configs/stm3240g-eval/ostest/defconfig @@ -426,7 +426,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -437,6 +437,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm3240g-eval/src/Makefile b/nuttx/configs/stm3240g-eval/src/Makefile index 0e901a4d16..80225ea1fb 100644 --- a/nuttx/configs/stm3240g-eval/src/Makefile +++ b/nuttx/configs/stm3240g-eval/src/Makefile @@ -56,8 +56,8 @@ ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += up_buttons.c endif -ifeq ($(CONFIG_USBDEV),y) -CSRCS += up_usbdev.c +ifeq ($(CONFIG_STM32_OTGFS),y) +CSRCS += up_usb.c endif ifeq ($(CONFIG_STM32_FSMC),y) diff --git a/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h b/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h index c71aee75f0..cef4d2d19f 100644 --- a/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h +++ b/nuttx/configs/stm3240g-eval/src/stm3240g-internal.h @@ -134,9 +134,14 @@ * PF11 OTG_FS_Overcurrent */ -#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9) -#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTH|GPIO_PIN5) -#define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN11) +#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9) +#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTH|GPIO_PIN5) + +#ifdef CONFIG_USBHOST +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN11) +#else +# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTF|GPIO_PIN11) +#endif /* The STM3240G-EVAL has two STMPE811QTR I/O expanders on board both connected * to the STM32 via I2C1. They share a common interrupt line: PI2. @@ -212,77 +217,93 @@ void weak_function stm32_spiinitialize(void); -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_usbinitialize * * Description: - * Called to setup USB-related GPIO pins for the STM3210E-EVAL board. + * Called from stm32_usbinitialize very early in inialization to setup USB-related GPIO pins for + * the STM3240G-EVAL board. * - ************************************************************************************/ + ****************************************************************************************************/ +#ifdef CONFIG_STM32_OTGFS void weak_function stm32_usbinitialize(void); +#endif + +/**************************************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host functionality. This function will + * start a thread that will monitor for device connection/disconnection events. + * + ****************************************************************************************************/ + +#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST) +int stm32_usbhost_initialize(void); +#endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_extmemgpios * * Description: * Initialize GPIOs for external memory usage * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_extmemgpios(const uint32_t *gpios, int ngpios); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_extmemaddr * * Description: * Initialize adress line GPIOs for external memory access * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_extmemaddr(int naddrs); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_extmemdata * * Description: * Initialize data line GPIOs for external memory access * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_extmemdata(int ndata); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_enablefsmc * * Description: * enable clocking to the FSMC module * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_enablefsmc(void); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_disablefsmc * * Description: * enable clocking to the FSMC module * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_disablefsmc(void); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_selectsram * * Description: @@ -306,43 +327,43 @@ void stm32_disablefsmc(void); * word and uses the needed byte only). The NBL[1:0] are always kept low * during read transactions. * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_selectsram(void); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_deselectsram * * Description: * Disable SRAM * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_deselectsram(void); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_selectlcd * * Description: * Initialize to the LCD * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_selectlcd(void); #endif -/************************************************************************************ +/**************************************************************************************************** * Name: stm32_deselectlcd * * Description: * Disable the LCD * - ************************************************************************************/ + ****************************************************************************************************/ #ifdef CONFIG_STM32_FSMC void stm32_deselectlcd(void); @@ -350,4 +371,3 @@ void stm32_deselectlcd(void); #endif /* __ASSEMBLY__ */ #endif /* __CONFIGS_STM3240G_EVAL_SRC_STM3240G_INTERNAL_H */ - diff --git a/nuttx/configs/stm3240g-eval/src/up_boot.c b/nuttx/configs/stm3240g-eval/src/up_boot.c index 7322878e81..518bb4ff70 100644 --- a/nuttx/configs/stm3240g-eval/src/up_boot.c +++ b/nuttx/configs/stm3240g-eval/src/up_boot.c @@ -88,12 +88,13 @@ void stm32_boardinitialize(void) stm32_selectsram(); #endif - /* Initialize USB is 1) USBDEV is selected, 2) the OTG FS controller is not - * disabled, and 3) the weak function stm32_usbinitialize() has been brought - * into the build. + /* Initialize USB if the 1) OTG FS controller is in the configuration and 2) + * disabled, and 3) the weak function stm32_usbinitialize() has been brought + * the weak function stm32_usbinitialize() has been brought into the build. + * Presumeably either CONFIG_USBDEV or CONFIG_USBHOST is also selected. */ - -#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_OTGFS) + +#ifdef CONFIG_STM32_OTGFS if (stm32_usbinitialize) { stm32_usbinitialize(); diff --git a/nuttx/configs/stm3240g-eval/src/up_nsh.c b/nuttx/configs/stm3240g-eval/src/up_nsh.c index 016c68a357..c106e99180 100644 --- a/nuttx/configs/stm3240g-eval/src/up_nsh.c +++ b/nuttx/configs/stm3240g-eval/src/up_nsh.c @@ -55,7 +55,12 @@ # include #endif +#ifdef CONFIG_STM32_OTGFS +# include "stm32_usbhost.h" +#endif + #include "stm32_internal.h" +#include "stm3240g-internal.h" /**************************************************************************** * Pre-Processor Definitions @@ -67,41 +72,56 @@ #undef CONFIG_STM32_SPI1 -/* PORT and SLOT number probably depend on the board configuration */ +/* Assume that we support everything until convinced otherwise */ + +#define HAVE_MMCSD 1 +#define HAVE_USBDEV 1 +#define HAVE_USBHOST 1 + +/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support + * is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_STM32_SDIO) +# undef HAVE_MMCSD +#endif + +/* Default MMC/SD minor number */ + +#ifdef HAVE_MMCSD +# ifndef CONFIG_NSH_MMCSDMINOR +# define CONFIG_NSH_MMCSDMINOR 0 +# endif + +/* Default MMC/SD SLOT number */ -#ifdef CONFIG_ARCH_BOARD_STM3240G_EVAL -# define CONFIG_NSH_HAVEUSBDEV 1 -# define CONFIG_NSH_HAVEMMCSD 1 # if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0 # error "Only one MMC/SD slot" # undef CONFIG_NSH_MMCSDSLOTNO # endif + # ifndef CONFIG_NSH_MMCSDSLOTNO # define CONFIG_NSH_MMCSDSLOTNO 0 # endif -#else - /* Add configuration for new STM32 boards here */ -# error "Unrecognized STM32 board" -# undef CONFIG_NSH_HAVEUSBDEV -# undef CONFIG_NSH_HAVEMMCSD #endif -/* Can't support USB features if USB is not enabled */ +/* Can't support USB host or device features if USB OTG FS is not enabled */ -#ifndef CONFIG_USBDEV -# undef CONFIG_NSH_HAVEUSBDEV +#ifndef CONFIG_STM32_OTGFS +# undef HAVE_USBDEV +# undef HAVE_USBHOST #endif -/* Can't support MMC/SD features if mountpoints are disabled or if SDIO support - * is not enabled. - */ +/* Can't support USB device is USB device is not enabled */ -#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_STM32_SDIO) -# undef CONFIG_NSH_HAVEMMCSD +#ifndef CONFIG_USBDEV +# undef HAVE_USBDEV #endif -#ifndef CONFIG_NSH_MMCSDMINOR -# define CONFIG_NSH_MMCSDMINOR 0 +/* Can't support USB host is USB host is not enabled */ + +#ifndef CONFIG_USBHOST +# undef HAVE_USBHOST #endif /* Debug ********************************************************************/ @@ -138,8 +158,10 @@ int nsh_archinitialize(void) FAR struct spi_dev_s *spi; FAR struct mtd_dev_s *mtd; #endif -#ifdef CONFIG_NSH_HAVEMMCSD +#ifdef HAVE_MMCSD FAR struct sdio_dev_s *sdio; +#endif +#if defined(HAVE_MMCSD) || defined(HAVE_USBHOST) int ret; #endif @@ -148,35 +170,29 @@ 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 /* Mount the SDIO-based MMC/SD block driver */ -#ifdef CONFIG_NSH_HAVEMMCSD +#ifdef HAVE_MMCSD /* First, get an instance of the SDIO interface */ - message("nsh_archinitialize: Initializing SDIO slot %d\n", - CONFIG_NSH_MMCSDSLOTNO); sdio = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO); if (!sdio) { @@ -187,15 +203,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 STM3240G-EVAL board supports a GPIO to detect if there is a card in @@ -204,5 +217,19 @@ int nsh_archinitialize(void) sdio_mediachange(sdio, true); #endif + +#ifdef HAVE_USBHOST + /* Initialize USB host operation. stm32_usbhost_initialize() starts a thread + * will monitor for USB connection and disconnection events. + */ + + 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/stm3240g-eval/src/up_usb.c b/nuttx/configs/stm3240g-eval/src/up_usb.c new file mode 100644 index 0000000000..294fd661e3 --- /dev/null +++ b/nuttx/configs/stm3240g-eval/src/up_usb.c @@ -0,0 +1,294 @@ +/************************************************************************************ + * configs/stm3240g-eval/src/up_usbdev.c + * arch/arm/src/board/up_boot.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ************************************************************************************/ + +/************************************************************************************ + * Included Files + ************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "up_arch.h" +#include "stm32_internal.h" +#include "stm3240g-internal.h" + +#ifdef CONFIG_STM32_OTGFS + +/************************************************************************************ + * Pre-processor Definitions + ************************************************************************************/ + +#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST) +# define HAVE_USB 1 +#else +# warning "CONFIG_STM32_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST" +# 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_USBHOST +static struct usbhost_driver_s *g_drvr; +#endif + +/************************************************************************************ + * Private Functions + ************************************************************************************/ + +/************************************************************************************ + * Name: usbhost_waiter + * + * Description: + * Wait for USB devices to be connected. + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +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 + ************************************************************************************/ + +/************************************************************************************ + * Name: stm32_usbinitialize + * + * Description: + * Called from stm32_usbinitialize very early in inialization to setup USB-related + * GPIO pins for the STM3240G-EVAL board. + * + ************************************************************************************/ + +void stm32_usbinitialize(void) +{ + /* The OTG FS has an internal soft pull-up. No GPIO configuration is required */ + + /* Configure the OTG FS VBUS sensing GPIO, Power On, and Overcurrent GPIOs */ + +#ifdef CONFIG_STM32_OTGFS + stm32_configgpio(GPIO_OTGFS_VBUS); + stm32_configgpio(GPIO_OTGFS_PWRON); + stm32_configgpio(GPIO_OTGFS_OVER); +#endif +} + +/*********************************************************************************** + * Name: stm32_usbhost_initialize + * + * Description: + * Called at application startup time to initialize the USB host functionality. + * This function will start a thread that will monitor for device + * connection/disconnection events. + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +int stm32_usbhost_initialize(void) +{ + 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 + +/*********************************************************************************** + * Name: stm32_usbhost_vbusdrive + * + * Description: + * Enable/disable driving of VBUS 5V output. This function must be provided be + * each platform that implements the STM32 OTG FS host interface + * + * "On-chip 5 V VBUS generation is not supported. For this reason, a charge pump + * or, if 5 V are available on the application board, a basic power switch, must + * be added externally to drive the 5 V VBUS line. The external charge pump can + * be driven by any GPIO output. When the application decides to power on VBUS + * using the chosen GPIO, it must also set the port power bit in the host port + * control and status register (PPWR bit in OTG_FS_HPRT). + * + * "The application uses this field to control power to this port, and the core + * clears this bit on an overcurrent condition." + * + * Input Parameters: + * iface - For future growth to handle multiple USB host interface. Should be zero. + * enable - true: enable VBUS power; false: disable VBUS power + * + * Returned Value: + * None + * + ***********************************************************************************/ + +#ifdef CONFIG_USBHOST +void stm32_usbhost_vbusdrive(int iface, bool enable) +{ + DEBUGASSERT(iface == 0); + + if (enable) + { + /* Enable the Power Switch by driving the enable pin low */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, false); + } + else + { + /* Disable the Power Switch by driving the enable pin high */ + + stm32_gpiowrite(GPIO_OTGFS_PWRON, true); + } +} +#endif + +/************************************************************************************ + * Name: stm32_setup_overcurrent + * + * Description: + * Setup to receive an interrupt-level callback if an overcurrent condition is + * detected. + * + * Input paramter: + * handler - New overcurrent interrupt handler + * + * Returned value: + * Old overcurrent interrupt handler + * + ************************************************************************************/ + +#ifdef CONFIG_USBHOST +xcpt_t stm32_setup_overcurrent(xcpt_t handler) +{ + return stm32_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler); +} +#endif + +/************************************************************************************ + * Name: stm32_usbsuspend + * + * Description: + * Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is + * used. This function is called whenever the USB enters or leaves suspend mode. + * This is an opportunity for the board logic to shutdown clocks, power, etc. + * while the USB is suspended. + * + ************************************************************************************/ + +#ifdef CONFIG_USBDEV +void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume) +{ + ulldbg("resume: %d\n", resume); +} +#endif + +#endif /* CONFIG_STM32_OTGFS */ + + + diff --git a/nuttx/configs/stm3240g-eval/src/up_usbdev.c b/nuttx/configs/stm3240g-eval/src/up_usbdev.c deleted file mode 100644 index bd7f880b00..0000000000 --- a/nuttx/configs/stm3240g-eval/src/up_usbdev.c +++ /dev/null @@ -1,103 +0,0 @@ -/************************************************************************************ - * configs/stm3240g-eval/src/up_usbdev.c - * arch/arm/src/board/up_boot.c - * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ************************************************************************************/ - -/************************************************************************************ - * Included Files - ************************************************************************************/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "up_arch.h" -#include "stm32_internal.h" -#include "stm3240g-internal.h" - -/************************************************************************************ - * Definitions - ************************************************************************************/ - -/************************************************************************************ - * Private Functions - ************************************************************************************/ - -/************************************************************************************ - * Public Functions - ************************************************************************************/ - -/************************************************************************************ - * Name: stm32_usbinitialize - * - * Description: - * Called to setup USB-related GPIO pins for the STM3210E-EVAL board. - * - ************************************************************************************/ - -void stm32_usbinitialize(void) -{ - /* The OTG FS has an internal soft pull-up */ - - /* Configure the OTG FS VBUS sensing GPIO, Power On, and Overcurrent GPIOs */ - -#ifdef CONFIG_STM32_OTGFS - stm32_configgpio(GPIO_OTGFS_VBUS); - stm32_configgpio(GPIO_OTGFS_PWRON); - stm32_configgpio(GPIO_OTGFS_OVER); -#endif -} - -/************************************************************************************ - * Name: stm32_usbsuspend - * - * Description: - * Board logic must provide the stm32_usbsuspend logic if the USBDEV driver is - * used. This function is called whenever the USB enters or leaves suspend mode. - * This is an opportunity for the board logic to shutdown clocks, power, etc. - * while the USB is suspended. - * - ************************************************************************************/ - -void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume) -{ - ulldbg("resume: %d\n", resume); -} - diff --git a/nuttx/configs/stm3240g-eval/telnetd/defconfig b/nuttx/configs/stm3240g-eval/telnetd/defconfig index 2db1801e92..26686968a3 100644 --- a/nuttx/configs/stm3240g-eval/telnetd/defconfig +++ b/nuttx/configs/stm3240g-eval/telnetd/defconfig @@ -440,7 +440,7 @@ CONFIG_RTC_FREQUENCY=n CONFIG_RTC_ALARM=n # -# USB Device Configuration +# STM32 USB OTG FS Device Configuration # CONFIG_USBDEV=n CONFIG_USBDEV_ISOCHRONOUS=n @@ -451,6 +451,18 @@ CONFIG_USBDEV_MAXPOWER=100 CONFIG_USBDEV_TRACE=n CONFIG_USBDEV_TRACE_NRECORDS=128 +# +# STM32 USB OTG FS Host Configuration +# +CONFIG_USBHOST=n +#CONFIG_STM32_OTGFS_RXFIFO_SIZE +#CONFIG_STM32_OTGFS_NPTXFIFO_SIZE +#CONFIG_STM32_OTGFS_PTXFIFO_SIZE +#CONFIG_STM32_OTGFS_DESCSIZE +CONFIG_STM32_OTGFS_SOFINTR=n +CONFIG_STM32_USBHOST_REGDEBUG=n +CONFIG_STM32_USBHOST_PKTDUMP=n + # # USB Serial Device Configuration # diff --git a/nuttx/configs/stm32f4discovery/nsh/defconfig b/nuttx/configs/stm32f4discovery/nsh/defconfig index 01b4e89edf..16c9ea6491 100644 --- a/nuttx/configs/stm32f4discovery/nsh/defconfig +++ b/nuttx/configs/stm32f4discovery/nsh/defconfig @@ -460,8 +460,6 @@ CONFIG_USBDEV_TRACE_NRECORDS=128 # # STM32 USB OTG FS Host Configuration # -# Pre-requisites -# CONFIG_USBHOST=n #CONFIG_STM32_OTGFS_RXFIFO_SIZE #CONFIG_STM32_OTGFS_NPTXFIFO_SIZE diff --git a/nuttx/configs/stm32f4discovery/nxlines/defconfig b/nuttx/configs/stm32f4discovery/nxlines/defconfig index acb289df82..4c34a26a7f 100644 --- a/nuttx/configs/stm32f4discovery/nxlines/defconfig +++ b/nuttx/configs/stm32f4discovery/nxlines/defconfig @@ -460,8 +460,6 @@ CONFIG_USBDEV_TRACE_NRECORDS=128 # # STM32 USB OTG FS Host Configuration # -# Pre-requisites -# CONFIG_USBHOST=n #CONFIG_STM32_OTGFS_RXFIFO_SIZE #CONFIG_STM32_OTGFS_NPTXFIFO_SIZE diff --git a/nuttx/configs/stm32f4discovery/ostest/defconfig b/nuttx/configs/stm32f4discovery/ostest/defconfig index 2c3f9866df..094a1c4855 100644 --- a/nuttx/configs/stm32f4discovery/ostest/defconfig +++ b/nuttx/configs/stm32f4discovery/ostest/defconfig @@ -418,8 +418,6 @@ CONFIG_USBDEV_TRACE_NRECORDS=128 # # STM32 USB OTG FS Host Configuration # -# Pre-requisites -# CONFIG_USBHOST=n #CONFIG_STM32_OTGFS_RXFIFO_SIZE #CONFIG_STM32_OTGFS_NPTXFIFO_SIZE diff --git a/nuttx/configs/stm32f4discovery/pm/defconfig b/nuttx/configs/stm32f4discovery/pm/defconfig index 338baf585e..8d469b4c7e 100644 --- a/nuttx/configs/stm32f4discovery/pm/defconfig +++ b/nuttx/configs/stm32f4discovery/pm/defconfig @@ -479,8 +479,6 @@ CONFIG_USBDEV_TRACE_NRECORDS=128 # # STM32 USB OTG FS Host Configuration # -# Pre-requisites -# CONFIG_USBHOST=n #CONFIG_STM32_OTGFS_RXFIFO_SIZE #CONFIG_STM32_OTGFS_NPTXFIFO_SIZE diff --git a/nuttx/configs/stm32f4discovery/src/up_usb.c b/nuttx/configs/stm32f4discovery/src/up_usb.c index d4250bc2f0..89fc960062 100644 --- a/nuttx/configs/stm32f4discovery/src/up_usb.c +++ b/nuttx/configs/stm32f4discovery/src/up_usb.c @@ -281,10 +281,12 @@ xcpt_t stm32_setup_overcurrent(xcpt_t handler) * ************************************************************************************/ +#ifdef CONFIG_USBDEV void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume) { ulldbg("resume: %d\n", resume); } +#endif #endif /* CONFIG_STM32_OTGFS */ -- cgit v1.2.3