summaryrefslogtreecommitdiff
path: root/ports/stm32/stm32_it.c
diff options
context:
space:
mode:
authorAndrew Leech <andrew.leech@planetinnovation.com.au>2025-10-28 16:20:31 +1100
committerDamien George <damien@micropython.org>2025-10-31 10:52:11 +1100
commit9bb266e31162ba80ec06a6bc9a6b94b9cbafa9b2 (patch)
treee0260ed1414475c9d8659e831f357e079472c4dc /ports/stm32/stm32_it.c
parent6b0e1c2701490260cb81bbe884f42a9c18bea020 (diff)
stm32/usb: Add support for using TinyUSB stack.
This commit adapts the stm32 port to allow switching from STM USB stack to TinyUSB stack. Using TinyUSB improves consistancy with other MicroPython ports and brings in the ability to use the runtime USB definition support recently added to other TinyUSB based ports. By default the existing STM USB stack is used. TinyUSB can be enabled in a board configuration with: #define MICROPY_HW_TINYUSB_STACK (1) Or, it can be enabled from the command line with: make -C ports/stm32 CFLAGS_EXTRA='-DMICROPY_HW_TINYUSB_STACK=1' Signed-off-by: Andrew Leech <andrew@alelec.net>
Diffstat (limited to 'ports/stm32/stm32_it.c')
-rw-r--r--ports/stm32/stm32_it.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c
index 470df4758..19778020d 100644
--- a/ports/stm32/stm32_it.c
+++ b/ports/stm32/stm32_it.c
@@ -80,7 +80,13 @@
#include "uart.h"
#include "storage.h"
#include "dma.h"
+
+#if MICROPY_HW_TINYUSB_STACK
+#include "tusb.h"
+#include "shared/tinyusb/mp_usbd.h"
+#else
#include "usb.h"
+#endif
#if defined(MICROPY_HW_USB_FS)
extern PCD_HandleTypeDef pcd_fs_handle;
@@ -145,7 +151,7 @@ void HardFault_C_Handler(ExceptionRegisters_t *regs) {
powerctrl_mcu_reset();
}
- #if MICROPY_HW_ENABLE_USB
+ #if MICROPY_HW_STM_USB_STACK
// We need to disable the USB so it doesn't try to write data out on
// the VCP and then block indefinitely waiting for the buffer to drain.
pyb_usb_flags = 0;
@@ -299,7 +305,11 @@ void DebugMon_Handler(void) {
#if MICROPY_HW_USB_FS
void USB_UCPD1_2_IRQHandler(void) {
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_fs_handle);
+ #endif
}
#endif
@@ -307,7 +317,11 @@ void USB_UCPD1_2_IRQHandler(void) {
#if MICROPY_HW_USB_FS
void USB_DRD_FS_IRQHandler(void) {
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_fs_handle);
+ #endif
}
#endif
@@ -315,7 +329,11 @@ void USB_DRD_FS_IRQHandler(void) {
#if MICROPY_HW_USB_FS
void USB_IRQHandler(void) {
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_fs_handle);
+ #endif
}
#endif
@@ -323,7 +341,11 @@ void USB_IRQHandler(void) {
#if MICROPY_HW_USB_FS
void USB_LP_IRQHandler(void) {
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_fs_handle);
+ #endif
}
#endif
@@ -337,7 +359,11 @@ void USB_LP_IRQHandler(void) {
#if MICROPY_HW_USB_FS
void OTG_FS_IRQHandler(void) {
IRQ_ENTER(OTG_FS_IRQn);
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_fs_handle);
+ #endif
IRQ_EXIT(OTG_FS_IRQn);
}
#endif
@@ -345,13 +371,21 @@ void OTG_FS_IRQHandler(void) {
#if defined(STM32N6)
void USB1_OTG_HS_IRQHandler(void) {
IRQ_ENTER(USB1_OTG_HS_IRQn);
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_hs_handle);
+ #endif
IRQ_EXIT(USB1_OTG_HS_IRQn);
}
#else
void OTG_HS_IRQHandler(void) {
IRQ_ENTER(OTG_HS_IRQn);
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #else
HAL_PCD_IRQHandler(&pcd_hs_handle);
+ #endif
IRQ_EXIT(OTG_HS_IRQn);
}
#endif
@@ -414,6 +448,9 @@ static void OTG_CMD_WKUP_Handler(PCD_HandleTypeDef *pcd_handle) {
/* ungate PHY clock */
__HAL_PCD_UNGATE_PHYCLOCK(pcd_handle);
}
+ #if MICROPY_HW_TINYUSB_STACK
+ tud_int_handler(0);
+ #endif
}
#endif