summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2024-10-10 17:00:40 +0700
committerGitHub <[email protected]>2024-10-10 17:00:40 +0700
commita4fb8354e41b2604f66e7da22afa292b1a44f0a2 (patch)
tree1e980f0c18f558e3041dbef3021afa346297a85d /hw
parentffdf81f53a84111a2536defa86e4a637c3c46854 (diff)
parent57aac432b52df6d284c98daf591e661d1c55aa05 (diff)
Merge pull request #2834 from hathach/add-tusb_int_handler-update-tinyusb_init
add new tusb_int_handler(rhport, in_isr) and update tusb_init(rhport, role)
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/imxrt/boards/mimxrt1060_evk/board.cmake1
-rw-r--r--hw/bsp/imxrt/family.c28
-rw-r--r--hw/bsp/lpc18/family.c33
-rw-r--r--hw/bsp/lpc43/family.c46
-rw-r--r--hw/bsp/lpc54/family.c20
-rw-r--r--hw/bsp/lpc55/family.c20
-rw-r--r--hw/bsp/mcx/family.c26
-rw-r--r--hw/bsp/ra/family.c36
-rw-r--r--hw/bsp/rp2040/family.c4
-rw-r--r--hw/bsp/stm32f4/boards/stm32f412disco/board.cmake1
-rw-r--r--hw/bsp/stm32f4/family.c4
-rw-r--r--hw/bsp/stm32h7/family.c32
12 files changed, 48 insertions, 203 deletions
diff --git a/hw/bsp/imxrt/boards/mimxrt1060_evk/board.cmake b/hw/bsp/imxrt/boards/mimxrt1060_evk/board.cmake
index fd335cdf5..f70a5f923 100644
--- a/hw/bsp/imxrt/boards/mimxrt1060_evk/board.cmake
+++ b/hw/bsp/imxrt/boards/mimxrt1060_evk/board.cmake
@@ -1,6 +1,7 @@
set(MCU_VARIANT MIMXRT1062)
set(JLINK_DEVICE MIMXRT1062xxx6A)
+#set(JLINK_OPTION "-USB 000726129165")
set(PYOCD_TARGET mimxrt1060)
set(NXPLINK_DEVICE MIMXRT1062xxxxA:EVK-MIMXRT1060)
diff --git a/hw/bsp/imxrt/family.c b/hw/bsp/imxrt/family.c
index 2f305aa4d..6087ee37d 100644
--- a/hw/bsp/imxrt/family.c
+++ b/hw/bsp/imxrt/family.c
@@ -46,18 +46,6 @@
#pragma GCC diagnostic pop
#endif
-#if defined(BOARD_TUD_RHPORT) && CFG_TUD_ENABLED
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#if defined(BOARD_TUH_RHPORT) && CFG_TUH_ENABLED
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
// needed by fsl_flexspi_nor_boot
TU_ATTR_USED const uint8_t dcd_data[] = { 0x00 };
@@ -156,23 +144,11 @@ void board_init(void)
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB_OTG1_IRQHandler(void) {
- #if PORT_SUPPORT_DEVICE(0)
- tud_int_handler(0);
- #endif
-
- #if PORT_SUPPORT_HOST(0)
- tuh_int_handler(0, true);
- #endif
+ tusb_int_handler(0, true);
}
void USB_OTG2_IRQHandler(void) {
- #if PORT_SUPPORT_DEVICE(1)
- tud_int_handler(1);
- #endif
-
- #if PORT_SUPPORT_HOST(1)
- tuh_int_handler(1, true);
- #endif
+ tusb_int_handler(1, true);
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/lpc18/family.c b/hw/bsp/lpc18/family.c
index e6abecb4b..55ef31ee4 100644
--- a/hw/bsp/lpc18/family.c
+++ b/hw/bsp/lpc18/family.c
@@ -28,39 +28,15 @@
#include "bsp/board_api.h"
#include "board.h"
-#ifdef BOARD_TUD_RHPORT
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void) {
- #if PORT_SUPPORT_DEVICE(0)
- tud_int_handler(0);
- #endif
-
- #if PORT_SUPPORT_HOST(0)
- tuh_int_handler(0, true);
- #endif
+ tusb_int_handler(0, true);
}
void USB1_IRQHandler(void) {
- #if PORT_SUPPORT_DEVICE(1)
- tud_int_handler(1);
- #endif
-
- #if PORT_SUPPORT_HOST(1)
- tuh_int_handler(1, true);
- #endif
+ tusb_int_handler(1, true);
}
//--------------------------------------------------------------------+
@@ -118,13 +94,8 @@ void board_init(void) {
Chip_UART_TXEnable(UART_DEV);
//------------- USB -------------//
-#if PORT_SUPPORT_DEVICE(0) || PORT_SUPPORT_HOST(0)
Chip_USB0_Init();
-#endif
-
-#if PORT_SUPPORT_DEVICE(1) || PORT_SUPPORT_HOST(1)
Chip_USB1_Init();
-#endif
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/lpc43/family.c b/hw/bsp/lpc43/family.c
index 8be729f7d..dfee9f5ea 100644
--- a/hw/bsp/lpc43/family.c
+++ b/hw/bsp/lpc43/family.c
@@ -39,18 +39,6 @@
#include "bsp/board_api.h"
#include "board.h"
-#ifdef BOARD_TUD_RHPORT
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
/* System configuration variables used by chip driver */
const uint32_t OscRateIn = 12000000;
const uint32_t ExtRateIn = 0;
@@ -161,9 +149,7 @@ void board_init(void)
* - Insert jumpers in position 2-3 in JP17/JP18/JP19
* - Insert jumpers in JP31 (OTG)
*/
-#if PORT_SUPPORT_DEVICE(0) || PORT_SUPPORT_HOST(0)
Chip_USB0_Init();
-#endif
/* From EA4357 user manual
*
@@ -186,17 +172,15 @@ void board_init(void)
* - LED34 lights green when +5V is available on J20.
* - JP15 shall not be inserted. JP16 has no effect
*/
-#if PORT_SUPPORT_DEVICE(1) || PORT_SUPPORT_HOST(1)
Chip_USB1_Init();
-#endif
// USB0 Vbus Power: P2_3 on EA4357 channel B U20 GPIO26 active low (base board)
Chip_SCU_PinMuxSet(2, 3, SCU_MODE_PULLUP | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC7);
- #if PORT_SUPPORT_DEVICE(0)
- // P9_5 (GPIO5[18]) (GPIO28 on oem base) as USB connect, active low.
- Chip_SCU_PinMuxSet(9, 5, SCU_MODE_PULLDOWN | SCU_MODE_FUNC4);
- Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 5, 18);
+ #if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 0
+ // P9_5 (GPIO5[18]) (GPIO28 on oem base) as USB connect, active low.
+ Chip_SCU_PinMuxSet(9, 5, SCU_MODE_PULLDOWN | SCU_MODE_FUNC4);
+ Chip_GPIO_SetPinDIROutput(LPC_GPIO_PORT, 5, 18);
#endif
// USB1 Power: EA4357 channel A U20 is enabled by SJ5 connected to pad 1-2, no more action required
@@ -206,26 +190,12 @@ void board_init(void)
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
-void USB0_IRQHandler(void)
-{
- #if PORT_SUPPORT_DEVICE(0)
- tud_int_handler(0);
- #endif
-
- #if PORT_SUPPORT_HOST(0)
- tuh_int_handler(0, true);
- #endif
+void USB0_IRQHandler(void) {
+ tusb_int_handler(0, true);
}
-void USB1_IRQHandler(void)
-{
- #if PORT_SUPPORT_DEVICE(1)
- tud_int_handler(1);
- #endif
-
- #if PORT_SUPPORT_HOST(1)
- tuh_int_handler(1, true);
- #endif
+void USB1_IRQHandler(void) {
+ tusb_int_handler(1, true);
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/lpc54/family.c b/hw/bsp/lpc54/family.c
index 5e5732d74..5e6ff2231 100644
--- a/hw/bsp/lpc54/family.c
+++ b/hw/bsp/lpc54/family.c
@@ -33,18 +33,6 @@
#include "bsp/board_api.h"
#include "board.h"
-#ifdef BOARD_TUD_RHPORT
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
@@ -71,11 +59,11 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
void USB1_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
/****************************************************************
@@ -160,7 +148,7 @@ void board_init(void) {
#if defined(FSL_FEATURE_SOC_USBHSD_COUNT) && FSL_FEATURE_SOC_USBHSD_COUNT
// LPC546xx and LPC540xx has OTG 1 FS + 1 HS rhports
- #if PORT_SUPPORT_DEVICE(0)
+ #if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 0
// Port0 is Full Speed
POWER_DisablePD(kPDRUNCFG_PD_USB0_PHY); /*< Turn on USB Phy */
CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1, false);
@@ -174,7 +162,7 @@ void board_init(void) {
CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbSrcFro, CLOCK_GetFroHfFreq());
#endif
- #if PORT_SUPPORT_DEVICE(1)
+ #if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 1
// Port1 is High Speed
POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY);
diff --git a/hw/bsp/lpc55/family.c b/hw/bsp/lpc55/family.c
index 075832ea7..68ccf52d5 100644
--- a/hw/bsp/lpc55/family.c
+++ b/hw/bsp/lpc55/family.c
@@ -37,18 +37,6 @@
#include "sct_neopixel.h"
#endif
-#ifdef BOARD_TUD_RHPORT
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
@@ -73,11 +61,11 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
void USB1_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
/****************************************************************
@@ -209,7 +197,7 @@ void board_init(void) {
/* PORT0 PIN22 configured as USB0_VBUS */
IOCON_PinMuxSet(IOCON, 0U, 22U, IOCON_PIO_DIG_FUNC7_EN);
-#if PORT_SUPPORT_DEVICE(0)
+#if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 0
// Port0 is Full Speed
/* Turn on USB0 Phy */
@@ -234,7 +222,7 @@ void board_init(void) {
CLOCK_EnableUsbfs0DeviceClock(kCLOCK_UsbfsSrcFro, CLOCK_GetFreq(kCLOCK_FroHf));
#endif
-#if PORT_SUPPORT_DEVICE(1)
+#if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 1
// Port1 is High Speed
/* Turn on USB1 Phy */
diff --git a/hw/bsp/mcx/family.c b/hw/bsp/mcx/family.c
index cc675a49d..ce54097fe 100644
--- a/hw/bsp/mcx/family.c
+++ b/hw/bsp/mcx/family.c
@@ -34,38 +34,22 @@
#include "clock_config.h"
//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-#ifdef BOARD_TUD_RHPORT
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#ifdef BOARD_TUH_RHPORT
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
-//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
#if CFG_TUSB_MCU == OPT_MCU_MCXN9
void USB0_FS_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
void USB1_HS_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
#elif CFG_TUSB_MCU == OPT_MCU_MCXA15
void USB0_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
#endif
@@ -133,7 +117,7 @@ void board_init(void) {
// USB VBUS
/* PORT0 PIN22 configured as USB0_VBUS */
-#if PORT_SUPPORT_DEVICE(0)
+#if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 0
// Port0 is Full Speed
#if CFG_TUSB_MCU == OPT_MCU_MCXA15
@@ -147,7 +131,7 @@ void board_init(void) {
CLOCK_EnableUsbfsClock();
#endif
-#if PORT_SUPPORT_DEVICE(1) && (CFG_TUSB_MCU == OPT_MCU_MCXN9)
+#if defined(BOARD_TUD_RHPORT) && BOARD_TUD_RHPORT == 1 && (CFG_TUSB_MCU == OPT_MCU_MCXN9)
// Port1 is High Speed
// Power
diff --git a/hw/bsp/ra/family.c b/hw/bsp/ra/family.c
index a8b4ebcc7..87f7b4a22 100644
--- a/hw/bsp/ra/family.c
+++ b/hw/bsp/ra/family.c
@@ -182,43 +182,19 @@ uint32_t board_millis(void) {
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
-#if CFG_TUD_ENABLED && defined(BOARD_TUD_RHPORT)
- #define PORT_SUPPORT_DEVICE(_n) (BOARD_TUD_RHPORT == _n)
-#else
- #define PORT_SUPPORT_DEVICE(_n) 0
-#endif
-
-#if CFG_TUH_ENABLED && defined(BOARD_TUH_RHPORT)
- #define PORT_SUPPORT_HOST(_n) (BOARD_TUH_RHPORT == _n)
-#else
- #define PORT_SUPPORT_HOST(_n) 0
-#endif
-
//------------- USB0 FullSpeed -------------//
void usbfs_interrupt_handler(void) {
IRQn_Type irq = R_FSP_CurrentIrqGet();
R_BSP_IrqStatusClear(irq);
- #if PORT_SUPPORT_HOST(0)
- tuh_int_handler(0, true);
- #endif
-
- #if PORT_SUPPORT_DEVICE(0)
- tud_int_handler(0);
- #endif
+ tusb_int_handler(0, true);
}
void usbfs_resume_handler(void) {
IRQn_Type irq = R_FSP_CurrentIrqGet();
R_BSP_IrqStatusClear(irq);
- #if PORT_SUPPORT_HOST(0)
- tuh_int_handler(0, true);
- #endif
-
- #if PORT_SUPPORT_DEVICE(0)
- tud_int_handler(0);
- #endif
+ tusb_int_handler(0, true);
}
void usbfs_d0fifo_handler(void) {
@@ -240,13 +216,7 @@ void usbhs_interrupt_handler(void) {
IRQn_Type irq = R_FSP_CurrentIrqGet();
R_BSP_IrqStatusClear(irq);
- #if PORT_SUPPORT_HOST(1)
- tuh_int_handler(1, true);
- #endif
-
- #if PORT_SUPPORT_DEVICE(1)
- tud_int_handler(1);
- #endif
+ tusb_int_handler(1, true);
}
void usbhs_d0fifo_handler(void) {
diff --git a/hw/bsp/rp2040/family.c b/hw/bsp/rp2040/family.c
index 64a3a0af6..ccc1e1f70 100644
--- a/hw/bsp/rp2040/family.c
+++ b/hw/bsp/rp2040/family.c
@@ -205,7 +205,9 @@ size_t board_get_unique_id(uint8_t id[], size_t max_len) {
pico_get_unique_board_id(&pico_id);
size_t len = PICO_UNIQUE_BOARD_ID_SIZE_BYTES;
- if (len > max_len) len = max_len;
+ if (len > max_len) {
+ len = max_len;
+ }
memcpy(id, pico_id.id, len);
return len;
diff --git a/hw/bsp/stm32f4/boards/stm32f412disco/board.cmake b/hw/bsp/stm32f4/boards/stm32f412disco/board.cmake
index f9e834409..c282af98e 100644
--- a/hw/bsp/stm32f4/boards/stm32f412disco/board.cmake
+++ b/hw/bsp/stm32f4/boards/stm32f412disco/board.cmake
@@ -1,5 +1,6 @@
set(MCU_VARIANT stm32f412zx)
set(JLINK_DEVICE stm32f412zg)
+# set(JLINK_OPTION "-USB 000771775987")
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F412ZGTx_FLASH.ld)
diff --git a/hw/bsp/stm32f4/family.c b/hw/bsp/stm32f4/family.c
index fb0347aba..b4a661421 100644
--- a/hw/bsp/stm32f4/family.c
+++ b/hw/bsp/stm32f4/family.c
@@ -32,11 +32,11 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
void OTG_HS_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
//--------------------------------------------------------------------+
diff --git a/hw/bsp/stm32h7/family.c b/hw/bsp/stm32h7/family.c
index c81437958..6e4b388d6 100644
--- a/hw/bsp/stm32h7/family.c
+++ b/hw/bsp/stm32h7/family.c
@@ -36,32 +36,27 @@ TU_ATTR_UNUSED static void Error_Handler(void) {
#include "board.h"
//--------------------------------------------------------------------+
+// MACRO TYPEDEF CONSTANT ENUM
+//--------------------------------------------------------------------+
+
+UART_HandleTypeDef UartHandle;
+
+//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
// Despite being call USB2_OTG_FS on some MCUs
// OTG_FS is marked as RHPort0 by TinyUSB to be consistent across stm32 port
void OTG_FS_IRQHandler(void) {
- tud_int_handler(0);
+ tusb_int_handler(0, true);
}
// Despite being call USB1_OTG_HS on some MCUs
// OTG_HS is marked as RHPort1 by TinyUSB to be consistent across stm32 port
void OTG_HS_IRQHandler(void) {
- tud_int_handler(1);
+ tusb_int_handler(1, true);
}
-
-//--------------------------------------------------------------------+
-// MACRO TYPEDEF CONSTANT ENUM
-//--------------------------------------------------------------------+
-
-UART_HandleTypeDef UartHandle;
-
-//--------------------------------------------------------------------+
-//
-//--------------------------------------------------------------------+
-
#ifdef TRACE_ETM
void trace_etm_init(void) {
// H7 trace pin is PE2 to PE6
@@ -111,9 +106,10 @@ void board_init(void) {
SysTick->CTRL &= ~1U;
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
-#ifdef USB_OTG_FS_PERIPH_BASE
+ #ifdef USB_OTG_FS_PERIPH_BASE
NVIC_SetPriority(OTG_FS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
-#endif
+ #endif
+
NVIC_SetPriority(OTG_HS_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY );
#endif
@@ -206,13 +202,11 @@ void board_init(void) {
struct {
GPIO_TypeDef* port;
uint32_t pin;
- } const ulpi_pins[] =
- {
+ } const ulpi_pins[] = {
ULPI_PINS
};
- for (uint8_t i=0; i < sizeof(ulpi_pins)/sizeof(ulpi_pins[0]); i++)
- {
+ for (uint8_t i=0; i < sizeof(ulpi_pins)/sizeof(ulpi_pins[0]); i++) {
GPIO_InitStruct.Pin = ulpi_pins[i].pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;