From b15d126d594630e8ad75780f54a9218ccb5ad7b9 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 24 Apr 2021 13:36:05 +0700 Subject: [PATCH] lpc55 improve multiple controller support port1 highspeed requires USB_RAM --- hw/bsp/lpc55/family.mk | 6 ++++-- src/device/usbd.c | 4 +++- src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 17 +++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/bsp/lpc55/family.mk b/hw/bsp/lpc55/family.mk index c8874f571..46923cc4f 100644 --- a/hw/bsp/lpc55/family.mk +++ b/hw/bsp/lpc55/family.mk @@ -14,13 +14,15 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv5-sp-d16 \ -DCFG_TUSB_MCU=OPT_MCU_LPC55XX \ - -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data")))' \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' \ -DBOARD_DEVICE_RHPORT_NUM=$(PORT) ifeq ($(PORT), 1) - CFLAGS += -DBOARD_DEVICE_RHPORT_SPEED=OPT_MODE_HIGH_SPEED $(info "PORT1 High Speed") + CFLAGS += -DBOARD_DEVICE_RHPORT_SPEED=OPT_MODE_HIGH_SPEED + + # LPC55 Highspeed Port1 can only write to USB_SRAM region + CFLAGS += -DCFG_TUSB_MEM_SECTION='__attribute__((section("m_usb_global")))' else $(info "PORT0 Full Speed") endif diff --git a/src/device/usbd.c b/src/device/usbd.c index 8a3d8ec2f..2853b619b 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -302,6 +302,8 @@ static char const* const _tusb_std_request_str[] = "Synch Frame" }; +static char const* const _tusb_speed_str[] = { "Full", "Low", "High" }; + // for usbd_control to print the name of control complete driver void usbd_driver_print_control_complete_name(usbd_control_xfer_cb_t callback) { @@ -464,7 +466,7 @@ void tud_task (void) switch ( event.event_id ) { case DCD_EVENT_BUS_RESET: - TU_LOG2("\r\n"); + TU_LOG2(": %s Speed\r\n", _tusb_speed_str[event.bus_reset.speed]); usbd_reset(event.rhport); _usbd_dev.speed = event.bus_reset.speed; break; diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index 090d9e602..d7efd8066 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -56,11 +56,6 @@ #include "device/dcd.h" -// only SRAM1 & USB RAM can be used for transfer. -// Used to set DATABUFSTART which is 22-bit aligned -// 2000 0000 to 203F FFFF -#define SRAM_REGION 0x20000000 - //--------------------------------------------------------------------+ // IP3511 Registers //--------------------------------------------------------------------+ @@ -161,6 +156,9 @@ typedef struct }dcd_data_t; // EP list must be 256-byte aligned +// Some MCU controller may require this variable to be placed in specific SRAM region. +// For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000) +// Use CFG_TUSB_MEM_SECTION to place it accordingly. CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd; //--------------------------------------------------------------------+ @@ -179,7 +177,7 @@ typedef struct static const dcd_controller_t _dcd_controller[] = { { .regs = (dcd_registers_t*) USB0_BASE , .max_speed = TUSB_SPEED_FULL, .irqnum = USB0_IRQn, .ep_pairs = FSL_FEATURE_USB_EP_NUM }, - #if FSL_FEATURE_SOC_USBHSD_COUNT + #if defined(FSL_FEATURE_SOC_USBHSD_COUNT) && FSL_FEATURE_SOC_USBHSD_COUNT { .regs = (dcd_registers_t*) USBHSD_BASE, .max_speed = TUSB_SPEED_HIGH, .irqnum = USB1_IRQn, .ep_pairs = FSL_FEATURE_USBHSD_EP_NUM } #endif }; @@ -203,9 +201,9 @@ static inline uint16_t get_buf_offset(void const * buffer) return ( (addr >> 6) & 0xFFFFUL ) ; } -static inline uint8_t ep_addr2id(uint8_t endpoint_addr) +static inline uint8_t ep_addr2id(uint8_t ep_addr) { - return 2*(endpoint_addr & 0x0F) + ((endpoint_addr & TUSB_DIR_IN_MASK) ? 1 : 0); + return 2*(ep_addr & 0x0F) + ((ep_addr & TUSB_DIR_IN_MASK) ? 1 : 0); } //--------------------------------------------------------------------+ @@ -216,8 +214,7 @@ void dcd_init(uint8_t rhport) dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs; dcd_reg->EPLISTSTART = (uint32_t) _dcd.ep; - dcd_reg->DATABUFSTART = SRAM_REGION; // 22-bit alignment - + dcd_reg->DATABUFSTART = tu_align((uint32_t) &_dcd, 22); // 22-bit alignment dcd_reg->INTSTAT = dcd_reg->INTSTAT; // clear all pending interrupt dcd_reg->INTEN = INT_DEVICE_STATUS_MASK; dcd_reg->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK |