From 7fd68efe7b0d1fe95834828f08014ec97f1e005a Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 3 Oct 2019 13:37:10 +0700 Subject: couldn't get 32L4 running with crystal less mode --- src/device/dcd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/device/dcd.h b/src/device/dcd.h index 168eb181c..bef062fb1 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -42,7 +42,7 @@ typedef enum DCD_EVENT_BUS_RESET = 1, DCD_EVENT_UNPLUGGED, DCD_EVENT_SOF, - DCD_EVENT_SUSPEND, + DCD_EVENT_SUSPEND, // TODO LPM Sleep L1 support DCD_EVENT_RESUME, DCD_EVENT_SETUP_RECEIVED, -- cgit v1.3.1 From 13d37e4a36386cadc4db29b005f33b48d68564b4 Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 3 Oct 2019 15:23:01 +0700 Subject: lpcxpresso1549 board test running --- hw/bsp/lpcxpresso1549/board.mk | 47 +++++++ hw/bsp/lpcxpresso1549/lpc1549.ld | 246 +++++++++++++++++++++++++++++++++ hw/bsp/lpcxpresso1549/lpcxpresso1549.c | 128 +++++++++++++++++ src/tusb_option.h | 3 +- 4 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 hw/bsp/lpcxpresso1549/board.mk create mode 100644 hw/bsp/lpcxpresso1549/lpc1549.ld create mode 100644 hw/bsp/lpcxpresso1549/lpcxpresso1549.c (limited to 'src') diff --git a/hw/bsp/lpcxpresso1549/board.mk b/hw/bsp/lpcxpresso1549/board.mk new file mode 100644 index 000000000..682674822 --- /dev/null +++ b/hw/bsp/lpcxpresso1549/board.mk @@ -0,0 +1,47 @@ +CFLAGS += \ + -mthumb \ + -mabi=aapcs \ + -mcpu=cortex-m3 \ + -nostdlib \ + -DCORE_M3 \ + -D__USE_LPCOPEN \ + -DCFG_TUSB_MCU=OPT_MCU_LPC15XX \ + -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' + +# -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM3")))' \ +# -DCFG_EXAMPLE_MSC_READONLY \ + +# startup.c and lpc_types.h cause following errors +CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter -Wno-error=unused-variable + +MCU_DIR = hw/mcu/nxp/lpc_driver/lpc15xx/lpc_chip_15xx + +# All source paths should be relative to the top level. +LD_FILE = hw/bsp/$(BOARD)/lpc1549.ld + +SRC_C += \ + $(MCU_DIR)/../gcc/cr_startup_lpc15xx.c \ + $(MCU_DIR)/src/chip_15xx.c \ + $(MCU_DIR)/src/clock_15xx.c \ + $(MCU_DIR)/src/gpio_15xx.c \ + $(MCU_DIR)/src/iocon_15xx.c \ + $(MCU_DIR)/src/swm_15xx.c \ + $(MCU_DIR)/src/sysctl_15xx.c \ + $(MCU_DIR)/src/sysinit_15xx.c + +INC += \ + $(TOP)/$(MCU_DIR)/inc + +# For TinyUSB port source +VENDOR = nxp +CHIP_FAMILY = lpc_ip3511 + +# For freeRTOS port source +FREERTOS_PORT = ARM_CM3 + +# For flash-jlink target +JLINK_DEVICE = LPC1549 +JLINK_IF = swd + +# flash using jlink +flash: flash-jlink diff --git a/hw/bsp/lpcxpresso1549/lpc1549.ld b/hw/bsp/lpcxpresso1549/lpc1549.ld new file mode 100644 index 000000000..6dd12ade1 --- /dev/null +++ b/hw/bsp/lpcxpresso1549/lpc1549.ld @@ -0,0 +1,246 @@ +/* + * GENERATED FILE - DO NOT EDIT + * Copyright (c) 2008-2013 Code Red Technologies Ltd, + * Copyright 2015, 2018-2019 NXP + * (c) NXP Semiconductors 2013-2019 + * Generated linker script file for LPC1549 + * Created from linkscript.ldt by FMCreateLinkLibraries + * Using Freemarker v2.3.23 + * MCUXpresso IDE v11.0.0 [Build 2516] [2019-06-05] on Oct 3, 2019 2:55:18 PM + */ + + +MEMORY +{ + /* Define each memory region */ + MFlash256 (rx) : ORIGIN = 0x0, LENGTH = 0x40000 /* 256K bytes (alias Flash) */ + Ram0_16 (rwx) : ORIGIN = 0x2000000, LENGTH = 0x4000 /* 16K bytes (alias RAM) */ + Ram1_16 (rwx) : ORIGIN = 0x2004000, LENGTH = 0x4000 /* 16K bytes (alias RAM2) */ + Ram2_4 (rwx) : ORIGIN = 0x2008000, LENGTH = 0x1000 /* 4K bytes (alias RAM3) */ +} + + /* Define a symbol for the top of each memory region */ + __base_MFlash256 = 0x0 ; /* MFlash256 */ + __base_Flash = 0x0 ; /* Flash */ + __top_MFlash256 = 0x0 + 0x40000 ; /* 256K bytes */ + __top_Flash = 0x0 + 0x40000 ; /* 256K bytes */ + __base_Ram0_16 = 0x2000000 ; /* Ram0_16 */ + __base_RAM = 0x2000000 ; /* RAM */ + __top_Ram0_16 = 0x2000000 + 0x4000 ; /* 16K bytes */ + __top_RAM = 0x2000000 + 0x4000 ; /* 16K bytes */ + __base_Ram1_16 = 0x2004000 ; /* Ram1_16 */ + __base_RAM2 = 0x2004000 ; /* RAM2 */ + __top_Ram1_16 = 0x2004000 + 0x4000 ; /* 16K bytes */ + __top_RAM2 = 0x2004000 + 0x4000 ; /* 16K bytes */ + __base_Ram2_4 = 0x2008000 ; /* Ram2_4 */ + __base_RAM3 = 0x2008000 ; /* RAM3 */ + __top_Ram2_4 = 0x2008000 + 0x1000 ; /* 4K bytes */ + __top_RAM3 = 0x2008000 + 0x1000 ; /* 4K bytes */ + +ENTRY(ResetISR) + +SECTIONS +{ + /* MAIN TEXT SECTION */ + .text : ALIGN(4) + { + FILL(0xff) + __vectors_start__ = ABSOLUTE(.) ; + KEEP(*(.isr_vector)) + /* Global Section Table */ + . = ALIGN(4) ; + __section_table_start = .; + __data_section_table = .; + LONG(LOADADDR(.data)); + LONG( ADDR(.data)); + LONG( SIZEOF(.data)); + LONG(LOADADDR(.data_RAM2)); + LONG( ADDR(.data_RAM2)); + LONG( SIZEOF(.data_RAM2)); + LONG(LOADADDR(.data_RAM3)); + LONG( ADDR(.data_RAM3)); + LONG( SIZEOF(.data_RAM3)); + __data_section_table_end = .; + __bss_section_table = .; + LONG( ADDR(.bss)); + LONG( SIZEOF(.bss)); + LONG( ADDR(.bss_RAM2)); + LONG( SIZEOF(.bss_RAM2)); + LONG( ADDR(.bss_RAM3)); + LONG( SIZEOF(.bss_RAM3)); + __bss_section_table_end = .; + __section_table_end = . ; + /* End of Global Section Table */ + + *(.after_vectors*) + + } > MFlash256 + + .text : ALIGN(4) + { + *(.text*) + *(.rodata .rodata.* .constdata .constdata.*) + . = ALIGN(4); + } > MFlash256 + /* + * for exception handling/unwind - some Newlib functions (in common + * with C++ and STDC++) use this. + */ + .ARM.extab : ALIGN(4) + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > MFlash256 + + __exidx_start = .; + + .ARM.exidx : ALIGN(4) + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > MFlash256 + __exidx_end = .; + + _etext = .; + + /* DATA section for Ram1_16 */ + + .data_RAM2 : ALIGN(4) + { + FILL(0xff) + PROVIDE(__start_data_RAM2 = .) ; + *(.ramfunc.$RAM2) + *(.ramfunc.$Ram1_16) + *(.data.$RAM2) + *(.data.$Ram1_16) + *(.data.$RAM2.*) + *(.data.$Ram1_16.*) + . = ALIGN(4) ; + PROVIDE(__end_data_RAM2 = .) ; + } > Ram1_16 AT>MFlash256 + /* DATA section for Ram2_4 */ + + .data_RAM3 : ALIGN(4) + { + FILL(0xff) + PROVIDE(__start_data_RAM3 = .) ; + *(.ramfunc.$RAM3) + *(.ramfunc.$Ram2_4) + *(.data.$RAM3) + *(.data.$Ram2_4) + *(.data.$RAM3.*) + *(.data.$Ram2_4.*) + . = ALIGN(4) ; + PROVIDE(__end_data_RAM3 = .) ; + } > Ram2_4 AT>MFlash256 + /* MAIN DATA SECTION */ + .uninit_RESERVED (NOLOAD) : + { + . = ALIGN(4) ; + KEEP(*(.bss.$RESERVED*)) + . = ALIGN(4) ; + _end_uninit_RESERVED = .; + } > Ram0_16 + + /* Main DATA section (Ram0_16) */ + .data : ALIGN(4) + { + FILL(0xff) + _data = . ; + *(vtable) + *(.ramfunc*) + *(.data*) + . = ALIGN(4) ; + _edata = . ; + } > Ram0_16 AT>MFlash256 + + /* BSS section for Ram1_16 */ + .bss_RAM2 : + { + . = ALIGN(4) ; + PROVIDE(__start_bss_RAM2 = .) ; + *(.bss.$RAM2) + *(.bss.$Ram1_16) + *(.bss.$RAM2.*) + *(.bss.$Ram1_16.*) + . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ + PROVIDE(__end_bss_RAM2 = .) ; + } > Ram1_16 + + /* BSS section for Ram2_4 */ + .bss_RAM3 : + { + . = ALIGN(4) ; + PROVIDE(__start_bss_RAM3 = .) ; + *(.bss.$RAM3) + *(.bss.$Ram2_4) + *(.bss.$RAM3.*) + *(.bss.$Ram2_4.*) + . = ALIGN (. != 0 ? 4 : 1) ; /* avoid empty segment */ + PROVIDE(__end_bss_RAM3 = .) ; + } > Ram2_4 + + /* MAIN BSS SECTION */ + .bss : + { + . = ALIGN(4) ; + _bss = .; + *(.bss*) + *(COMMON) + . = ALIGN(4) ; + _ebss = .; + PROVIDE(end = .); + } > Ram0_16 + + /* NOINIT section for Ram1_16 */ + .noinit_RAM2 (NOLOAD) : + { + . = ALIGN(4) ; + *(.noinit.$RAM2) + *(.noinit.$Ram1_16) + *(.noinit.$RAM2.*) + *(.noinit.$Ram1_16.*) + . = ALIGN(4) ; + } > Ram1_16 + + /* NOINIT section for Ram2_4 */ + .noinit_RAM3 (NOLOAD) : + { + . = ALIGN(4) ; + *(.noinit.$RAM3) + *(.noinit.$Ram2_4) + *(.noinit.$RAM3.*) + *(.noinit.$Ram2_4.*) + . = ALIGN(4) ; + } > Ram2_4 + + /* DEFAULT NOINIT SECTION */ + .noinit (NOLOAD): + { + . = ALIGN(4) ; + _noinit = .; + *(.noinit*) + . = ALIGN(4) ; + _end_noinit = .; + } > Ram0_16 + PROVIDE(_pvHeapStart = DEFINED(__user_heap_base) ? __user_heap_base : .); + PROVIDE(_vStackTop = DEFINED(__user_stack_top) ? __user_stack_top : __top_Ram0_16 - 0); + + /* ## Create checksum value (used in startup) ## */ + PROVIDE(__valid_user_code_checksum = 0 - + (_vStackTop + + (ResetISR + 1) + + (NMI_Handler + 1) + + (HardFault_Handler + 1) + + (( DEFINED(MemManage_Handler) ? MemManage_Handler : 0 ) + 1) /* MemManage_Handler may not be defined */ + + (( DEFINED(BusFault_Handler) ? BusFault_Handler : 0 ) + 1) /* BusFault_Handler may not be defined */ + + (( DEFINED(UsageFault_Handler) ? UsageFault_Handler : 0 ) + 1) /* UsageFault_Handler may not be defined */ + ) ); + + /* Provide basic symbols giving location and size of main text + * block, including initial values of RW data sections. Note that + * these will need extending to give a complete picture with + * complex images (e.g multiple Flash banks). + */ + _image_start = LOADADDR(.text); + _image_end = LOADADDR(.data) + SIZEOF(.data); + _image_size = _image_end - _image_start; +} \ No newline at end of file diff --git a/hw/bsp/lpcxpresso1549/lpcxpresso1549.c b/hw/bsp/lpcxpresso1549/lpcxpresso1549.c new file mode 100644 index 000000000..8e178eb76 --- /dev/null +++ b/hw/bsp/lpcxpresso1549/lpcxpresso1549.c @@ -0,0 +1,128 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include "chip.h" +#include "../board.h" + +#define LED_PORT 0 +#define LED_PIN 25 + +// Wake Switch +#define BUTTON_PORT 0 +#define BUTTON_PIN 17 + +/* System oscillator rate and RTC oscillator rate */ +const uint32_t OscRateIn = 12000000; +const uint32_t RTCOscRateIn = 32768; + +/* Pin muxing table, only items that need changing from their default pin + state are in this table. */ +static const PINMUX_GRP_T pinmuxing[] = +{ + {1, 11, (IOCON_MODE_PULLDOWN | IOCON_DIGMODE_EN)}, /* PIO0_3 used for USB_VBUS */ +}; + +// Invoked by startup code +void SystemInit(void) +{ + Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); + Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); + Chip_SYSCTL_PeriphReset(RESET_IOCON); + + // Pin Mux + Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); + + // SWM USB + Chip_SWM_MovablePortPinAssign(SWM_USB_VBUS_I, 1, 11); + + Chip_SetupXtalClocking(); +} + +void board_init(void) +{ + SystemCoreClockUpdate(); + +#if CFG_TUSB_OS == OPT_OS_NONE + // 1ms tick timer + SysTick_Config(SystemCoreClock / 1000); +#elif CFG_TUSB_OS == OPT_OS_FREERTOS + // If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher ) + NVIC_SetPriority(USB0_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY ); +#endif + + Chip_GPIO_Init(LPC_GPIO); + + // LED + Chip_GPIO_SetPinDIROutput(LPC_GPIO, LED_PORT, LED_PIN); + + // Button + Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_PORT, BUTTON_PIN); + + // USB: Setup PLL clock, and power + Chip_USB_Init(); +} + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +#if CFG_TUSB_OS == OPT_OS_NONE +volatile uint32_t system_ticks = 0; +void SysTick_Handler (void) +{ + system_ticks++; +} + +uint32_t board_millis(void) +{ + return system_ticks; +} +#endif + +void board_led_write(bool state) +{ + Chip_GPIO_SetPinState(LPC_GPIO, LED_PORT, LED_PIN, state); +} + +uint32_t board_button_read(void) +{ + // active low + return Chip_GPIO_GetPinState(LPC_GPIO, BUTTON_PORT, BUTTON_PIN) ? 0 : 1; +} + +int board_uart_read(uint8_t* buf, int len) +{ + (void) buf; + (void) len; + return 0; +} + +int board_uart_write(void const * buf, int len) +{ + (void) buf; + (void) len; + return 0; +} diff --git a/src/tusb_option.h b/src/tusb_option.h index 76ea59758..d0cc0be6a 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -38,7 +38,8 @@ // LPC #define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx -#define OPT_MCU_LPC13XX 3 ///< NXP LPC13xx +#define OPT_MCU_LPC13XX 2 ///< NXP LPC13xx +#define OPT_MCU_LPC15xx 3 ///< NXP LPC15xx #define OPT_MCU_LPC175X_6X 4 ///< NXP LPC175x, LPC176x #define OPT_MCU_LPC177X_8X 5 ///< NXP LPC177x, LPC178x #define OPT_MCU_LPC18XX 6 ///< NXP LPC18xx -- cgit v1.3.1 From 281cd858b067a240478490af6d302f7881b3aaf7 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 4 Oct 2019 13:13:51 +0700 Subject: adding lpc1549, but couldnt recieve setup packet, though setup received interrupt is triggered --- .../device/cdc_msc/ses/lpc13xx/lpc13xx.emProject | 2 +- hw/bsp/lpcxpresso11u37/lpcxpresso11u37.c | 4 --- hw/bsp/lpcxpresso1347/board.mk | 2 +- hw/bsp/lpcxpresso1549/board.mk | 6 ++-- hw/bsp/lpcxpresso1549/lpcxpresso1549.c | 14 ++++---- src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c | 38 +++++++++++++--------- src/tusb_option.h | 2 +- 7 files changed, 34 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/examples/device/cdc_msc/ses/lpc13xx/lpc13xx.emProject b/examples/device/cdc_msc/ses/lpc13xx/lpc13xx.emProject index d07cc68ff..f25307dda 100644 --- a/examples/device/cdc_msc/ses/lpc13xx/lpc13xx.emProject +++ b/examples/device/cdc_msc/ses/lpc13xx/lpc13xx.emProject @@ -19,7 +19,7 @@ arm_target_interface_type="SWD" build_treat_warnings_as_errors="Yes" c_preprocessor_definitions="__LPC1347FBD64__;__LPC1300_FAMILY;__LPC134x_SUBFAMILY;ARM_MATH_CM3;FLASH_PLACEMENT=1;CORE_M3;CFG_TUSB_MCU=OPT_MCU_LPC13XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss3")));CFG_TUSB_MEM_ALIGN=__attribute__ ((aligned(64)))" - c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc_chip_13xx/inc;$(rootDir)/src" + c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/hw/mcu/nxp/lpc_driver/lpc13xx/lpc_chip_13xx/inc;$(rootDir)/src" debug_register_definition_file="$(ProjectDir)/LPC13Uxx_Registers.xml" debug_target_connection="J-Link" gcc_enable_all_warnings="Yes" diff --git a/hw/bsp/lpcxpresso11u37/lpcxpresso11u37.c b/hw/bsp/lpcxpresso11u37/lpcxpresso11u37.c index ce093ed29..f7fc16ec2 100644 --- a/hw/bsp/lpcxpresso11u37/lpcxpresso11u37.c +++ b/hw/bsp/lpcxpresso11u37/lpcxpresso11u37.c @@ -58,8 +58,6 @@ static const PINMUX_GRP_T pinmuxing[] = {0, 19, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_DIGMODE_EN)}, // UART0 TX }; - -#if 1 /* Setup system clocking */ static void SystemSetupClocking(void) { @@ -114,13 +112,11 @@ static void SystemSetupClocking(void) /* Wait for PLL to lock */ while (!Chip_Clock_IsUSBPLLLocked()) {} } -#endif // Invoked by startup code void SystemInit(void) { SystemSetupClocking(); -// Chip_SystemInit(); Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_RAM1); /* Enable IOCON clock */ diff --git a/hw/bsp/lpcxpresso1347/board.mk b/hw/bsp/lpcxpresso1347/board.mk index 4e0c70392..0f9be1b56 100644 --- a/hw/bsp/lpcxpresso1347/board.mk +++ b/hw/bsp/lpcxpresso1347/board.mk @@ -7,7 +7,7 @@ CFLAGS += \ -D__USE_LPCOPEN \ -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_LPC13XX \ - -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM3")))' \ + -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM2")))' \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' # startup.c and lpc_types.h cause following errors diff --git a/hw/bsp/lpcxpresso1549/board.mk b/hw/bsp/lpcxpresso1549/board.mk index 682674822..929c63a8d 100644 --- a/hw/bsp/lpcxpresso1549/board.mk +++ b/hw/bsp/lpcxpresso1549/board.mk @@ -5,13 +5,11 @@ CFLAGS += \ -nostdlib \ -DCORE_M3 \ -D__USE_LPCOPEN \ + -DCFG_EXAMPLE_MSC_READONLY \ -DCFG_TUSB_MCU=OPT_MCU_LPC15XX \ -DCFG_TUSB_MEM_ALIGN='__attribute__((aligned(64)))' -# -DCFG_TUSB_MEM_SECTION='__attribute__((section(".data.$$RAM3")))' \ -# -DCFG_EXAMPLE_MSC_READONLY \ - -# startup.c and lpc_types.h cause following errors +# mcu driver cause following warnings CFLAGS += -Wno-error=strict-prototypes -Wno-error=unused-parameter -Wno-error=unused-variable MCU_DIR = hw/mcu/nxp/lpc_driver/lpc15xx/lpc_chip_15xx diff --git a/hw/bsp/lpcxpresso1549/lpcxpresso1549.c b/hw/bsp/lpcxpresso1549/lpcxpresso1549.c index 8e178eb76..e10e24020 100644 --- a/hw/bsp/lpcxpresso1549/lpcxpresso1549.c +++ b/hw/bsp/lpcxpresso1549/lpcxpresso1549.c @@ -40,24 +40,21 @@ const uint32_t RTCOscRateIn = 32768; /* Pin muxing table, only items that need changing from their default pin state are in this table. */ -static const PINMUX_GRP_T pinmuxing[] = +static const PINMUX_GRP_T pinmuxing[] = { - {1, 11, (IOCON_MODE_PULLDOWN | IOCON_DIGMODE_EN)}, /* PIO0_3 used for USB_VBUS */ + {1, 11, (IOCON_MODE_PULLDOWN | IOCON_DIGMODE_EN)}, /* PIO1_11-ISP_1 (VBUS) */ }; // Invoked by startup code void SystemInit(void) { Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON); - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); - Chip_SYSCTL_PeriphReset(RESET_IOCON); + Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM); + Chip_SYSCTL_PeriphReset(RESET_IOCON); - // Pin Mux + // Pin Mux Chip_IOCON_SetPinMuxing(LPC_IOCON, pinmuxing, sizeof(pinmuxing) / sizeof(PINMUX_GRP_T)); - // SWM USB - Chip_SWM_MovablePortPinAssign(SWM_USB_VBUS_I, 1, 11); - Chip_SetupXtalClocking(); } @@ -82,6 +79,7 @@ void board_init(void) Chip_GPIO_SetPinDIRInput(LPC_GPIO, BUTTON_PORT, BUTTON_PIN); // USB: Setup PLL clock, and power + Chip_SWM_MovablePortPinAssign(SWM_USB_VBUS_I, 1, 11); Chip_USB_Init(); } diff --git a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c index 160eefb24..5b2bd83e9 100644 --- a/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c +++ b/src/portable/nxp/lpc_ip3511/dcd_lpc_ip3511.c @@ -28,9 +28,11 @@ /* Since 2012 starting with LPC11uxx, NXP start to use common USB Device Controller with code name LPC IP3511 * for almost their new MCUs. Currently supported and tested families are - * - LPC11Uxx - * - LPC13xx - * - LPC51Uxx + * - LPC11U68, LPC11U37 + * - LPC1347 + * - LPC51U68 + * - LPC54114 + * - LPC55s69 * * For similar controller of other families, this file may require some minimal changes to work with. * Previous MCUs such as LPC17xx, LPC40xx, LPC18xx, LPC43xx have their own driver implementation. @@ -38,20 +40,23 @@ #if TUSB_OPT_DEVICE_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_LPC11UXX || \ CFG_TUSB_MCU == OPT_MCU_LPC13XX || \ + CFG_TUSB_MCU == OPT_MCU_LPC15XX || \ CFG_TUSB_MCU == OPT_MCU_LPC51UXX || \ CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ CFG_TUSB_MCU == OPT_MCU_LPC55XX) -#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX - // LPC11Uxx and LPC13xx use lpcopen +#if CFG_TUSB_MCU == OPT_MCU_LPC11UXX || CFG_TUSB_MCU == OPT_MCU_LPC13XX || CFG_TUSB_MCU == OPT_MCU_LPC15XX + // LPC 11Uxx, 13xx, 15xx use lpcopen #include "chip.h" #define DCD_REGS LPC_USB #define DCD_IRQHandler USB_IRQHandler + #elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ CFG_TUSB_MCU == OPT_MCU_LPC55XX // TODO 55xx has dual usb controllers #include "fsl_device_registers.h" #define DCD_REGS USB0 #define DCD_IRQHandler USB0_IRQHandler + #endif #include "device/dcd.h" @@ -61,6 +66,9 @@ //--------------------------------------------------------------------+ // Number of endpoints +// - 11 13 15 51 54 has 5x2 endpoints +// - 18/43 usb0 & 55s usb1 (HS) has 6x2 endpoints +// - 18/43 usb1 & 55s usb0 (FS) has 4x2 endpoints #define EP_COUNT 10 // only SRAM1 & USB RAM can be used for transfer. @@ -166,7 +174,7 @@ void dcd_init(uint8_t rhport) DCD_REGS->INTSTAT = DCD_REGS->INTSTAT; // clear all pending interrupt DCD_REGS->INTEN = INT_DEVICE_STATUS_MASK; DCD_REGS->DEVCMDSTAT |= CMDSTAT_DEVICE_ENABLE_MASK | CMDSTAT_DEVICE_CONNECT_MASK | - CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; + CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; NVIC_ClearPendingIRQ(USB0_IRQn); } @@ -270,7 +278,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to prepare_ep_xfer(ep_id, get_buf_offset(buffer), total_bytes); - return true; + return true; } //--------------------------------------------------------------------+ @@ -329,7 +337,7 @@ static void process_xfer_isr(uint32_t int_status) void DCD_IRQHandler(void) { - uint32_t const dev_cmd_stat = DCD_REGS->DEVCMDSTAT; + uint32_t const cmd_stat = DCD_REGS->DEVCMDSTAT; uint32_t int_status = DCD_REGS->INTSTAT & DCD_REGS->INTEN; DCD_REGS->INTSTAT = int_status; // Acknowledge handled interrupt @@ -340,16 +348,16 @@ void DCD_IRQHandler(void) if ( int_status & INT_DEVICE_STATUS_MASK ) { DCD_REGS->DEVCMDSTAT |= CMDSTAT_RESET_CHANGE_MASK | CMDSTAT_CONNECT_CHANGE_MASK | CMDSTAT_SUSPEND_CHANGE_MASK; - if ( dev_cmd_stat & CMDSTAT_RESET_CHANGE_MASK) // bus reset + if ( cmd_stat & CMDSTAT_RESET_CHANGE_MASK) // bus reset { bus_reset(); dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); } - if (dev_cmd_stat & CMDSTAT_CONNECT_CHANGE_MASK) + if (cmd_stat & CMDSTAT_CONNECT_CHANGE_MASK) { // device disconnect - if (dev_cmd_stat & CMDSTAT_DEVICE_ADDR_MASK) + if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK) { // debouncing as this can be set when device is powering dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, true); @@ -357,12 +365,12 @@ void DCD_IRQHandler(void) } // TODO support suspend & resume - if (dev_cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK) + if (cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK) { - if (dev_cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK) + if (cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK) { // suspend signal, bus idle for more than 3ms // Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration. - if (dev_cmd_stat & CMDSTAT_DEVICE_ADDR_MASK) + if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK) { dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true); } @@ -376,7 +384,7 @@ void DCD_IRQHandler(void) } // Setup Receive - if ( tu_bit_test(int_status, 0) && (dev_cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) ) + if ( tu_bit_test(int_status, 0) && (cmd_stat & CMDSTAT_SETUP_RECEIVED_MASK) ) { // Follow UM flowchart to clear Active & Stall on both Control IN/OUT endpoints _dcd.ep[0][0].active = _dcd.ep[1][0].active = 0; diff --git a/src/tusb_option.h b/src/tusb_option.h index d0cc0be6a..a0823026d 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -39,7 +39,7 @@ // LPC #define OPT_MCU_LPC11UXX 1 ///< NXP LPC11Uxx #define OPT_MCU_LPC13XX 2 ///< NXP LPC13xx -#define OPT_MCU_LPC15xx 3 ///< NXP LPC15xx +#define OPT_MCU_LPC15XX 3 ///< NXP LPC15xx #define OPT_MCU_LPC175X_6X 4 ///< NXP LPC175x, LPC176x #define OPT_MCU_LPC177X_8X 5 ///< NXP LPC177x, LPC178x #define OPT_MCU_LPC18XX 6 ///< NXP LPC18xx -- cgit v1.3.1 From 0747c4b61bdb19f2c2e7ecf4ce7033d69487bb76 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Thu, 3 Oct 2019 14:22:43 +0200 Subject: Add Spresense board --- .gitmodules | 3 + examples/make.mk | 4 + examples/rules.mk | 6 +- hw/bsp/spresense/board.mk | 47 +++++ hw/bsp/spresense/board_spresense.c | 105 ++++++++++ hw/mcu/sony/cxd56/spresense-exported-sdk | 1 + src/portable/sony/cxd56/dcd_cxd56.c | 321 +++++++++++++++++++++++++++++++ src/tusb_option.h | 2 + 8 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 hw/bsp/spresense/board.mk create mode 100644 hw/bsp/spresense/board_spresense.c create mode 160000 hw/mcu/sony/cxd56/spresense-exported-sdk create mode 100644 src/portable/sony/cxd56/dcd_cxd56.c (limited to 'src') diff --git a/.gitmodules b/.gitmodules index f61ef719c..ad85278bf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "hw/mcu/st/st_driver"] path = hw/mcu/st/st_driver url = https://github.com/hathach/st_driver.git +[submodule "hw/mcu/sony/cxd56/spresense-exported-sdk"] + path = hw/mcu/sony/cxd56/spresense-exported-sdk + url = https://github.com/sonydevworld/spresense-exported-sdk.git diff --git a/examples/make.mk b/examples/make.mk index 22d8f7455..699cc43d6 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -80,5 +80,9 @@ CFLAGS += \ ifeq ($(DEBUG), 1) CFLAGS += -O0 -ggdb -DCFG_TUSB_DEBUG=1 else +ifneq ($(BOARD), spresense) CFLAGS += -flto -Os +else + CFLAGS += -Os +endif endif diff --git a/examples/rules.mk b/examples/rules.mk index c3daf9dac..c6997c040 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -3,7 +3,11 @@ # # libc -LIBS += -lgcc -lc -lm -lnosys +LIBS += -lgcc -lm -lnosys + +ifneq ($(BOARD), spresense) +LIBS += -lc +endif # TinyUSB Stack source SRC_C += \ diff --git a/hw/bsp/spresense/board.mk b/hw/bsp/spresense/board.mk new file mode 100644 index 000000000..16421686a --- /dev/null +++ b/hw/bsp/spresense/board.mk @@ -0,0 +1,47 @@ +SPRESENSE_SDK = $(TOP)/hw/mcu/sony/cxd56/spresense-exported-sdk + +INC += \ + $(SPRESENSE_SDK)/nuttx/include \ + $(SPRESENSE_SDK)/nuttx/arch \ + $(SPRESENSE_SDK)/nuttx/arch/chip \ + $(SPRESENSE_SDK)/sdk/bsp/include \ + $(SPRESENSE_SDK)/sdk/bsp/include/sdk \ + +CFLAGS += \ + -DCONFIG_WCHAR_BUILTIN \ + -DCONFIG_HAVE_DOUBLE \ + -Dmain=spresense_main \ + -pipe \ + -std=gnu11 \ + -mcpu=cortex-m4 \ + -mthumb \ + -mfpu=fpv4-sp-d16 \ + -mfloat-abi=hard \ + -mabi=aapcs \ + -fno-builtin \ + -fno-strength-reduce \ + -fomit-frame-pointer \ + -DCFG_TUSB_MCU=OPT_MCU_CXD56 \ + +LIBS += \ + $(SPRESENSE_SDK)/sdk/libs/libapps.a \ + $(SPRESENSE_SDK)/sdk/libs/libsdk.a \ + +LD_FILE = hw/mcu/sony/cxd56/spresense-exported-sdk/nuttx/build/ramconfig.ld + +LDFLAGS += \ + -Xlinker --entry=__start \ + -nostartfiles \ + -nodefaultlibs \ + -Wl,--defsym,__stack=_vectors+786432 \ + -Wl,--gc-sections \ + -u spresense_main \ + +# For TinyUSB port source +VENDOR = sony +CHIP_FAMILY = cxd56 + +# flash +flash: + $(SPRESENSE_SDK)/sdk/tools/linux/mkspk -c 2 $(BUILD)/spresense-firmware.elf nuttx $(BUILD)/spresense-firmware.spk + $(SPRESENSE_SDK)/sdk/tools/flash.sh -c /dev/ttyUSB0 $(BUILD)/spresense-firmware.spk diff --git a/hw/bsp/spresense/board_spresense.c b/hw/bsp/spresense/board_spresense.c new file mode 100644 index 000000000..256bccd15 --- /dev/null +++ b/hw/bsp/spresense/board_spresense.c @@ -0,0 +1,105 @@ +/* + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include +#include +#include +#include + +#include "bsp/board.h" + +/*------------------------------------------------------------------*/ +/* MACRO TYPEDEF CONSTANT ENUM + *------------------------------------------------------------------*/ +#define LED_PIN PIN_I2S1_BCK + +#define BUTTON_PIN PIN_HIF_IRQ_OUT + +// Initialize on-board peripherals : led, button, uart and USB +void board_init(void) +{ + boardctl(BOARDIOC_INIT, 0); + + board_gpio_write(PIN_I2S1_BCK, -1); + board_gpio_config(PIN_I2S1_BCK, 0, false, true, PIN_FLOAT); + + board_gpio_write(PIN_HIF_IRQ_OUT, -1); + board_gpio_config(PIN_HIF_IRQ_OUT, 0, true, true, PIN_FLOAT); +}; + +//--------------------------------------------------------------------+ +// Board porting API +//--------------------------------------------------------------------+ + +// Turn LED on or off +void board_led_write(bool state) +{ + board_gpio_write(LED_PIN, state); +} + +// Get the current state of button +// a '1' means active (pressed), a '0' means inactive. +uint32_t board_button_read(void) +{ + if (board_gpio_read(BUTTON_PIN)) + { + return 0; + } + + return 1; +} + +// Get characters from UART +int board_uart_read(uint8_t *buf, int len) +{ + int r = read(0, buf, len); + + return r; +} + +// Send characters to UART +int board_uart_write(void const *buf, int len) +{ + int r = write(1, buf, len); + + return r; +} + +// Get current milliseconds +uint32_t board_millis(void) +{ + struct timespec tp; + + /* Wait until RTC is available */ + while (g_rtc_enabled == false); + + if (clock_gettime(CLOCK_MONOTONIC, &tp)) + { + return 0; + } + + return (((uint64_t)tp.tv_sec) * 1000 + tp.tv_nsec / 1000000); +} diff --git a/hw/mcu/sony/cxd56/spresense-exported-sdk b/hw/mcu/sony/cxd56/spresense-exported-sdk new file mode 160000 index 000000000..b473b28a1 --- /dev/null +++ b/hw/mcu/sony/cxd56/spresense-exported-sdk @@ -0,0 +1 @@ +Subproject commit b473b28a14a03f3d416b6e2c071bcfd4fb92cb63 diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c new file mode 100644 index 000000000..32eb50a6f --- /dev/null +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -0,0 +1,321 @@ +/* + * The MIT License (MIT) + * + * Copyright 2019 Sony Semiconductor Solutions Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include "tusb_option.h" + +#if TUSB_OPT_DEVICE_ENABLED && CFG_TUSB_MCU == OPT_MCU_CXD56 + +#include +#include + +#include "device/dcd.h" + +#define CXD56_EPNUM (7) + +struct usbdcd_driver_s +{ + struct usbdevclass_driver_s usbdevclass_driver; + FAR struct usbdev_ep_s *ep[CXD56_EPNUM]; + FAR struct usbdev_req_s *req[CXD56_EPNUM]; +}; + +static struct usbdcd_driver_s usbdcd_driver; +static struct usbdev_s *usbdev; + +static int dcd_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +static void dcd_unbind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +static int dcd_setup(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev, + FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout, size_t outlen); +static void dcd_disconnect(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +static void dcd_suspend(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); +static void dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev); + +static const struct usbdevclass_driverops_s g_driverops = +{ + dcd_bind, /* bind */ + dcd_unbind, /* unbind */ + dcd_setup, /* setup */ + dcd_disconnect, /* disconnect */ + dcd_suspend, /* suspend */ + dcd_resume, /* resume */ +}; + +static void usbdcd_ep0incomplete(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req) +{ + (void) ep; + + uint8_t ep_addr = (uint32_t)req->priv; + + if (req->result || req->xfrd != req->len) + { + if (req->len) + { + dcd_event_xfer_complete(0, ep_addr, req->xfrd, XFER_RESULT_SUCCESS, true); + } + } + else + { + if (req->xfrd) + { + dcd_event_xfer_complete(0, ep_addr, req->xfrd, XFER_RESULT_SUCCESS, true); + } + } +} + +static int dcd_bind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) +{ + (void) driver; + + usbdev = dev; + usbdcd_driver.ep[0] = dev->ep0; + + usbdcd_driver.req[0] = EP_ALLOCREQ(usbdcd_driver.ep[0]); + if (usbdcd_driver.req[0] != NULL) + { + usbdcd_driver.req[0]->len = 64; + usbdcd_driver.req[0]->buf = EP_ALLOCBUFFER(usbdcd_driver.ep[0], 64); + if (!usbdcd_driver.req[0]->buf) + { + EP_FREEREQ(usbdcd_driver.ep[0], usbdcd_driver.req[0]); + usbdcd_driver.req[0] = NULL; + } + } + + usbdcd_driver.req[0]->callback = usbdcd_ep0incomplete; + + DEV_CONNECT(dev); + return 0; +} + +static void dcd_unbind(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) +{ + (void) driver; + (void) dev; +} + +static int dcd_setup(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev, + FAR const struct usb_ctrlreq_s *ctrl, FAR uint8_t *dataout, size_t outlen) +{ + (void) driver; + (void) dev; + (void) dataout; + (void) outlen; + + dcd_event_setup_received(0, (uint8_t *)ctrl, true); + + return 0; +} + +static void dcd_disconnect(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) +{ + (void) driver; + + dcd_event_bus_signal(0, DCD_EVENT_BUS_RESET, true); + DEV_CONNECT(dev); +} + +static void dcd_suspend(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) +{ + (void) driver; + (void) dev; +} + +static void dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) +{ + (void) driver; + (void) dev; +} + +void dcd_init(uint8_t rhport) +{ + (void) rhport; + + usbdcd_driver.usbdevclass_driver.speed = USB_SPEED_HIGH; + usbdcd_driver.usbdevclass_driver.ops = &g_driverops; + + usbdev_register(&usbdcd_driver.usbdevclass_driver); +} + +// Enable device interrupt +void dcd_int_enable(uint8_t rhport) +{ + (void) rhport; +} + +// Disable device interrupt +void dcd_int_disable(uint8_t rhport) +{ + (void) rhport; +} + +// Receive Set Address request, mcu port must also include status IN response +void dcd_set_address(uint8_t rhport, uint8_t dev_addr) +{ + (void) rhport; + (void) dev_addr; +} + +// Receive Set Config request +void dcd_set_config(uint8_t rhport, uint8_t config_num) +{ + (void) rhport; + (void) config_num; +} + +void dcd_remote_wakeup(uint8_t rhport) +{ + (void) rhport; + + DEV_WAKEUP(usbdev); +} + +//--------------------------------------------------------------------+ +// Endpoint API +//--------------------------------------------------------------------+ + +bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *p_endpoint_desc) +{ + (void) rhport; + + uint8_t epnum = tu_edpt_number(p_endpoint_desc->bEndpointAddress); + uint8_t const dir = tu_edpt_dir(p_endpoint_desc->bEndpointAddress); + uint8_t xfrtype = 0; + struct usb_epdesc_s epdesc; + + if (epnum >= CXD56_EPNUM) + { + return false; + } + + switch (p_endpoint_desc->bmAttributes.xfer) + { + case 1: + xfrtype = USB_EP_ATTR_XFER_ISOC; + break; + case 2: + xfrtype = USB_EP_ATTR_XFER_BULK; + break; + case 3: + xfrtype = USB_EP_ATTR_XFER_INT; + break; + } + + usbdcd_driver.ep[epnum] = DEV_ALLOCEP(usbdev, epnum, dir == TUSB_DIR_IN, xfrtype); + if (usbdcd_driver.ep[epnum] == NULL) + { + return false; + } + + usbdcd_driver.req[epnum] = NULL; + usbdcd_driver.req[epnum] = EP_ALLOCREQ(usbdcd_driver.ep[epnum]); + if (usbdcd_driver.req[epnum] != NULL) + { + usbdcd_driver.req[epnum]->len = p_endpoint_desc->wMaxPacketSize.size; + } + else + { + return false; + } + + usbdcd_driver.req[epnum]->callback = usbdcd_ep0incomplete; + + epdesc.len = p_endpoint_desc->bLength; + epdesc.type = p_endpoint_desc->bDescriptorType; + epdesc.addr = p_endpoint_desc->bEndpointAddress; + epdesc.attr = xfrtype; + epdesc.mxpacketsize[0] = LSBYTE(p_endpoint_desc->wMaxPacketSize.size); + epdesc.mxpacketsize[1] = MSBYTE(p_endpoint_desc->wMaxPacketSize.size); + epdesc.interval = p_endpoint_desc->bInterval; + + if (EP_CONFIGURE(usbdcd_driver.ep[epnum], &epdesc, false) < 0) + { + return false; + } + + return true; +} + +bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes) +{ + (void) rhport; + + uint8_t epnum = tu_edpt_number(ep_addr); + + if (epnum >= CXD56_EPNUM) + { + return false; + } + + usbdcd_driver.req[epnum]->len = total_bytes; + usbdcd_driver.req[epnum]->priv = (void *)((uint32_t)ep_addr); + usbdcd_driver.req[epnum]->flags = 0; + + if (total_bytes) + { + usbdcd_driver.req[epnum]->buf = buffer; + } + else + { + return true; + } + + if (EP_SUBMIT(usbdcd_driver.ep[epnum], usbdcd_driver.req[epnum]) < 0) + { + return false; + } + + return true; +} + +void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr) +{ + (void) rhport; + + uint8_t epnum = tu_edpt_number(ep_addr); + + if (epnum >= CXD56_EPNUM) + { + return; + } + + EP_STALL(usbdcd_driver.ep[epnum]); +} + +void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) +{ + (void) rhport; + + uint8_t epnum = tu_edpt_number(ep_addr); + + if (epnum >= CXD56_EPNUM) + { + return; + } + + EP_RESUME(usbdcd_driver.ep[epnum]); +} + +#endif diff --git a/src/tusb_option.h b/src/tusb_option.h index 76ea59758..28664c732 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -67,6 +67,8 @@ #define OPT_MCU_STM32L1 308 ///< ST STM32L1 #define OPT_MCU_STM32L4 309 ///< ST STM32L4 +#define OPT_MCU_CXD56 400 ///< SONY CXD56 + /** @} */ /** \defgroup group_supported_os Supported RTOS -- cgit v1.3.1 From b3872febe2651d51a08941352dc1a5e66df74d4b Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 7 Oct 2019 14:03:02 +0200 Subject: Disable/enable interrupt --- src/portable/sony/cxd56/dcd_cxd56.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 32eb50a6f..3698e5103 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -163,12 +163,16 @@ void dcd_init(uint8_t rhport) void dcd_int_enable(uint8_t rhport) { (void) rhport; + + __asm volatile ("cpsie i" : : : "memory"); } // Disable device interrupt void dcd_int_disable(uint8_t rhport) { (void) rhport; + + __asm volatile ("cpsid i" : : : "memory"); } // Receive Set Address request, mcu port must also include status IN response -- cgit v1.3.1 From 992360422113d15266552c5e488d87e0db60345e Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Mon, 7 Oct 2019 14:04:48 +0200 Subject: Send SUSPEND and RESUME signals --- src/portable/sony/cxd56/dcd_cxd56.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 3698e5103..38f3b5c75 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -141,12 +141,16 @@ static void dcd_suspend(FAR struct usbdevclass_driver_s *driver, FAR struct usbd { (void) driver; (void) dev; + + dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true); } static void dcd_resume(FAR struct usbdevclass_driver_s *driver, FAR struct usbdev_s *dev) { (void) driver; (void) dev; + + dcd_event_bus_signal(0, DCD_EVENT_RESUME, true); } void dcd_init(uint8_t rhport) -- cgit v1.3.1 From 0cea82568c318f1fb0cc2ade0e23811c4a13e724 Mon Sep 17 00:00:00 2001 From: Kamil Tomaszewski Date: Tue, 8 Oct 2019 09:58:56 +0200 Subject: Disable/enable only USB interrupt --- src/portable/sony/cxd56/dcd_cxd56.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/portable/sony/cxd56/dcd_cxd56.c b/src/portable/sony/cxd56/dcd_cxd56.c index 38f3b5c75..638b2f979 100644 --- a/src/portable/sony/cxd56/dcd_cxd56.c +++ b/src/portable/sony/cxd56/dcd_cxd56.c @@ -30,6 +30,7 @@ #include #include +#include #include "device/dcd.h" @@ -168,7 +169,7 @@ void dcd_int_enable(uint8_t rhport) { (void) rhport; - __asm volatile ("cpsie i" : : : "memory"); + up_enable_irq(CXD56_IRQ_USB_INT); } // Disable device interrupt @@ -176,7 +177,7 @@ void dcd_int_disable(uint8_t rhport) { (void) rhport; - __asm volatile ("cpsid i" : : : "memory"); + up_disable_irq(CXD56_IRQ_USB_INT); } // Receive Set Address request, mcu port must also include status IN response -- cgit v1.3.1 From 195d0f5a147fb83ae3685b9558bdaeb0bd83f8f2 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 12 Oct 2019 00:00:08 +0700 Subject: adding log support with uart started with pca10056 --- examples/make.mk | 1 + hw/bsp/board.c | 58 +++++++++++ hw/bsp/board.h | 2 +- hw/bsp/ea4357/ea4357.c | 2 +- hw/bsp/lpcxpresso1769/lpcxpresso1769.c | 2 +- hw/bsp/mbed1768/mbed1768.c | 2 +- hw/bsp/mcb1800/mcb1800.c | 2 +- hw/bsp/ngx4330/ngx4330.c | 2 +- hw/bsp/pca10056/board.mk | 1 + hw/bsp/pca10056/pca10056.c | 31 +++++- hw/bsp/printf_retarget.c | 183 --------------------------------- hw/mcu/nordic/nrfx_log.h | 135 ++++++++++++++++++++++++ src/common/tusb_compiler.h | 7 +- 13 files changed, 233 insertions(+), 195 deletions(-) create mode 100644 hw/bsp/board.c delete mode 100644 hw/bsp/printf_retarget.c create mode 100644 hw/mcu/nordic/nrfx_log.h (limited to 'src') diff --git a/examples/make.mk b/examples/make.mk index 699cc43d6..552483965 100644 --- a/examples/make.mk +++ b/examples/make.mk @@ -46,6 +46,7 @@ BUILD = _build/build-$(BOARD) include $(TOP)/hw/bsp/$(BOARD)/board.mk # Include all source C in board folder +SRC_C += hw/bsp/board.c SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/$(BOARD)/*.c)) # Compiler Flags diff --git a/hw/bsp/board.c b/hw/bsp/board.c new file mode 100644 index 000000000..16e713de5 --- /dev/null +++ b/hw/bsp/board.c @@ -0,0 +1,58 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2018, hathach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include "board.h" + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + +//#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART +// #define retarget_getchar board_uart_getchar +// #define retarget_putchar board_uart_putchar +//#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO +// volatile int32_t ITM_RxBuffer; // keil variable to read from SWO +// #define retarget_getchar ITM_ReceiveChar +// #define retarget_putchar ITM_SendChar +//#else +// #error Target is not implemented yet +//#endif + +//------------- IMPLEMENTATION -------------// + +// newlib read()/write() retarget + +TU_ATTR_USED int _write (int fhdl, const void *buf, size_t count) +{ + (void) fhdl; + return board_uart_write(buf, count); +} + +TU_ATTR_USED int _read (int fhdl, char *buf, size_t count) +{ + (void) fhdl; + return board_uart_read((uint8_t*) buf, count); +} diff --git a/hw/bsp/board.h b/hw/bsp/board.h index 15e3a2511..e0455b80d 100644 --- a/hw/bsp/board.h +++ b/hw/bsp/board.h @@ -42,7 +42,7 @@ #include "tusb.h" -#define CFG_UART_BAUDRATE 115200 +#define CFG_BOARD_UART_BAUDRATE 115200 //--------------------------------------------------------------------+ // Board Porting API diff --git a/hw/bsp/ea4357/ea4357.c b/hw/bsp/ea4357/ea4357.c index 2164d3e09..df80815d8 100644 --- a/hw/bsp/ea4357/ea4357.c +++ b/hw/bsp/ea4357/ea4357.c @@ -134,7 +134,7 @@ void board_init(void) UART_CFG_Type UARTConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; + UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE; UARTConfigStruct.Clock_Speed = 0; UART_Init(BOARD_UART_PORT, &UARTConfigStruct); diff --git a/hw/bsp/lpcxpresso1769/lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/lpcxpresso1769.c index bc6b1da7e..13b8fc9ff 100644 --- a/hw/bsp/lpcxpresso1769/lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/lpcxpresso1769.c @@ -116,7 +116,7 @@ void board_init(void) UART_CFG_Type UARTConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; + UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE; UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit diff --git a/hw/bsp/mbed1768/mbed1768.c b/hw/bsp/mbed1768/mbed1768.c index 05fb4ef35..647334a42 100644 --- a/hw/bsp/mbed1768/mbed1768.c +++ b/hw/bsp/mbed1768/mbed1768.c @@ -108,7 +108,7 @@ void board_init(void) UART_CFG_Type UARTConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; + UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE; UART_Init(BOARD_UART_PORT, &UARTConfigStruct); UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit diff --git a/hw/bsp/mcb1800/mcb1800.c b/hw/bsp/mcb1800/mcb1800.c index 6f1ef4244..44f5b11bb 100644 --- a/hw/bsp/mcb1800/mcb1800.c +++ b/hw/bsp/mcb1800/mcb1800.c @@ -118,7 +118,7 @@ void board_init(void) UART_CFG_Type UARTConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; + UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE; UARTConfigStruct.Clock_Speed = 0; UART_Init(BOARD_UART_PORT, &UARTConfigStruct); diff --git a/hw/bsp/ngx4330/ngx4330.c b/hw/bsp/ngx4330/ngx4330.c index 0e39ea711..609b4dac6 100644 --- a/hw/bsp/ngx4330/ngx4330.c +++ b/hw/bsp/ngx4330/ngx4330.c @@ -132,7 +132,7 @@ void board_init(void) UART_CFG_Type UARTConfigStruct; UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = CFG_UART_BAUDRATE; + UARTConfigStruct.Baud_rate = CFG_BOARD_UART_BAUDRATE; UARTConfigStruct.Clock_Speed = 0; UART_Init(BOARD_UART_PORT, &UARTConfigStruct); diff --git a/hw/bsp/pca10056/board.mk b/hw/bsp/pca10056/board.mk index c0616abee..3cd3e51c6 100644 --- a/hw/bsp/pca10056/board.mk +++ b/hw/bsp/pca10056/board.mk @@ -24,6 +24,7 @@ LDFLAGS += -L$(TOP)/hw/mcu/nordic/nrfx/mdk SRC_C += \ hw/mcu/nordic/nrfx/drivers/src/nrfx_power.c \ + hw/mcu/nordic/nrfx/drivers/src/nrfx_uart.c \ hw/mcu/nordic/nrfx/mdk/system_nrf52840.c \ INC += \ diff --git a/hw/bsp/pca10056/pca10056.c b/hw/bsp/pca10056/pca10056.c index 57426732c..78d9cc2cd 100644 --- a/hw/bsp/pca10056/pca10056.c +++ b/hw/bsp/pca10056/pca10056.c @@ -29,6 +29,7 @@ #include "nrfx.h" #include "nrfx/hal/nrf_gpio.h" #include "nrfx/drivers/include/nrfx_power.h" +#include "nrfx/drivers/include/nrfx_uart.h" #ifdef SOFTDEVICE_PRESENT #include "nrf_sdm.h" @@ -44,6 +45,12 @@ #define BUTTON_PIN 11 #define BUTTON_STATE_ACTIVE 0 +#define UART_RX_PIN 8 +#define UART_TX_PIN 6 + +static nrfx_uart_t _uart_id = NRFX_UART_INSTANCE(0); +//static void uart_handler(nrfx_uart_event_t const * p_event, void* p_context); + // tinyusb function that handles power event (detected, ready, removed) // We must call it within SD's SOC event handler, or set it as power event handler if SD is not enabled. extern void tusb_hal_nrf_power_event(uint32_t event); @@ -69,6 +76,21 @@ void board_init(void) SysTick_Config(SystemCoreClock/1000); #endif + // UART + nrfx_uart_config_t uart_cfg = + { + .pseltxd = UART_TX_PIN, + .pselrxd = UART_RX_PIN, + .pselcts = NRF_UART_PSEL_DISCONNECTED, + .pselrts = NRF_UART_PSEL_DISCONNECTED, + .p_context = NULL, + .hwfc = NRF_UART_HWFC_DISABLED, + .parity = NRF_UART_PARITY_EXCLUDED, + .baudrate = NRF_UART_BAUDRATE_115200 // CFG_BOARD_UART_BAUDRATE + }; + + nrfx_uart_init(&_uart_id, &uart_cfg, NULL); //uart_handler); + #if TUSB_OPT_DEVICE_ENABLED // Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice // 2 is highest for application @@ -124,6 +146,11 @@ uint32_t board_button_read(void) return BUTTON_STATE_ACTIVE == nrf_gpio_pin_read(BUTTON_PIN); } +//static void uart_handler(nrfx_uart_event_t const * p_event, void* p_context) +//{ +// +//} + int board_uart_read(uint8_t* buf, int len) { (void) buf; @@ -133,9 +160,7 @@ int board_uart_read(uint8_t* buf, int len) int board_uart_write(void const * buf, int len) { - (void) buf; - (void) len; - return 0; + return (NRFX_SUCCESS == nrfx_uart_tx(&_uart_id, (uint8_t const*) buf, (size_t) len)) ? len : 0; } #if CFG_TUSB_OS == OPT_OS_NONE diff --git a/hw/bsp/printf_retarget.c b/hw/bsp/printf_retarget.c deleted file mode 100644 index 707a1e099..000000000 --- a/hw/bsp/printf_retarget.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "board.h" - -#if CFG_PRINTF_TARGET != PRINTF_TARGET_SEMIHOST - -#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART - #define retarget_getchar() board_uart_getchar() - #define retarget_putchar(c) board_uart_putchar(c); -#elif CFG_PRINTF_TARGET == PRINTF_TARGET_SWO - volatile int32_t ITM_RxBuffer; // keil variable to read from SWO - #define retarget_getchar() ITM_ReceiveChar() - #define retarget_putchar(c) ITM_SendChar(c) -#else - #error Target is not implemented yet -#endif - -//--------------------------------------------------------------------+ -// LPCXPRESSO / RED SUITE -//--------------------------------------------------------------------+ -#if defined __CODE_RED - -#if CFG_PRINTF_TARGET == PRINTF_TARGET_SWO - #error author does not know how to retarget SWO with lpcxpresso/red-suite -#endif - -// Called by bottom level of printf routine within RedLib C library to write -// a character. With the default semihosting stub, this would write the character -// to the debugger console window . But this version writes -// the character to the UART. -int __sys_write (int iFileHandle, char *buf, int length) -{ - (void) iFileHandle; - - for (int i=0; i -#include -#include "__libc.h" - -int printf(const char *fmt,...) { - char buffer[128]; - va_list args; - va_start (args, fmt); - int n = vsnprintf(buffer, sizeof(buffer), fmt, args); - - for(int i=0; i < n; i++) - { - retarget_putchar( buffer[i] ); - } - - va_end(args); - return n; -} - -int __putchar(int ch, __printf_tag_ptr ctx) -{ - (void)ctx; - retarget_putchar( (uint8_t) ch ); - return 1; -} - -int __getchar() -{ - return retarget_getchar(); -} - -//--------------------------------------------------------------------+ -// KEIL -//--------------------------------------------------------------------+ -#elif defined __CC_ARM // keil - -struct __FILE { - uint32_t handle; -}; - -void _ttywrch(int ch) -{ - if ( ch == '\n' ) retarget_putchar('\r'); - - retarget_putchar(ch); -} - -int fgetc(FILE *f) -{ - return retarget_getchar(); -} - -int fputc(int ch, FILE *f) -{ - _ttywrch(ch); - return ch; -} - -//--------------------------------------------------------------------+ -// IAR -//--------------------------------------------------------------------+ -#elif defined __ICCARM__ // TODO could not able to retarget to UART with IAR - -#if CFG_PRINTF_TARGET == PRINTF_TARGET_UART -#include - -size_t __write(int handle, const unsigned char *buf, size_t length) -{ - /* Check for the command to flush all handles */ - if (handle == -1) return 0; - - /* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */ - if (handle != 1 && handle != 2) return -1; - - for (size_t i=0; i Date: Fri, 18 Oct 2019 16:38:02 +0700 Subject: clean up tusb_verify --- src/common/tusb_verify.h | 51 ++++++++++++++---------------------------------- src/osal/osal.h | 3 --- 2 files changed, 15 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index fae0c88ae..e59481352 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -107,20 +107,6 @@ if ( !(_cond) ) { _handler; return _ret; } \ } while(0) -/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ -#define TU_VERIFY_ERR_DEF2(_error, _handler) do \ -{ \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \ -} while(0) - -#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \ -{ \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \ -} while(0) - - /*------------------------------------------------------------------*/ /* TU_VERIFY * - TU_VERIFY_1ARGS : return false if failed @@ -142,28 +128,6 @@ #define TU_VERIFY_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_HDLR_3ARGS, TU_VERIFY_HDLR_2ARGS,UNUSED)(__VA_ARGS__) - -/*------------------------------------------------------------------*/ -/* TU_VERIFY STATUS - * - TU_VERIFY_ERR_1ARGS : return status of condition if failed - * - TU_VERIFY_ERR_2ARGS : return provided status code if failed - *------------------------------------------------------------------*/ -#define TU_VERIFY_ERR_1ARGS(_error) TU_VERIFY_ERR_DEF2(_error, ) -#define TU_VERIFY_ERR_2ARGS(_error, _ret) TU_VERIFY_ERR_DEF3(_error, ,_ret) - -#define TU_VERIFY_ERR(...) GET_3RD_ARG(__VA_ARGS__, TU_VERIFY_ERR_2ARGS, TU_VERIFY_ERR_1ARGS,UNUSED)(__VA_ARGS__) - -/*------------------------------------------------------------------*/ -/* TU_VERIFY STATUS WITH HANDLER - * - TU_VERIFY_ERR_HDLR_2ARGS : execute handler, return status if failed - * - TU_VERIFY_ERR_HDLR_3ARGS : execute handler, return provided error if failed - *------------------------------------------------------------------*/ -#define TU_VERIFY_ERR_HDLR_2ARGS(_error, _handler) TU_VERIFY_ERR_DEF2(_error, _handler) -#define TU_VERIFY_ERR_HDLR_3ARGS(_error, _handler, _ret) TU_VERIFY_ERR_DEF3(_error, _handler, _ret) - -#define TU_VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_ERR_HDLR_3ARGS, TU_VERIFY_ERR_HDLR_2ARGS,UNUSED)(__VA_ARGS__) - - /*------------------------------------------------------------------*/ /* ASSERT * basically TU_VERIFY with TU_BREAKPOINT() as handler @@ -175,6 +139,21 @@ #define TU_ASSERT(...) GET_3RD_ARG(__VA_ARGS__, ASSERT_2ARGS, ASSERT_1ARGS,UNUSED)(__VA_ARGS__) +// TODO remove TU_ASSERT_ERR() later + +/*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ +#define TU_VERIFY_ERR_DEF2(_error, _handler) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \ +} while(0) + +#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \ +} while(0) + /*------------------------------------------------------------------*/ /* ASSERT Error * basically TU_VERIFY Error with TU_BREAKPOINT() as handler diff --git a/src/osal/osal.h b/src/osal/osal.h index ea655d4f1..6b1d668a4 100644 --- a/src/osal/osal.h +++ b/src/osal/osal.h @@ -86,9 +86,6 @@ static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, b #define STASK_RETURN(_error) return _error; #define STASK_INVOKE(_subtask, _status) (_status) = _subtask - -// Sub Task Assert -#define STASK_ASSERT_ERR(_err) TU_VERIFY_ERR(_err) #define STASK_ASSERT(_cond) TU_VERIFY(_cond, TUSB_ERROR_OSAL_TASK_FAILED) #endif -- cgit v1.3.1 From 661515a8072f2b8ccd601c58120ea87b96158e76 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 23 Oct 2019 21:18:46 +0700 Subject: adding debug log function --- README.md | 5 +- hw/bsp/stm32f767nucleo/stm32f767nucleo.c | 3 +- src/common/tusb_common.h | 44 ++++++++++++++++-- src/device/dcd.h | 7 ++- src/device/usbd.c | 63 +++++++++++++++++-------- src/tusb.c | 80 +++++++++++++++++++++++++++++++- 6 files changed, 172 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/README.md b/README.md index 9609f315e..02fb8257c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://travis-ci.org/hathach/tinyusb.svg?branch=master)](https://travis-ci.org/hathach/tinyusb) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) -TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system. It is designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events are deferred then handled in the stack's task function. +TinyUSB is an open-source cross-platform USB Host/Device stack for embedded system, designed to be memory-safe with no dynamic allocation and thread-safe with all interrupt events are deferred then handled in the non-ISR task function. ![tinyusb](https://user-images.githubusercontent.com/249515/49858616-f60c9700-fe27-11e8-8627-e76936352ff7.png) @@ -54,7 +54,7 @@ Support multiple device configurations by dynamically changing usb descriptors. ## OS Abtraction layer -TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context. It also uses semphore/mutex to access shared resource such as CDC FIFO. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box. +TinyUSB is completely thread-safe by pushing all ISR events into a central queue, then process it later in the non-ISR context task function. It also uses semphore/mutex to access shared resource such as CDC FIFO. Therefore the stack needs to use some of OS's basic APIs. Following OSes are already supported out of the box. - **No OS** : Disabling USB IRQ is used as way to provide mutex - **FreeRTOS** @@ -84,6 +84,7 @@ TinyUSB is currently used by these other projects: * [Adafruit nRF52 Bootloader](https://github.com/adafruit/Adafruit_nRF52_Bootloader) * [Adafruit SAMD Arduino](https://github.com/adafruit/ArduinoCore-samd) * [CircuitPython](https://github.com/adafruit/circuitpython) +* [MicroPython](https://github.com/micropython/micropython) * [TinyUSB Arduino Library](https://github.com/adafruit/Adafruit_TinyUSB_Arduino) Let's me know if your project also uses TinyUSB and want to share. diff --git a/hw/bsp/stm32f767nucleo/stm32f767nucleo.c b/hw/bsp/stm32f767nucleo/stm32f767nucleo.c index 381692fa4..13966438f 100644 --- a/hw/bsp/stm32f767nucleo/stm32f767nucleo.c +++ b/hw/bsp/stm32f767nucleo/stm32f767nucleo.c @@ -214,8 +214,7 @@ int board_uart_read(uint8_t* buf, int len) int board_uart_write(void const * buf, int len) { HAL_UART_Transmit(&UartHandle, (uint8_t*) buf, len, 0xffff); -// (void) buf; (void) len; - return 0; + return len; } #if CFG_TUSB_OS == OPT_OS_NONE diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 57c6e2fcf..59e1fe7fd 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -35,7 +35,7 @@ extern "C" { #endif - //--------------------------------------------------------------------+ +//--------------------------------------------------------------------+ // Macros Helper //--------------------------------------------------------------------+ #define TU_ARRAY_SIZE(_arr) ( sizeof(_arr) / sizeof(_arr[0]) ) @@ -58,7 +58,7 @@ #define TU_BIT(n) (1U << (n)) //--------------------------------------------------------------------+ -// INCLUDES +// Includes //--------------------------------------------------------------------+ // Standard Headers @@ -77,7 +77,7 @@ #include "tusb_types.h" //--------------------------------------------------------------------+ -// INLINE FUNCTION +// Inline Functions //--------------------------------------------------------------------+ #define tu_memclr(buffer, size) memset((buffer), 0, (size)) #define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var))) @@ -203,6 +203,44 @@ static inline bool tu_bit_test (uint32_t value, uint8_t n) { return (value & + TU_BIN8(dlsb)) #endif +//--------------------------------------------------------------------+ +// Debug Function +//--------------------------------------------------------------------+ + +// CFG_TUSB_DEBUG for debugging +// 0 : no debug +// 1 : print when there is error +// 2 : print out log +#if CFG_TUSB_DEBUG + +void tu_print_mem(void const *buf, uint8_t size, uint16_t count); + +#ifndef tu_printf + #define tu_printf printf +#endif + +// Log with debug level 1 +#define TU_LOG1 tu_printf +#define TU_LOG1_MEM tu_print_mem + +// Log with debug level 2 +#if CFG_TUSB_DEBUG > 1 + #define TU_LOG2 TU_LOG1 + #define TU_LOG2_MEM TU_LOG1_MEM +#endif + +#endif // CFG_TUSB_DEBUG + +#ifndef TU_LOG1 + #define TU_LOG1(...) + #define TU_LOG1_MEM(...) +#endif + +#ifndef TU_LOG2 + #define TU_LOG2(...) + #define TU_LOG2_MEM(...) +#endif + #ifdef __cplusplus } #endif diff --git a/src/device/dcd.h b/src/device/dcd.h index bef062fb1..c417ee4be 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -39,7 +39,8 @@ typedef enum { - DCD_EVENT_BUS_RESET = 1, + DCD_EVENT_INVALID = 0, + DCD_EVENT_BUS_RESET, DCD_EVENT_UNPLUGGED, DCD_EVENT_SOF, DCD_EVENT_SUSPEND, // TODO LPM Sleep L1 support @@ -49,7 +50,9 @@ typedef enum DCD_EVENT_XFER_COMPLETE, // Not an DCD event, just a convenient way to defer ISR function - USBD_EVENT_FUNC_CALL + USBD_EVENT_FUNC_CALL, + + DCD_EVENT_COUNT } dcd_eventid_t; typedef struct TU_ATTR_ALIGNED(4) diff --git a/src/device/usbd.c b/src/device/usbd.c index 14e56a9b7..e7871fc03 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -192,6 +192,25 @@ void usbd_control_reset (uint8_t rhport); bool usbd_control_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_request_t const * ) ); + +//--------------------------------------------------------------------+ +// Debugging +//--------------------------------------------------------------------+ +#if CFG_TUSB_DEBUG +static char const* const _usbd_event_str[DCD_EVENT_COUNT] = +{ + "INVALID" , + "BUS_RESET" , + "UNPLUGGED" , + "SOF" , + "SUSPEND" , + "RESUME" , + "SETUP_RECEIVED" , + "XFER_COMPLETE" , + "FUNC_CALL" +}; +#endif + //--------------------------------------------------------------------+ // Application API //--------------------------------------------------------------------+ @@ -218,6 +237,8 @@ bool tud_remote_wakeup(void) //--------------------------------------------------------------------+ bool usbd_init (void) { + TU_LOG2("USBD Init\r\n"); + tu_varclr(&_usbd_dev); // Init device queue & task @@ -279,6 +300,8 @@ void tud_task (void) if ( !osal_queue_receive(_usbd_q, &event) ) return; + TU_LOG2("USBD: event %s\r\n", event.event_id < DCD_EVENT_COUNT ? _usbd_event_str[event.event_id] : "CORRUPTED"); + switch ( event.event_id ) { case DCD_EVENT_BUS_RESET: @@ -293,6 +316,8 @@ void tud_task (void) break; case DCD_EVENT_SETUP_RECEIVED: + TU_LOG2_MEM(&event.setup_received, 1, 8); + // Mark as connected after receiving 1st setup packet. // But it is easier to set it every time instead of wasting time to check then set _usbd_dev.connected = 1; @@ -307,29 +332,29 @@ void tud_task (void) break; case DCD_EVENT_XFER_COMPLETE: - // Only handle xfer callback in ready state - // if (_usbd_dev.connected && !_usbd_dev.suspended) - { - // Invoke the class callback associated with the endpoint address - uint8_t const ep_addr = event.xfer_complete.ep_addr; - uint8_t const epnum = tu_edpt_number(ep_addr); - uint8_t const ep_dir = tu_edpt_dir(ep_addr); + { + // Invoke the class callback associated with the endpoint address + uint8_t const ep_addr = event.xfer_complete.ep_addr; + uint8_t const epnum = tu_edpt_number(ep_addr); + uint8_t const ep_dir = tu_edpt_dir(ep_addr); - _usbd_dev.ep_status[epnum][ep_dir].busy = false; + TU_LOG2("Endpoint: 0x%02X, Bytes: %ld\r\n", ep_addr, event.xfer_complete.len); - if ( 0 == epnum ) - { - // control transfer DATA stage callback - usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); - } - else - { - uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir]; - TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); + _usbd_dev.ep_status[epnum][ep_dir].busy = false; - usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); - } + if ( 0 == epnum ) + { + // control transfer DATA stage callback + usbd_control_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } + else + { + uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir]; + TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); + + usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); + } + } break; case DCD_EVENT_SUSPEND: diff --git a/src/tusb.c b/src/tusb.c index 0f8eedd57..97e3371db 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -43,11 +43,11 @@ bool tusb_init(void) if (_initialized) return true; #if TUSB_OPT_HOST_ENABLED - TU_VERIFY( usbh_init() ); // init host stack + TU_ASSERT( usbh_init() ); // init host stack #endif #if TUSB_OPT_DEVICE_ENABLED - TU_VERIFY ( usbd_init() ); // init device stack + TU_ASSERT ( usbd_init() ); // init device stack #endif _initialized = true; @@ -64,7 +64,83 @@ bool tusb_inited(void) /* Debug *------------------------------------------------------------------*/ #if CFG_TUSB_DEBUG +#include + char const* const tusb_strerr[TUSB_ERROR_COUNT] = { ERROR_TABLE(ERROR_STRING) }; + +static void dump_str_line(uint8_t const* buf, uint16_t count) +{ + // each line is 16 bytes + for(int i=0; i Date: Thu, 24 Oct 2019 12:00:06 +0700 Subject: adding more log --- examples/device/cdc_msc/src/main.c | 1 - src/device/usbd.c | 67 +++++++++++++++++++++++++++++++++++--- src/tusb.c | 8 ++--- 3 files changed, 65 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index c6ed4a922..e1b9ab113 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -55,7 +55,6 @@ void cdc_task(void); int main(void) { board_init(); - tusb_init(); while (1) diff --git a/src/device/usbd.c b/src/device/usbd.c index e7871fc03..f2becab95 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -196,7 +196,7 @@ void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_reque //--------------------------------------------------------------------+ // Debugging //--------------------------------------------------------------------+ -#if CFG_TUSB_DEBUG +#if CFG_TUSB_DEBUG > 1 static char const* const _usbd_event_str[DCD_EVENT_COUNT] = { "INVALID" , @@ -209,6 +209,47 @@ static char const* const _usbd_event_str[DCD_EVENT_COUNT] = "XFER_COMPLETE" , "FUNC_CALL" }; + +// must be same driver order as usbd_class_drivers[] +static char const* const _usbd_driver_str[USBD_CLASS_DRIVER_COUNT] = +{ + #if CFG_TUD_CDC + "CDC", + #endif + #if CFG_TUD_MSC + "MSC", + #endif + #if CFG_TUD_HID + "HID", + #endif + #if CFG_TUD_MIDI + "MIDI", + #endif + #if CFG_TUD_VENDOR + "Vendor", + #endif + #if CFG_TUD_USBTMC + "USBTMC" + #endif +}; + +static char const* const _tusb_std_request_str[] = +{ + "Get Status" , + "Clear Feature" , + "Reserved" , + "Set Feature" , + "Reserved" , + "Set Address" , + "Get Descriptor" , + "Set Descriptor" , + "Get Configuration" , + "Set Configuration" , + "Get Interface" , + "Set Interface" , + "Synch Frame" +}; + #endif //--------------------------------------------------------------------+ @@ -237,7 +278,7 @@ bool tud_remote_wakeup(void) //--------------------------------------------------------------------+ bool usbd_init (void) { - TU_LOG2("USBD Init\r\n"); + TU_LOG2("USBD init\r\n"); tu_varclr(&_usbd_dev); @@ -246,7 +287,11 @@ bool usbd_init (void) TU_ASSERT(_usbd_q != NULL); // Init class drivers - for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) usbd_class_drivers[i].init(); + for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) + { + TU_LOG2("%s init\r\n", _usbd_driver_str[i]); + usbd_class_drivers[i].init(); + } // Init device controller driver dcd_init(TUD_OPT_RHPORT); @@ -316,6 +361,7 @@ void tud_task (void) break; case DCD_EVENT_SETUP_RECEIVED: + TU_LOG2(" "); TU_LOG2_MEM(&event.setup_received, 1, 8); // Mark as connected after receiving 1st setup packet. @@ -338,7 +384,7 @@ void tud_task (void) uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const ep_dir = tu_edpt_dir(ep_addr); - TU_LOG2("Endpoint: 0x%02X, Bytes: %ld\r\n", ep_addr, event.xfer_complete.len); + TU_LOG2(" Endpoint: 0x%02X, Bytes: %ld\r\n", ep_addr, event.xfer_complete.len); _usbd_dev.ep_status[epnum][ep_dir].busy = false; @@ -352,6 +398,7 @@ void tud_task (void) uint8_t const drv_id = _usbd_dev.ep2drv[epnum][ep_dir]; TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); + TU_LOG2(" %s xfer callback\r\n", _usbd_driver_str[drv_id]); usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } } @@ -407,6 +454,13 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const return tud_vendor_control_request_cb(rhport, p_request); } +#if CFG_TUSB_DEBUG > 1 + if (TUSB_REQ_TYPE_STANDARD == p_request->bmRequestType_bit.type && p_request->bRequest <= TUSB_REQ_SYNCH_FRAME) + { + TU_LOG2(" %s\r\n", _tusb_std_request_str[p_request->bRequest]); + } +#endif + switch ( p_request->bmRequestType_bit.recipient ) { //------------- Device Requests e.g in enumeration -------------// @@ -519,6 +573,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const // GET HID REPORT DESCRIPTOR falls into this case // stall control endpoint if driver return false usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete); + TU_LOG2(" %s control request\r\n", _usbd_driver_str[drvid]); TU_ASSERT(usbd_class_drivers[drvid].control_request != NULL && usbd_class_drivers[drvid].control_request(rhport, p_request)); break; @@ -528,6 +583,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const // forward to class driver: "non-STD request to Interface" // stall control endpoint if driver return false usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete); + TU_LOG2(" %s control request\r\n", _usbd_driver_str[drvid]); TU_ASSERT(usbd_class_drivers[drvid].control_request != NULL && usbd_class_drivers[drvid].control_request(rhport, p_request)); } @@ -595,7 +651,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const // For std-type requests: non-std request codes are already discarded. // must not call tud_control_status(), and return value will have no effect // class driver is invoked last, so that EP already has EP stall cleared (in event of clear feature EP halt) - + TU_LOG2(" %s control request\r\n", _usbd_driver_str[drv_id]); if ( usbd_class_drivers[drv_id].control_request && usbd_class_drivers[drv_id].control_request(rhport, p_request)) { @@ -652,6 +708,7 @@ static bool process_set_config(uint8_t rhport, uint8_t cfg_num) _usbd_dev.itf2drv[desc_itf->bInterfaceNumber] = drv_id; uint16_t itf_len=0; + TU_LOG2(" %s open\r\n", _usbd_driver_str[drv_id]); TU_ASSERT( usbd_class_drivers[drv_id].open(rhport, desc_itf, &itf_len) ); TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) ); diff --git a/src/tusb.c b/src/tusb.c index 97e3371db..271b35f1e 100644 --- a/src/tusb.c +++ b/src/tusb.c @@ -85,7 +85,7 @@ void tu_print_mem(void const *buf, uint8_t size, uint16_t count) { if ( !buf || !count ) { - tu_printf("NULL\n"); + tu_printf("NULL\r\n"); return; } @@ -107,7 +107,7 @@ void tu_print_mem(void const *buf, uint8_t size, uint16_t count) { tu_printf(" | "); dump_str_line(buf8-16, 16); - tu_printf("\n"); + tu_printf("\r\n"); } // print offset or absolute address @@ -136,9 +136,7 @@ void tu_print_mem(void const *buf, uint8_t size, uint16_t count) tu_printf(" | "); dump_str_line(buf8-nback, nback); - tu_printf("\n"); - - tu_printf("\n"); + tu_printf("\r\n"); } #endif -- cgit v1.3.1