From 27c31add9e2595d90a3504bed8186f5a6ba884cc Mon Sep 17 00:00:00 2001 From: Jie Feng Date: Thu, 24 Oct 2024 12:43:24 +0800 Subject: [PATCH] Support AT32F403A remap --- hw/bsp/at32f403a_407/family.c | 9 ++++++- src/portable/st/stm32_fsdev/fsdev_at32.h | 32 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/hw/bsp/at32f403a_407/family.c b/hw/bsp/at32f403a_407/family.c index c83e33dd9d..05378893fe 100644 --- a/hw/bsp/at32f403a_407/family.c +++ b/hw/bsp/at32f403a_407/family.c @@ -39,10 +39,17 @@ void USBFS_L_CAN1_RX0_IRQHandler(void) { tud_int_handler(0); } -void USBFSWakeUp_IRQHandler(void) { +void USBFS_MAPH_IRQHandler(void) { + tud_int_handler(0); +} + +void USBFS_MAPL_IRQHandler(void) { tud_int_handler(0); } +void USBFSWakeUp_IRQHandler(void) { + tud_int_handler(0); +} /** * @brief usb 48M clock select diff --git a/src/portable/st/stm32_fsdev/fsdev_at32.h b/src/portable/st/stm32_fsdev/fsdev_at32.h index a05d13f416..88f4823b01 100644 --- a/src/portable/st/stm32_fsdev/fsdev_at32.h +++ b/src/portable/st/stm32_fsdev/fsdev_at32.h @@ -59,15 +59,39 @@ enum { FSDEV_IRQ_NUM = TU_ARRAY_SIZE(fsdev_irq) }; void dcd_int_enable(uint8_t rhport) { (void)rhport; - for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { - NVIC_EnableIRQ(fsdev_irq[i]); + #if CFG_TUSB_MCU == OPT_MCU_AT32F403A_407 + // AT32F403A/407 devices allow to remap the USB interrupt vectors from + // shared USB/CAN IRQs to separate CAN and USB IRQs. + // This dynamically checks if this remap is active to enable the right IRQs. + if (CRM->intmap_bit.usbintmap) { + NVIC_DisableIRQ(USBFS_MAPH_IRQn); + NVIC_DisableIRQ(USBFS_MAPL_IRQn); + NVIC_DisableIRQ(USBFSWakeUp_IRQn); + } else + #endif + { + for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { + NVIC_EnableIRQ(fsdev_irq[i]); + } } } void dcd_int_disable(uint8_t rhport) { (void)rhport; - for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { - NVIC_DisableIRQ(fsdev_irq[i]); + #if CFG_TUSB_MCU == OPT_MCU_AT32F403A_407 + // AT32F403A/407 devices allow to remap the USB interrupt vectors from + // shared USB/CAN IRQs to separate CAN and USB IRQs. + // This dynamically checks if this remap is active to enable the right IRQs. + if (CRM->intmap_bit.usbintmap) { + NVIC_DisableIRQ(USBFS_MAPH_IRQn); + NVIC_DisableIRQ(USBFS_MAPL_IRQn); + NVIC_DisableIRQ(USBFSWakeUp_IRQn); + } else + #endif + { + for(uint8_t i=0; i < FSDEV_IRQ_NUM; i++) { + NVIC_DisableIRQ(fsdev_irq[i]); + } } }