Add USB host support to the STM32F4Discovery board
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5066 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
2ea9da27fb
commit
632eb9651e
@ -861,11 +861,16 @@ Where <subdir> is one of the following:
|
||||
8. USB OTG FS Device or Host Support
|
||||
|
||||
CONFIG_USBDEV - Enable USB device support, OR
|
||||
CONFIG_USBHOST - Enable USB host support
|
||||
CONFIG_USBHOST - Enable USB host support (but not both)
|
||||
|
||||
CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
CONFIG_STM32_SYSCFG - Needed
|
||||
CONFIG_SCHED_WORKQUEUE - Worker thread support is required
|
||||
|
||||
CONFIG_STM32_SYSCFG - Needed for all USB OTF FS support
|
||||
|
||||
CONFIG_SCHED_WORKQUEUE - Worker thread support is required for the mass
|
||||
storage class (both host and device).
|
||||
CONFIG_NSH_ARCHINIT - Architecture specific USB initialization
|
||||
is needed
|
||||
|
||||
9. This configuration requires that jumper JP22 be set to enable RS-232 operation.
|
||||
|
||||
nsh2:
|
||||
|
@ -88,13 +88,13 @@ static struct usbhost_driver_s *g_drvr;
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
/************************************************************************************
|
||||
* Name: usbhost_waiter
|
||||
*
|
||||
* Description:
|
||||
* Wait for USB devices to be connected.
|
||||
*
|
||||
****************************************************************************/
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_USBHOST
|
||||
static int usbhost_waiter(int argc, char *argv[])
|
||||
|
@ -1066,6 +1066,19 @@ Where <subdir> is one of the following:
|
||||
you can still use certain kinds of debug output (see include/debug.h, all
|
||||
of the interfaces based on lib_lowprintf will work in this configuration).
|
||||
|
||||
8. USB OTG FS Device or Host Support
|
||||
|
||||
CONFIG_USBDEV - Enable USB device support, OR
|
||||
CONFIG_USBHOST - Enable USB host support (but not both)
|
||||
|
||||
CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
CONFIG_STM32_SYSCFG - Needed for all USB OTF FS support
|
||||
|
||||
CONFIG_SCHED_WORKQUEUE - Worker thread support is required for the mass
|
||||
storage class (both host and device).
|
||||
CONFIG_NSH_ARCHINIT - Architecture specific USB initialization
|
||||
is needed
|
||||
|
||||
nxlines:
|
||||
------
|
||||
An example using the NuttX graphics system (NX). This example focuses on
|
||||
|
@ -34,17 +34,19 @@
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ARCH_BOARD_BOARD_H
|
||||
#define __ARCH_BOARD_BOARD_H
|
||||
#ifndef __CONFIG_STM32F4DISCOVERY_INCLUDE_BOARD_H
|
||||
#define __CONFIG_STM32F4DISCOVERY_INCLUDE_BOARD_H
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "stm32_rcc.h"
|
||||
#include "stm32_sdio.h"
|
||||
#include "stm32_internal.h"
|
||||
@ -318,4 +320,4 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_BOARD_BOARD_H */
|
||||
#endif /* __CONFIG_STM32F4DISCOVERY_INCLUDE_BOARD_H */
|
||||
|
@ -831,7 +831,7 @@ CONFIG_RTC_FREQUENCY=n
|
||||
CONFIG_RTC_ALARM=n
|
||||
|
||||
#
|
||||
# USB Device Configuration
|
||||
# STM32 USB OTG FS Device Configuration
|
||||
#
|
||||
# CONFIG_USBDEV
|
||||
# Enables USB device support
|
||||
@ -858,6 +858,41 @@ CONFIG_USBDEV_MAXPOWER=100
|
||||
CONFIG_USBDEV_TRACE=n
|
||||
CONFIG_USBDEV_TRACE_NRECORDS=128
|
||||
|
||||
#
|
||||
# STM32 USB OTG FS Host Configuration
|
||||
#
|
||||
# Pre-requisites
|
||||
#
|
||||
# CONFIG_USBHOST - Enable general USB host support
|
||||
# CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
# CONFIG_STM32_SYSCFG - Needed
|
||||
# CONFIG_SCHED_WORKQUEUE - Worker thread support is required
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
|
||||
# Default 128 (512 bytes)
|
||||
# CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
|
||||
# in 32-bit words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
|
||||
# words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_DESCSIZE - Maximum size of a descriptor. Default: 128
|
||||
# CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever
|
||||
# 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
|
||||
# packets. Depends on CONFIG_DEBUG.
|
||||
#
|
||||
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 (Prolifics PL2303 emulation)
|
||||
#
|
||||
|
@ -831,7 +831,7 @@ CONFIG_RTC_FREQUENCY=n
|
||||
CONFIG_RTC_ALARM=n
|
||||
|
||||
#
|
||||
# USB Device Configuration
|
||||
# STM32 USB OTG FS Device Configuration
|
||||
#
|
||||
# CONFIG_USBDEV
|
||||
# Enables USB device support
|
||||
@ -858,6 +858,41 @@ CONFIG_USBDEV_MAXPOWER=100
|
||||
CONFIG_USBDEV_TRACE=n
|
||||
CONFIG_USBDEV_TRACE_NRECORDS=128
|
||||
|
||||
#
|
||||
# STM32 USB OTG FS Host Configuration
|
||||
#
|
||||
# Pre-requisites
|
||||
#
|
||||
# CONFIG_USBHOST - Enable general USB host support
|
||||
# CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
# CONFIG_STM32_SYSCFG - Needed
|
||||
# CONFIG_SCHED_WORKQUEUE - Worker thread support is required
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
|
||||
# Default 128 (512 bytes)
|
||||
# CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
|
||||
# in 32-bit words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
|
||||
# words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_DESCSIZE - Maximum size of a descriptor. Default: 128
|
||||
# CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever
|
||||
# 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
|
||||
# packets. Depends on CONFIG_DEBUG.
|
||||
#
|
||||
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 (Prolifics PL2303 emulation)
|
||||
#
|
||||
|
@ -783,7 +783,7 @@ CONFIG_RTC_FREQUENCY=n
|
||||
CONFIG_RTC_ALARM=n
|
||||
|
||||
#
|
||||
# USB Device Configuration
|
||||
# STM32 USB OTG FS Device Configuration
|
||||
#
|
||||
# CONFIG_USBDEV
|
||||
# Enables USB device support
|
||||
@ -810,6 +810,41 @@ CONFIG_USBDEV_MAXPOWER=100
|
||||
CONFIG_USBDEV_TRACE=n
|
||||
CONFIG_USBDEV_TRACE_NRECORDS=128
|
||||
|
||||
#
|
||||
# STM32 USB OTG FS Host Configuration
|
||||
#
|
||||
# Pre-requisites
|
||||
#
|
||||
# CONFIG_USBHOST - Enable general USB host support
|
||||
# CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
# CONFIG_STM32_SYSCFG - Needed
|
||||
# CONFIG_SCHED_WORKQUEUE - Worker thread support is required
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
|
||||
# Default 128 (512 bytes)
|
||||
# CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
|
||||
# in 32-bit words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
|
||||
# words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_DESCSIZE - Maximum size of a descriptor. Default: 128
|
||||
# CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever
|
||||
# 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
|
||||
# packets. Depends on CONFIG_DEBUG.
|
||||
#
|
||||
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
|
||||
#
|
||||
|
@ -850,7 +850,7 @@ CONFIG_RTC_FREQUENCY=1
|
||||
CONFIG_RTC_ALARM=y
|
||||
|
||||
#
|
||||
# USB Device Configuration
|
||||
# STM32 USB OTG FS Device Configuration
|
||||
#
|
||||
# CONFIG_USBDEV
|
||||
# Enables USB device support
|
||||
@ -877,6 +877,41 @@ CONFIG_USBDEV_MAXPOWER=100
|
||||
CONFIG_USBDEV_TRACE=n
|
||||
CONFIG_USBDEV_TRACE_NRECORDS=128
|
||||
|
||||
#
|
||||
# STM32 USB OTG FS Host Configuration
|
||||
#
|
||||
# Pre-requisites
|
||||
#
|
||||
# CONFIG_USBHOST - Enable general USB host support
|
||||
# CONFIG_STM32_OTGFS - Enable the STM32 USB OTG FS block
|
||||
# CONFIG_STM32_SYSCFG - Needed
|
||||
# CONFIG_SCHED_WORKQUEUE - Worker thread support is required
|
||||
#
|
||||
# Options:
|
||||
#
|
||||
# CONFIG_STM32_OTGFS_RXFIFO_SIZE - Size of the RX FIFO in 32-bit words.
|
||||
# Default 128 (512 bytes)
|
||||
# CONFIG_STM32_OTGFS_NPTXFIFO_SIZE - Size of the non-periodic Tx FIFO
|
||||
# in 32-bit words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_PTXFIFO_SIZE - Size of the periodic Tx FIFO in 32-bit
|
||||
# words. Default 96 (384 bytes)
|
||||
# CONFIG_STM32_OTGFS_DESCSIZE - Maximum size of a descriptor. Default: 128
|
||||
# CONFIG_STM32_OTGFS_SOFINTR - Enable SOF interrupts. Why would you ever
|
||||
# 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
|
||||
# packets. Depends on CONFIG_DEBUG.
|
||||
#
|
||||
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 (Prolifics PL2303 emulation)
|
||||
#
|
||||
|
@ -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_PWM),y)
|
||||
@ -72,6 +72,10 @@ ifeq ($(CONFIG_WATCHDOG),y)
|
||||
CSRCS += up_watchdog.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NSH_ARCHINIT),y)
|
||||
CSRCS += up_nsh.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_PM_CUSTOMINIT),y)
|
||||
CSRCS += up_pm.c
|
||||
endif
|
||||
|
@ -105,7 +105,13 @@
|
||||
|
||||
#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_PORTC|GPIO_PIN0)
|
||||
#define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5)
|
||||
|
||||
#ifdef CONFIG_USBHOST
|
||||
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5)
|
||||
|
||||
#else
|
||||
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5)
|
||||
#endif
|
||||
|
||||
/****************************************************************************************************
|
||||
* Public Types
|
||||
@ -131,92 +137,112 @@
|
||||
|
||||
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 STM32F4Discovery 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: up_ledpminitialize
|
||||
****************************************************************************/
|
||||
*
|
||||
* Description:
|
||||
* Enable logic to use the LEDs on the STM32F4Discovery to support power management testing
|
||||
*
|
||||
****************************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_PM
|
||||
void up_ledpminitialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
/****************************************************************************************************
|
||||
* Name: up_pmbuttons
|
||||
*
|
||||
* Description:
|
||||
* Configure the user button of the STM32f4discovery board as EXTI,
|
||||
* so it is able to wakeup the MCU from the PM_STANDBY mode
|
||||
*
|
||||
****************************************************************************/
|
||||
****************************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_PM) && defined(CONFIG_IDLE_CUSTOM) && defined(CONFIG_PM_BUTTONS)
|
||||
void up_pmbuttons(void);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* configs/stm32f4discovery/src/up_boot.c
|
||||
* arch/arm/src/board/up_boot.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -82,12 +82,13 @@ void stm32_boardinitialize(void)
|
||||
}
|
||||
#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();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32f4discovery/src/up_usbdev.c
|
||||
* arch/arm/src/board/up_boot.c
|
||||
/****************************************************************************
|
||||
* config/stm32f4discovery/src/up_nsh.c
|
||||
* arch/arm/src/board/up_nsh.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
@ -32,72 +32,103 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
#include <nuttx/usb/usbdev_trace.h>
|
||||
#ifdef CONFIG_STM32_SDIO
|
||||
# include <nuttx/sdio.h>
|
||||
# include <nuttx/mmcsd.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_OTGFS
|
||||
# include "stm32_usbhost.h"
|
||||
#endif
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "stm32_internal.h"
|
||||
#include "stm32f4discovery-internal.h"
|
||||
|
||||
/************************************************************************************
|
||||
* Definitions
|
||||
************************************************************************************/
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
#define HAVE_USBDEV 1
|
||||
#define HAVE_USBHOST 1
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_usbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to setup USB-related GPIO pins for the STM3210E-EVAL board.
|
||||
*
|
||||
************************************************************************************/
|
||||
/* Can't support USB host or device features if USB OTG FS is not enabled */
|
||||
|
||||
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);
|
||||
#ifndef CONFIG_STM32_OTGFS
|
||||
# undef HAVE_USBDEV
|
||||
# undef HAVE_USBHOST
|
||||
#endif
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_usbsuspend
|
||||
/* Can't support USB device is USB device is not enabled */
|
||||
|
||||
#ifndef CONFIG_USBDEV
|
||||
# undef HAVE_USBDEV
|
||||
#endif
|
||||
|
||||
/* Can't support USB host is USB host is not enabled */
|
||||
|
||||
#ifndef CONFIG_USBHOST
|
||||
# undef HAVE_USBHOST
|
||||
#endif
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# else
|
||||
# define message printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_archinitialize
|
||||
*
|
||||
* 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.
|
||||
* Perform architecture specific initialization
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
|
||||
int nsh_archinitialize(void)
|
||||
{
|
||||
ulldbg("resume: %d\n", resume);
|
||||
}
|
||||
#ifdef HAVE_USBHOST
|
||||
int ret;
|
||||
|
||||
/* 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;
|
||||
}
|
292
configs/stm32f4discovery/src/up_usb.c
Normal file
292
configs/stm32f4discovery/src/up_usb.c
Normal file
@ -0,0 +1,292 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32f4discovery/src/up_usbdev.c
|
||||
* arch/arm/src/board/up_boot.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
#include <nuttx/usb/usbhost.h>
|
||||
#include <nuttx/usb/usbdev_trace.h>
|
||||
|
||||
#include "up_arch.h"
|
||||
#include "stm32_internal.h"
|
||||
#include "stm32f4discovery-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 STM32F4Discovery 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void stm32_usbsuspend(FAR struct usbdev_s *dev, bool resume)
|
||||
{
|
||||
ulldbg("resume: %d\n", resume);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_STM32_OTGFS */
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user