diff --git a/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject b/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject index ed6840e0..6bcd7d4a 100644 --- a/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject +++ b/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject @@ -18,7 +18,7 @@ arm_target_debug_interface_type="ADIv5" arm_target_device_name="LPC4088" arm_target_interface_type="SWD" - c_preprocessor_definitions="CORE_M4;__LPC4000_FAMILY;__LPC408x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4088QS;CFG_TUSB_MCU=OPT_MCU_LPC40XX" + c_preprocessor_definitions="CORE_M4;__LPC4000_FAMILY;__LPC408x_SUBFAMILY;ARM_MATH_CM4;FLASH_PLACEMENT=1;BOARD_EA4088QS;CFG_TUSB_MCU=OPT_MCU_LPC40XX;CFG_TUSB_MEM_SECTION= __attribute__((section(".bss2")))" c_user_include_directories="../../src;$(rootDir)/hw;$(rootDir)/src;$(lpcDir)/inc" debug_register_definition_file="$(ProjectDir)/LPC408x_7x_Registers.xml" debug_target_connection="J-Link" diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index a9a356f2..30bf05fa 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/examples/device/cdc_msc_hid/src/tusb_config.h @@ -99,9 +99,9 @@ // #define CFG_TUD_DESC_VID 0xCAFE // #define CFG_TUD_DESC_PID 0x0001 -// LPC175x_6x's endpoint type (bulk/interrupt/iso) are fixed by its number +// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number // Therefor we need to force endpoint number to correct type on lpc17xx -#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X +#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX #define CFG_TUD_DESC_CDC_EPNUM_NOTIF 1 #define CFG_TUD_DESC_CDC_EPNUM 2 #define CFG_TUD_DESC_MSC_EPNUM 5 diff --git a/hw/bsp/ea4088qs/board_ea4088qs.c b/hw/bsp/ea4088qs/board_ea4088qs.c index 79e00a57..af48b363 100644 --- a/hw/bsp/ea4088qs/board_ea4088qs.c +++ b/hw/bsp/ea4088qs/board_ea4088qs.c @@ -39,6 +39,7 @@ #ifdef BOARD_EA4088QS #include "../board.h" +#include "tusb.h" #define LED_PORT 2 #define LED_PIN 19 @@ -55,9 +56,25 @@ const uint32_t RTCOscRateIn = 32768; static const PINMUX_GRP_T pinmuxing[] = { /* LEDs */ - {0x2, 19, (IOCON_FUNC0 | IOCON_MODE_INACT)}, + {2, 19, (IOCON_FUNC0 | IOCON_MODE_INACT)}, }; +static const PINMUX_GRP_T pin_usb_mux[] = +{ + // USB1 as Host + {0, 29, (IOCON_FUNC1 | IOCON_MODE_INACT)}, // D+1 + {0, 30, (IOCON_FUNC1 | IOCON_MODE_INACT)}, // D-1 + {1, 18, (IOCON_FUNC1 | IOCON_MODE_INACT)}, // UP LED1 + {1, 19, (IOCON_FUNC2 | IOCON_MODE_INACT)}, // PPWR1 + + // USB2 as Device + {0, 31, (IOCON_FUNC1 | IOCON_MODE_INACT)}, // D+2 + {0, 13, (IOCON_FUNC1 | IOCON_MODE_INACT)}, // UP LED + {0, 14, (IOCON_FUNC3 | IOCON_MODE_INACT)}, // CONNECT2 + + /* VBUS is not connected on this board, so leave the pin at default setting. */ + /*Chip_IOCON_PinMux(LPC_IOCON, 1, 30, IOCON_MODE_INACT, IOCON_FUNC2);*/ /* USB VBUS */ +}; // Invoked by startup code void SystemInit(void) @@ -90,6 +107,20 @@ void board_init(void) //------------- UART -------------// //------------- USB -------------// + // Port1 as Host, Port2: Device + Chip_USB_Init(); + + enum { + USBCLK = 0x1B // Host + Device + OTG + AHB + }; + + LPC_USB->OTGClkCtrl = USBCLK; + while ( (LPC_USB->OTGClkSt & USBCLK) != USBCLK ); + + // USB1 = host, USB2 = device + LPC_USB->StCtrl = 0x3; + + Chip_IOCON_SetPinMuxing(LPC_IOCON, pin_usb_mux, sizeof(pin_usb_mux) / sizeof(PINMUX_GRP_T)); } diff --git a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c index 257c74b6..00141e9a 100644 --- a/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c +++ b/hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c @@ -40,6 +40,7 @@ #ifdef BOARD_LPCXPRESSO1769 #include "../board.h" +#include "tusb.h" #define LED_PORT 0 #define LED_PIN 22 @@ -63,11 +64,19 @@ static const PINMUX_GRP_T pinmuxing[] = {2, 4, IOCON_MODE_INACT | IOCON_FUNC0}, /* JOYSTICK_LEFT */ {0, 16, IOCON_MODE_INACT | IOCON_FUNC0}, /* JOYSTICK_RIGHT */ {0, 17, IOCON_MODE_INACT | IOCON_FUNC0}, /* JOYSTICK_PRESS */ +}; - // USB +static const PINMUX_GRP_T pin_usb_mux[] = +{ {0, 29, IOCON_MODE_INACT | IOCON_FUNC1}, // D+ {0, 30, IOCON_MODE_INACT | IOCON_FUNC1}, // D- {2, 9, IOCON_MODE_INACT | IOCON_FUNC1}, // Connect + + {1, 19, IOCON_MODE_INACT | IOCON_FUNC2}, // USB_PPWR + {1, 22, IOCON_MODE_INACT | IOCON_FUNC2}, // USB_PWRD + + /* VBUS is not connected on this board, so leave the pin at default setting. */ + /*Chip_IOCON_PinMux(LPC_IOCON, 1, 30, IOCON_MODE_INACT, IOCON_FUNC2);*/ /* USB VBUS */ }; enum { @@ -101,18 +110,6 @@ void board_init(void) //------------- BUTTON -------------// // for(uint8_t i=0; iOTGClkCtrl = clk_en; + while ( (LPC_USB->OTGClkSt & clk_en) != clk_en ); + +#if MODE_HOST_SUPPORTED + // set portfunc to host !!! + LPC_USB->StCtrl = 0x3; // should be 1 +#endif + + Chip_IOCON_SetPinMuxing(LPC_IOCON, pin_usb_mux, sizeof(pin_usb_mux) / sizeof(PINMUX_GRP_T)); } /*------------------------------------------------------------------*/ diff --git a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c index 6ed1792c..8504cbf5 100644 --- a/src/portable/nxp/lpc17_40/dcd_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/dcd_lpc17_40.c @@ -103,7 +103,7 @@ typedef struct } dcd_data_t; -ATTR_ALIGNED(128) static dcd_data_t _dcd; +CFG_TUSB_MEM_SECTION ATTR_ALIGNED(128) static dcd_data_t _dcd; //--------------------------------------------------------------------+ diff --git a/src/portable/nxp/lpc17_40/hal_lpc17_40.c b/src/portable/nxp/lpc17_40/hal_lpc17_40.c index cebddd88..70df7051 100644 --- a/src/portable/nxp/lpc17_40/hal_lpc17_40.c +++ b/src/portable/nxp/lpc17_40/hal_lpc17_40.c @@ -59,30 +59,6 @@ void tusb_hal_int_disable(uint8_t rhport) //--------------------------------------------------------------------+ bool tusb_hal_init(void) { - enum { - USBCLK_DEVCIE = 0x12, // AHB + Device - USBCLK_HOST = 0x19, // AHB + Host + OTG (!) - }; - - Chip_USB_Init(); - -#if MODE_HOST_SUPPORTED - // TODO move pin config to BSP - PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 1, .Pinnum = 22, .Funcnum = 2} ); // P1.22 as USB_PWRD - PINSEL_ConfigPin( &(PINSEL_CFG_Type) { .Portnum = 1, .Pinnum = 19, .Funcnum = 2} ); // P1.19 as USB_PPWR - - // Enable host - LPC_USB->USBClkCtrl = USBCLK_HOST; - while ((LPC_USB->USBClkSt & USBCLK_HOST) != USBCLK_HOST); - LPC_USB->OTGClkSt = 0x3; -#endif - -#if TUSB_OPT_DEVICE_ENABLED - // Enable Device - LPC_USB->USBClkCtrl = USBCLK_DEVCIE; - while ((LPC_USB->USBClkSt & USBCLK_DEVCIE) != USBCLK_DEVCIE); -#endif - return true; } diff --git a/src/tusb_option.h b/src/tusb_option.h index d808a051..c558b30f 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -153,6 +153,10 @@ #define CFG_TUSB_MEM_SECTION #endif +#ifndef CFG_TUSB_MEM_ALIGN +#define CFG_TUSB_MEM_ALIGN ATTR_ALIGNED(4) +#endif + #ifndef CFG_TUSB_OS #define CFG_TUSB_OS OPT_OS_NONE #endif