Add USB Device support for i.MX RT (#408)

* arch/arm/src/imxrt/imxrt_usbdev.c: Add USB Device support for i.MX RT (USB OTG1)

Based on the LPC43xx USB Device driver.

* imxrt:usbotg Nxstyle fixes

Co-authored-by: thomasactia <61285689+thomasactia@users.noreply.github.com>
This commit is contained in:
David Sidrane 2020-02-29 14:03:52 -08:00 committed by GitHub
parent 41ef33bded
commit 4a4b2853c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3184 additions and 21 deletions

View File

@ -192,6 +192,10 @@ config IMXRT_USBOTG
select USBHOST_HAVE_ASYNCH if USBHOST
select USBHOST_ASYNCH
config IMXRT_USBDEV
bool "USB Device"
default n
config IMXRT_ENET
bool "Ethernet"
default n
@ -1527,4 +1531,31 @@ config IMXRT_EHCI_PREALLOCATE
endmenu # USB host controller driver (HCD) options
endif # IMXRT_USBOTG && USBHOST
if IMXRT_USBDEV
menu "USB device controller driver (DCD) options"
config IMXRT_USBDEV_NOVBUS
bool "No USB VBUS sensing"
default n
config IMXRT_USBDEV_FRAME_INTERRUPT
bool "USB frame interrupt"
default n
---help---
Handle USB Start-Of-Frame events. Enable reading SOF from interrupt
handler vs. simply reading on demand. Probably a bad idea... Unless
there is some issue with sampling the SOF from hardware asynchronously.
config IMXRT_USBDEV_REGDEBUG
bool "Register level debug"
depends on DEBUG_USB_INFO
default n
---help---
Output detailed register-level USB device debug information. Requires
also CONFIG_DEBUG_USB_INFO.
endmenu # USB device controller driver (DCD) options
endif # IMXRT_USBDEV
endif # ARCH_CHIP_IMXRT

View File

@ -164,3 +164,7 @@ endif
ifeq ($(CONFIG_IMXRT_USBOTG),y)
CHIP_CSRCS += imxrt_ehci.c
endif
ifeq ($(CONFIG_IMXRT_USBDEV),y)
CHIP_CSRCS += imxrt_usbdev.c
endif

View File

@ -1,4 +1,4 @@
/***************************************************************************
/********************************************************************************************
* arch/arm/src/imxrt/hardware/imxrt_usbotg.h
*
* Copyright (C) 2009-2011, 2019 Gregory Nutt. All rights reserved.
@ -32,24 +32,24 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/
********************************************************************************************/
#ifndef __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USBOTG_H
#define __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USBOTG_H
/***************************************************************************
/********************************************************************************************
* Included Files
***************************************************************************/
********************************************************************************************/
#include <nuttx/config.h>
/***************************************************************************
/********************************************************************************************
* Pre-processor Definitions
***************************************************************************/
********************************************************************************************/
#define IMXRT_EHCI_NRHPORT 1 /* There is only a single root hub port */
/* USBOTG register offsets (with respect to IMXRT_USB_BASE) *************************************/
/* USBOTG register offsets (with respect to IMXRT_USB_BASE) *********************************/
/* 0x000 - 0x0ff: Reserved */
@ -119,6 +119,8 @@
#define IMXRT_USBDEV_ENDPTFLUSH_OFFSET 0x1b4 /* Endpoint de-initialization */
#define IMXRT_USBDEV_ENDPTSTATUS_OFFSET 0x1b8 /* Endpoint status */
#define IMXRT_USBDEV_ENDPTCOMPLETE_OFFSET 0x1bc /* Endpoint complete */
#define IMXRT_USBDEV_ENDPTCTRL_OFFSET(n) (IMXRT_USBDEV_ENDPTCTRL0_OFFSET + ((n) * 4))
#define IMXRT_USBDEV_ENDPTCTRL0_OFFSET 0x1c0 /* Endpoint control 0 */
#define IMXRT_USBDEV_ENDPTCTRL1_OFFSET 0x1c4 /* Endpoint control 1 */
#define IMXRT_USBDEV_ENDPTCTRL2_OFFSET 0x1c8 /* Endpoint control 2 */
@ -133,7 +135,7 @@
#define IMXRT_USBNC_USB_OTG1_CTRL_OFFSET 0x0800 /* OTG1 Control Register */
#define IMXRT_USBNC_USB_OTG1_PHY_CTRL_0_OFFSET 0x0818 /* OTG1 Phy Control Register */
/* USBOTG register (virtual) addresses **********************************************************/
/* USBOTG register (virtual) addresses ******************************************************/
/* Device/host capability registers */
@ -199,6 +201,8 @@
#define IMXRT_USBDEV_ENDPTFLUSH (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTFLUSH_OFFSET)
#define IMXRT_USBDEV_ENDPTSTATUS (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTSTATUS_OFFSET)
#define IMXRT_USBDEV_ENDPTCOMPLETE (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTCOMPLETE_OFFSET)
#define IMXRT_USBDEV_ENDPTCTRL(n) (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTCTRL_OFFSET(n))
#define IMXRT_USBDEV_ENDPTCTRL0 (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTCTRL0_OFFSET)
#define IMXRT_USBDEV_ENDPTCTRL1 (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTCTRL1_OFFSET)
#define IMXRT_USBDEV_ENDPTCTRL2 (IMXRT_USB_BASE + IMXRT_USBDEV_ENDPTCTRL2_OFFSET)
@ -213,7 +217,7 @@
#define IMXRT_USBNC_USB_OTG1_CTRL (IMXRT_USB_BASE + IMXRT_USBNC_USB_OTG1_CTRL_OFFSET)
#define IMXRT_USBNC_USB_OTG1_PHY_CTRL_0 (IMXRT_USB_BASE + IMXRT_USBNC_USB_OTG1_PHY_CTRL_0_OFFSET)
/* USBOTG register bit definitions ******************************************/
/* USBOTG register bit definitions **********************************************************/
/* Device/host capability registers */
@ -726,16 +730,4 @@
/* Bit 30: Reserved */
#define USBNC_WIR (1 << 31) /* Bit 31: Wake up interrupt request */
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USBOTG_H */

View File

@ -0,0 +1,69 @@
/****************************************************************************
* arch/arm/src/imxrt/hardware/imxrt_usb_phy.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USB_PHY_H
#define __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USB_PHY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "hardware/imxrt_memorymap.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define IMXRT_USBPHY_BASE_OFFSET 0x1000 /* USB PHY Base */
#define IMXRT_USBPHY_BASE (IMXRT_ANATOP_BASE + IMXRT_USBPHY_BASE_OFFSET) /* USB PHY Base */
/* Register Offsets *********************************************************/
#define IMXRT_USBPHY1_PWD_OFFSET 0x0000 /* USBPHY1 USB PHY Power-Down Register */
#define IMXRT_USBPHY1_PWD_CLR_OFFSET 0x0008 /* USBPHY1 USB PHY Power-Down Register Clear */
#define IMXRT_USBPHY1_CTRL_OFFSET 0x0030 /* USBPHY1 USB PHY General Control Register */
#define IMXRT_USBPHY1_CTRL_CLR_OFFSET 0x0038 /* USBPHY1 USB PHY General Control Register Clear */
/* Register addresses *******************************************************/
#define IMXRT_USBPHY1_PWD (IMXRT_USBPHY_BASE + IMXRT_USBPHY1_PWD_OFFSET) /* USBPHY1 USB PHY Power-Down Register */
#define IMXRT_USBPHY1_PWD_CLR (IMXRT_USBPHY_BASE + IMXRT_USBPHY1_PWD_CLR_OFFSET) /* USBPHY1 USB PHY Power-Down Register Clear */
#define IMXRT_USBPHY1_CTRL (IMXRT_USBPHY_BASE + IMXRT_USBPHY1_CTRL_OFFSET) /* USBPHY1 USB PHY General Control Register */
#define IMXRT_USBPHY1_CTRL_CLR (IMXRT_USBPHY_BASE + IMXRT_USBPHY1_CTRL_CLR_OFFSET) /* USBPHY1 USB PHY General Control Register Clear */
/* Register Bit Definitions *************************************************/
/* USB PHY Power-Down Register */
#define USBPHY_PWD_RXPWDRX (1 << 20) /* Bit 20: Power-down the entire USB PHY receiver block except for the full-speed differential receiver. */
#define USBPHY_PWD_RXPWDDIFF (1 << 19) /* Bit 19: Power-down the USB high-speed differential receiver. */
#define USBPHY_PWD_RXPWD1PT1 (1 << 18) /* Bit 18: Power-down the USB full-speed differential receiver. */
#define USBPHY_PWD_RXPWDENV (1 << 17) /* Bit 17: Power-down the USB high-speed receiver envelope detector (squelch signal). */
#define USBPHY_PWD_TXPWDV2I (1 << 12) /* Bit 12: Power-down the USB PHY transmit V-to-I converter and the current mirror. */
#define USBPHY_PWD_TXPWDIBIAS (1 << 11) /* Bit 11: Power-down the USB PHY current bias block for the transmitter. */
#define USBPHY_PWD_TXPWDFS (1 << 10) /* Bit 10: Power-down the USB full-speed drivers. */
/* USB PHY General Control Register */
#define USBPHY_CTRL_SFTRST (1 << 31) /* Bit 31: Soft-reset */
#define USBPHY_CTRL_CLKGATE (1 << 30) /* Bit 30: Gate UTMI clocks */
#endif /* __ARCH_ARM_SRC_IMXRT_HARDWARE_IMXRT_USB_PHY_H */

File diff suppressed because it is too large Load Diff

View File

@ -58,6 +58,10 @@
# include <nuttx/usb/usbmonitor.h>
#endif
#ifdef CONFIG_PL2303
# include <nuttx/usb/pl2303.h>
#endif
#include "imxrt1060-evk.h"
#include <arch/board/board.h> /* Must always be included last */
@ -244,6 +248,10 @@ int imxrt_bringup(void)
}
#endif
#ifdef CONFIG_PL2303
usbdev_serialinitialize(0);
#endif
UNUSED(ret);
return OK;
}