summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-05 08:47:23 +0700
committerhathach <[email protected]>2018-12-05 08:47:23 +0700
commitdd9c7b4249618cb8113b0a37226bc6947818ecf0 (patch)
treea2f3dcdef1337434a25bf0319e1668da6873a018
parentfe8346e642c369ad0e0b5bbf3a10d8e7d16a10fc (diff)
lpc40xx device work, moving Chip_USB_Init out of tinyusb
-rw-r--r--examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject2
-rw-r--r--examples/device/cdc_msc_hid/src/tusb_config.h4
-rw-r--r--hw/bsp/ea4088qs/board_ea4088qs.c33
-rw-r--r--hw/bsp/lpcxpresso1769/board_lpcxpresso1769.c45
-rw-r--r--src/portable/nxp/lpc17_40/dcd_lpc17_40.c2
-rw-r--r--src/portable/nxp/lpc17_40/hal_lpc17_40.c24
-rw-r--r--src/tusb_option.h4
7 files changed, 70 insertions, 44 deletions
diff --git a/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject b/examples/device/cdc_msc_hid/ses/lpc40xx/lpc40xx.emProject
index ed6840e06..6bcd7d4a7 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(&quot;.bss2&quot;)))"
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 a9a356f20..30bf05fab 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 79e00a57e..af48b363b 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 257c74b63..00141e9a1 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; i<BOARD_BUTTON_COUNT; i++) GPIO_SetDir(buttons[i].port, BIT_(buttons[i].pin), 0);
-#if TUSB_OPT_DEVICE_ENABLED
- //------------- USB Device -------------//
- // VBUS sense is wrongly connected to P0_5 (instead of P1_30). So we need to always pull P1_30 to high
- // so that USB device block can work. However, Device Controller (thus tinyusb) cannot able to determine
- // if device is disconnected or not
- PINSEL_ConfigPin( &(PINSEL_CFG_Type) {
- .Portnum = 1, .Pinnum = 30,
- .Funcnum = 2, .Pinmode = PINSEL_PINMODE_PULLUP} );
-
- //P0_21 instead of P2_9 as USB connect
-#endif
-
#if 0
//------------- UART -------------//
PINSEL_CFG_Type PinCfg =
@@ -137,8 +134,26 @@ void board_init(void)
UART_TxCmd(BOARD_UART_PORT, ENABLE); // Enable UART Transmit
#endif
- /* VBUS is not connected on the NXP LPCXpresso LPC1769, so leave the pin at default setting. */
- /*Chip_IOCON_PinMux(LPC_IOCON, 1, 30, IOCON_MODE_INACT, IOCON_FUNC2);*/ /* USB VBUS */
+ //------------- USB -------------//
+ Chip_USB_Init();
+
+ enum {
+ USBCLK_DEVCIE = 0x12, // AHB + Device
+ USBCLK_HOST = 0x19, // AHB + Host + OTG
+// 0x1B // Host + Device + OTG + AHB
+ };
+
+ uint32_t const clk_en = TUSB_OPT_DEVICE_ENABLED ? USBCLK_DEVCIE : USBCLK_HOST;
+
+ LPC_USB->OTGClkCtrl = 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 6ed1792ce..8504cbf51 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 cebddd883..70df70510 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 d808a0518..c558b30ff 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