mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
initial code for USB OTG support in STM32L4. Builds, but needs debugging.
This commit is contained in:
@@ -44,7 +44,7 @@ CONFIG_RAW_BINARY=y
|
||||
#
|
||||
CONFIG_DEBUG=y
|
||||
CONFIG_ARCH_HAVE_HEAPCHECK=y
|
||||
# CONFIG_DEBUG_VERBOSE is not set
|
||||
CONFIG_DEBUG_VERBOSE=y
|
||||
|
||||
#
|
||||
# Subsystem Debug Options
|
||||
@@ -71,6 +71,7 @@ CONFIG_ARCH_HAVE_HEAPCHECK=y
|
||||
# CONFIG_DEBUG_GPIO is not set
|
||||
# CONFIG_DEBUG_RTC is not set
|
||||
# CONFIG_DEBUG_SPI is not set
|
||||
CONFIG_DEBUG_USB=y
|
||||
CONFIG_ARCH_HAVE_STACKCHECK=y
|
||||
# CONFIG_STACK_COLORATION is not set
|
||||
CONFIG_DEBUG_SYMBOLS=y
|
||||
@@ -223,7 +224,7 @@ CONFIG_STM32L4_DMA2=y
|
||||
#
|
||||
# AHB2 Peripherals
|
||||
#
|
||||
# CONFIG_STM32L4_OTGFS is not set
|
||||
CONFIG_STM32L4_OTGFS=y
|
||||
# CONFIG_STM32L4_ADC1 is not set
|
||||
# CONFIG_STM32L4_ADC2 is not set
|
||||
# CONFIG_STM32L4_ADC3 is not set
|
||||
@@ -338,6 +339,7 @@ CONFIG_ARCH_HAVE_RESET=y
|
||||
# CONFIG_ARCH_USE_MPU is not set
|
||||
# CONFIG_ARCH_IRQPRIO is not set
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_USBDUMP=y
|
||||
# CONFIG_ENDIAN_BIG is not set
|
||||
# CONFIG_ARCH_IDLE_CUSTOM is not set
|
||||
# CONFIG_ARCH_HAVE_RAMFUNCS is not set
|
||||
@@ -400,6 +402,7 @@ CONFIG_LIB_BOARDCTL=y
|
||||
# CONFIG_BOARDCTL_RESET is not set
|
||||
CONFIG_BOARDCTL_UNIQUEID=y
|
||||
CONFIG_BOARDCTL_UNIQUEID_SIZE=12
|
||||
CONFIG_BOARDCTL_USBDEVCTRL=y
|
||||
# CONFIG_BOARDCTL_TSCTEST is not set
|
||||
# CONFIG_BOARDCTL_ADCTEST is not set
|
||||
# CONFIG_BOARDCTL_PWMTEST is not set
|
||||
@@ -596,6 +599,7 @@ CONFIG_N25QXXX_SECTOR512=y
|
||||
# CONFIG_MTD_RAMTRON is not set
|
||||
# CONFIG_MTD_SST25 is not set
|
||||
# CONFIG_MTD_SST25XX is not set
|
||||
# CONFIG_MTD_SST26 is not set
|
||||
# CONFIG_MTD_SST39FV is not set
|
||||
# CONFIG_MTD_W25 is not set
|
||||
# CONFIG_EEPROM is not set
|
||||
@@ -606,6 +610,7 @@ CONFIG_N25QXXX_SECTOR512=y
|
||||
# CONFIG_SERCOMM_CONSOLE is not set
|
||||
CONFIG_SERIAL=y
|
||||
# CONFIG_DEV_LOWCONSOLE is not set
|
||||
CONFIG_SERIAL_REMOVABLE=y
|
||||
# CONFIG_16550_UART is not set
|
||||
# CONFIG_ARCH_HAVE_UART is not set
|
||||
# CONFIG_ARCH_HAVE_UART0 is not set
|
||||
@@ -657,7 +662,50 @@ CONFIG_USART2_2STOP=0
|
||||
# CONFIG_USART2_IFLOWCONTROL is not set
|
||||
# CONFIG_USART2_OFLOWCONTROL is not set
|
||||
# CONFIG_USART2_DMA is not set
|
||||
# CONFIG_USBDEV is not set
|
||||
CONFIG_USBDEV=y
|
||||
|
||||
#
|
||||
# USB Device Controller Driver Options
|
||||
#
|
||||
# CONFIG_USBDEV_ISOCHRONOUS is not set
|
||||
# CONFIG_USBDEV_DUALSPEED is not set
|
||||
CONFIG_USBDEV_SELFPOWERED=y
|
||||
# CONFIG_USBDEV_BUSPOWERED is not set
|
||||
CONFIG_USBDEV_MAXPOWER=100
|
||||
# CONFIG_USBDEV_DMA is not set
|
||||
# CONFIG_ARCH_USBDEV_STALLQUEUE is not set
|
||||
CONFIG_USBDEV_TRACE=y
|
||||
CONFIG_USBDEV_TRACE_NRECORDS=128
|
||||
CONFIG_USBDEV_TRACE_STRINGS=y
|
||||
CONFIG_USBDEV_TRACE_INITIALIDSET=y
|
||||
|
||||
#
|
||||
# USB Device Class Driver Options
|
||||
#
|
||||
# CONFIG_USBDEV_COMPOSITE is not set
|
||||
# CONFIG_PL2303 is not set
|
||||
CONFIG_CDCACM=y
|
||||
# CONFIG_CDCACM_CONSOLE is not set
|
||||
CONFIG_CDCACM_EP0MAXPACKET=64
|
||||
CONFIG_CDCACM_EPINTIN=1
|
||||
CONFIG_CDCACM_EPINTIN_FSSIZE=64
|
||||
CONFIG_CDCACM_EPINTIN_HSSIZE=64
|
||||
CONFIG_CDCACM_EPBULKOUT=3
|
||||
CONFIG_CDCACM_EPBULKOUT_FSSIZE=64
|
||||
CONFIG_CDCACM_EPBULKOUT_HSSIZE=512
|
||||
CONFIG_CDCACM_EPBULKIN=2
|
||||
CONFIG_CDCACM_EPBULKIN_FSSIZE=64
|
||||
CONFIG_CDCACM_EPBULKIN_HSSIZE=512
|
||||
CONFIG_CDCACM_NRDREQS=4
|
||||
CONFIG_CDCACM_NWRREQS=4
|
||||
CONFIG_CDCACM_BULKIN_REQLEN=96
|
||||
CONFIG_CDCACM_RXBUFSIZE=257
|
||||
CONFIG_CDCACM_TXBUFSIZE=193
|
||||
CONFIG_CDCACM_VENDORID=0x0525
|
||||
CONFIG_CDCACM_PRODUCTID=0xa4a7
|
||||
CONFIG_CDCACM_VENDORSTR="NuttX"
|
||||
CONFIG_CDCACM_PRODUCTSTR="CDC/ACM Serial"
|
||||
# CONFIG_USBMSC is not set
|
||||
# CONFIG_USBHOST is not set
|
||||
# CONFIG_DRIVERS_WIRELESS is not set
|
||||
|
||||
@@ -737,7 +785,7 @@ CONFIG_FS_PROCFS_REGISTER=y
|
||||
# Memory Management
|
||||
#
|
||||
# CONFIG_MM_SMALL is not set
|
||||
CONFIG_MM_REGIONS=1
|
||||
CONFIG_MM_REGIONS=2
|
||||
# CONFIG_ARCH_HAVE_HEAP2 is not set
|
||||
# CONFIG_GRAN is not set
|
||||
|
||||
@@ -910,7 +958,13 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
|
||||
# CONFIG_EXAMPLES_TOUCHSCREEN is not set
|
||||
# CONFIG_EXAMPLES_WEBSERVER is not set
|
||||
# CONFIG_EXAMPLES_UNIONFS is not set
|
||||
# CONFIG_EXAMPLES_USBSERIAL is not set
|
||||
CONFIG_EXAMPLES_USBSERIAL=y
|
||||
CONFIG_EXAMPLES_USBSERIAL_BUFSIZE=512
|
||||
CONFIG_EXAMPLES_USBSERIAL_TRACEINIT=y
|
||||
CONFIG_EXAMPLES_USBSERIAL_TRACECLASS=y
|
||||
CONFIG_EXAMPLES_USBSERIAL_TRACETRANSFERS=y
|
||||
CONFIG_EXAMPLES_USBSERIAL_TRACECONTROLLER=y
|
||||
CONFIG_EXAMPLES_USBSERIAL_TRACEINTERRUPTS=y
|
||||
# CONFIG_EXAMPLES_USBTERM is not set
|
||||
# CONFIG_EXAMPLES_WATCHDOG is not set
|
||||
|
||||
@@ -967,7 +1021,7 @@ CONFIG_NSH_LINELEN=64
|
||||
# CONFIG_NSH_DISABLE_SEMICOLON is not set
|
||||
# CONFIG_NSH_CMDPARMS is not set
|
||||
CONFIG_NSH_MAXARGUMENTS=6
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
CONFIG_NSH_ARGCAT=y
|
||||
CONFIG_NSH_NESTDEPTH=3
|
||||
# CONFIG_NSH_DISABLEBG is not set
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
@@ -1053,7 +1107,18 @@ CONFIG_NSH_ARCHROMFS=y
|
||||
# Console Configuration
|
||||
#
|
||||
CONFIG_NSH_CONSOLE=y
|
||||
# CONFIG_NSH_USBCONSOLE is not set
|
||||
# CONFIG_NSH_ALTCONDEV is not set
|
||||
|
||||
#
|
||||
# USB Device Trace Support
|
||||
#
|
||||
CONFIG_NSH_USBDEV_TRACE=y
|
||||
CONFIG_NSH_USBDEV_TRACEINIT=y
|
||||
CONFIG_NSH_USBDEV_TRACECLASS=y
|
||||
CONFIG_NSH_USBDEV_TRACETRANSFERS=y
|
||||
CONFIG_NSH_USBDEV_TRACECONTROLLER=y
|
||||
CONFIG_NSH_USBDEV_TRACEINTERRUPTS=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
# CONFIG_NSH_LOGIN is not set
|
||||
# CONFIG_NSH_CONSOLE_LOGIN is not set
|
||||
@@ -1085,6 +1150,8 @@ CONFIG_READLINE_ECHO=y
|
||||
# CONFIG_READLINE_CMD_HISTORY is not set
|
||||
# CONFIG_SYSTEM_SUDOKU is not set
|
||||
# CONFIG_SYSTEM_VI is not set
|
||||
# CONFIG_SYSTEM_CDCACM is not set
|
||||
# CONFIG_SYSTEM_UBLOXMODEM is not set
|
||||
# CONFIG_SYSTEM_USBMONITOR is not set
|
||||
# CONFIG_SYSTEM_ZMODEM is not set
|
||||
CONFIG_SYSTEM_DISCOTEST=y
|
||||
|
||||
@@ -42,7 +42,7 @@ ifeq ($(CONFIG_ARCH_BOARD_STM32L4_CUSTOM_CLOCKCONFIG),y)
|
||||
CSRCS += stm32_clockconfig.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STM32_OTGFS),y)
|
||||
ifeq ($(CONFIG_STM32L4_OTGFS),y)
|
||||
CSRCS += stm32_usb.c
|
||||
endif
|
||||
|
||||
|
||||
@@ -262,6 +262,30 @@ FAR struct mtd_dev_s *mtd_temp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USBHOST
|
||||
/* Initialize USB host operation. stm32l4_usbhost_initialize() starts a thread
|
||||
* will monitor for USB connection and disconnection events.
|
||||
*/
|
||||
|
||||
ret = stm32l4_usbhost_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to initialize USB host: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_USBMONITOR
|
||||
/* Start the USB Monitor */
|
||||
|
||||
ret = usbmonitor_start(0, NULL);
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to start USB monitor: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif /* CONFIG_LIB_BOARDCTL */
|
||||
|
||||
@@ -81,12 +81,12 @@ void stm32l4_boardinitialize(void)
|
||||
stm32l4_spiinitialize();
|
||||
#endif
|
||||
|
||||
/* Initialize USB is 1) USBDEV is selected, 2) the USB controller is not
|
||||
#ifdef CONFIG_STM32L4_OTGFS
|
||||
/* 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
|
||||
* into the build.
|
||||
* into the build. Presumably either CONFIG_USBDEV or CONFIG_USBHOST is also
|
||||
* selected.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
|
||||
stm32l4_usbinitialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
/************************************************************************************
|
||||
* configs/stm32f4discovery/src/stm32_usb.c
|
||||
*
|
||||
* Copyright (C) 2012-2013, 2015 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 <assert.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 "stm32l4.h"
|
||||
#include "stm32l4_otgfs.h"
|
||||
#include "stm32l476vg-disco.h"
|
||||
|
||||
#ifdef CONFIG_STM32L4_OTGFS
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
#if defined(CONFIG_USBDEV) || defined(CONFIG_USBHOST)
|
||||
# define HAVE_USB 1
|
||||
#else
|
||||
# warning "CONFIG_STM32L4_OTGFS is enabled but neither CONFIG_USBDEV nor CONFIG_USBHOST"
|
||||
# undef HAVE_USB
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_STM32L4DISCO_USBHOST_PRIO
|
||||
# define CONFIG_STM32L4DISCO_USBHOST_PRIO 100
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_STM32L4DISCO_USBHOST_STACKSIZE
|
||||
# define CONFIG_STM32L4DISCO_USBHOST_STACKSIZE 1024
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_USBHOST
|
||||
static struct usbhost_connection_s *g_usbconn;
|
||||
#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[])
|
||||
{
|
||||
struct usbhost_hubport_s *hport;
|
||||
|
||||
uvdbg("Running\n");
|
||||
for (;;)
|
||||
{
|
||||
/* Wait for the device to change state */
|
||||
|
||||
DEBUGVERIFY(CONN_WAIT(g_usbconn, &hport));
|
||||
uvdbg("%s\n", hport->connected ? "connected" : "disconnected");
|
||||
|
||||
/* Did we just become connected? */
|
||||
|
||||
if (hport->connected)
|
||||
{
|
||||
/* Yes.. enumerate the newly connected device */
|
||||
|
||||
(void)CONN_ENUMERATE(g_usbconn, hport);
|
||||
}
|
||||
}
|
||||
|
||||
/* Keep the compiler from complaining */
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32l4_usbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called from stm32l4_usbinitialize very early in initialization to setup USB-related
|
||||
* GPIO pins for the STM32L4Discovery board.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void stm32l4_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 Over current GPIOs */
|
||||
|
||||
#ifdef CONFIG_STM32L4_OTGFS
|
||||
stm32l4_configgpio(GPIO_OTGFS_VBUS);
|
||||
stm32l4_configgpio(GPIO_OTGFS_PWRON);
|
||||
stm32l4_configgpio(GPIO_OTGFS_OVER);
|
||||
#endif
|
||||
}
|
||||
|
||||
/***********************************************************************************
|
||||
* Name: stm32l4_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 stm32l4_usbhost_initialize(void)
|
||||
{
|
||||
int pid;
|
||||
#if defined(CONFIG_USBHOST_HUB) || defined(CONFIG_USBHOST_MSC) || \
|
||||
defined(CONFIG_USBHOST_HIDKBD) || defined(CONFIG_USBHOST_HIDMOUSE)
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* First, register all of the class drivers needed to support the drivers
|
||||
* that we care about:
|
||||
*/
|
||||
|
||||
uvdbg("Register class drivers\n");
|
||||
|
||||
#ifdef CONFIG_USBHOST_HUB
|
||||
/* Initialize USB hub class support */
|
||||
|
||||
ret = usbhost_hub_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
udbg("ERROR: usbhost_hub_initialize failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_MSC
|
||||
/* Register the USB mass storage class class */
|
||||
|
||||
ret = usbhost_msc_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to register the mass storage class: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_CDCACM
|
||||
/* Register the CDC/ACM serial class */
|
||||
|
||||
ret = usbhost_cdcacm_initialize();
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("ERROR: Failed to register the CDC/ACM serial class: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_HIDKBD
|
||||
/* Initialize the HID keyboard class */
|
||||
|
||||
ret = usbhost_kbdinit();
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("Failed to register the HID keyboard class\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USBHOST_HIDMOUSE
|
||||
/* Initialize the HID mouse class */
|
||||
|
||||
ret = usbhost_mouse_init();
|
||||
if (ret != OK)
|
||||
{
|
||||
udbg("Failed to register the HID mouse class\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then get an instance of the USB host interface */
|
||||
|
||||
uvdbg("Initialize USB host\n");
|
||||
g_usbconn = stm32l4_otgfshost_initialize(0);
|
||||
if (g_usbconn)
|
||||
{
|
||||
/* Start a thread to handle device connection. */
|
||||
|
||||
uvdbg("Start usbhost_waiter\n");
|
||||
|
||||
pid = task_create("usbhost", CONFIG_STM32L4DISCO_USBHOST_PRIO,
|
||||
CONFIG_STM32L4DISCO_USBHOST_STACKSIZE,
|
||||
(main_t)usbhost_waiter, (FAR char * const *)NULL);
|
||||
return pid < 0 ? -ENOEXEC : OK;
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***********************************************************************************
|
||||
* Name: stm32l4_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 over current 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 stm32l4_usbhost_vbusdrive(int iface, bool enable)
|
||||
{
|
||||
DEBUGASSERT(iface == 0);
|
||||
|
||||
if (enable)
|
||||
{
|
||||
/* Enable the Power Switch by driving the enable pin low */
|
||||
|
||||
stm32l4_gpiowrite(GPIO_OTGFS_PWRON, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable the Power Switch by driving the enable pin high */
|
||||
|
||||
stm32l4_gpiowrite(GPIO_OTGFS_PWRON, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32l4_setup_overcurrent
|
||||
*
|
||||
* Description:
|
||||
* Setup to receive an interrupt-level callback if an over current condition is
|
||||
* detected.
|
||||
*
|
||||
* Input Parameter:
|
||||
* handler - New over current interrupt handler
|
||||
*
|
||||
* Returned value:
|
||||
* Old over current interrupt handler
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_USBHOST
|
||||
xcpt_t stm32l4_setup_overcurrent(xcpt_t handler)
|
||||
{
|
||||
return stm32l4_gpiosetevent(GPIO_OTGFS_OVER, true, true, true, handler);
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32l4_usbsuspend
|
||||
*
|
||||
* Description:
|
||||
* Board logic must provide the stm32l4_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 stm32l4_usbsuspend(FAR struct usbdev_s *dev, bool resume)
|
||||
{
|
||||
ulldbg("resume: %d\n", resume);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_STM32L4_OTGFS */
|
||||
@@ -59,6 +59,9 @@
|
||||
#define HAVE_N25QXXX_NXFFS 1
|
||||
#define HAVE_N25QXXX_SMARTFS 1
|
||||
#define HAVE_N25QXXX_CHARDEV 1
|
||||
#define HAVE_USBDEV 1
|
||||
#define HAVE_USBHOST 1
|
||||
#define HAVE_USBMONITOR 1
|
||||
|
||||
#if !defined(CONFIG_FS_PROCFS)
|
||||
# undef HAVE_PROC
|
||||
@@ -124,6 +127,55 @@
|
||||
|
||||
#define PROGMEM_MTD_MINOR 1
|
||||
|
||||
/* Can't support USB host or device features if USB OTG FS is not enabled */
|
||||
|
||||
#ifndef CONFIG_STM32L4_OTGFS
|
||||
# undef HAVE_USBDEV
|
||||
# undef HAVE_USBHOST
|
||||
# undef HAVE_USBMONITOR
|
||||
#endif
|
||||
|
||||
/* Can't support USB device monitor if USB device is not enabled */
|
||||
|
||||
#ifndef CONFIG_USBDEV
|
||||
# undef HAVE_USBDEV
|
||||
# undef HAVE_USBMONITOR
|
||||
#endif
|
||||
|
||||
/* Can't support USB host is USB host is not enabled */
|
||||
|
||||
#ifndef CONFIG_USBHOST
|
||||
# undef HAVE_USBHOST
|
||||
#endif
|
||||
|
||||
/* Check if we should enable the USB monitor before starting NSH */
|
||||
|
||||
#if !defined(CONFIG_USBDEV_TRACE) || !defined(CONFIG_SYSTEM_USBMONITOR)
|
||||
# undef HAVE_USBMONITOR
|
||||
#endif
|
||||
|
||||
/* USB OTG FS
|
||||
*
|
||||
* PC11 OTG_FS_VBUS VBUS sensing (also connected to the green LED)
|
||||
* PC9 OTG_FS_PowerSwitchOn
|
||||
* PC10 OTG_FS_Overcurrent
|
||||
*/
|
||||
|
||||
#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
|
||||
GPIO_OPENDRAIN|GPIO_PORTC|GPIO_PIN11)
|
||||
#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
|
||||
GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN9)
|
||||
|
||||
#ifdef CONFIG_USBHOST
|
||||
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|\
|
||||
GPIO_SPEED_100MHz|GPIO_PUSHPULL|\
|
||||
GPIO_PORTC|GPIO_PIN10)
|
||||
|
||||
#else
|
||||
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
|
||||
GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN10)
|
||||
#endif
|
||||
|
||||
/* LED.
|
||||
* LD4: the red LED on PB2
|
||||
* LD5: the green LED on PE8
|
||||
@@ -211,14 +263,14 @@ extern struct spi_dev_s *g_spi2;
|
||||
void stm32_spiinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: stm32_usbinitialize
|
||||
* Name: stm32l4_usbinitialize
|
||||
*
|
||||
* Description:
|
||||
* Called to setup USB-related GPIO pins.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
void stm32_usbinitialize(void);
|
||||
void stm32l4_usbinitialize(void);
|
||||
|
||||
/************************************************************************************
|
||||
* Name: board_adc_initialize
|
||||
|
||||
Reference in New Issue
Block a user