From 746e2c985a912ecbeb841877f20f062a432d7324 Mon Sep 17 00:00:00 2001 From: Yuuki NAGAO Date: Sun, 1 Feb 2026 17:14:59 +0900 Subject: [PATCH] stm32: Update STM32U5 suppport. Add USB FS configuration to enable for STM32U5. Signed-off-by: Yuuki NAGAO --- ports/stm32/stm32_it.c | 2 +- ports/stm32/system_stm32.c | 9 ++++++++- ports/stm32/usbd_conf.c | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ports/stm32/stm32_it.c b/ports/stm32/stm32_it.c index 17b9532646..3ae1980f8f 100644 --- a/ports/stm32/stm32_it.c +++ b/ports/stm32/stm32_it.c @@ -470,7 +470,7 @@ void OTG_FS_WKUP_IRQHandler(void) { #if defined(STM32L4) EXTI->PR1 = USB_OTG_FS_WAKEUP_EXTI_LINE; - #elif !defined(STM32H5) && !defined(STM32H7) + #elif !defined(STM32H5) && !defined(STM32H7) && !defined(STM32U5) /* Clear EXTI pending Bit*/ __HAL_USB_FS_EXTI_CLEAR_FLAG(); #endif diff --git a/ports/stm32/system_stm32.c b/ports/stm32/system_stm32.c index 5386771991..35771f53eb 100644 --- a/ports/stm32/system_stm32.c +++ b/ports/stm32/system_stm32.c @@ -193,10 +193,12 @@ MP_WEAK void SystemClock_Config(void) { // H7 MCUs without SMPS, lock the power supply configuration update. MODIFY_REG(PWR->CR3, PWR_CR3_SCUEN, 0); #elif defined(STM32U5) + #if defined(STM32U5A5xx) HAL_PWREx_DisableUCPDDeadBattery(); if (HAL_PWREx_ConfigSupply(PWR_SMPS_SUPPLY) != HAL_OK) { MICROPY_BOARD_FATAL_ERROR("HAL_PWREx_ConfigSupply"); } + #endif #else // other MCUs, enable power control clock. __PWR_CLK_ENABLE(); @@ -565,9 +567,14 @@ MP_WEAK void SystemClock_Config(void) { PeriphClkInitStruct.AdcDacClockSelection = RCC_ADCDACCLKSOURCE_HSE; PeriphClkInitStruct.Dac1ClockSelection = RCC_DAC1CLKSOURCE_LSE; #endif - #if defined(MICROPY_HW_ENABLE_USB) + #if defined(MICROPY_HW_ENABLE_USB) && (MICROPY_HW_ENABLE_USB) + #if defined(STM32U5A5xx) PeriphClkInitStruct.PeriphClockSelection |= RCC_PERIPHCLK_USBPHY; PeriphClkInitStruct.UsbPhyClockSelection = RCC_USBPHYCLKSOURCE_PLL1; + #elif defined(STM32U585xx) + PeriphClkInitStruct.PeriphClockSelection |= RCC_PERIPHCLK_CLK48; + PeriphClkInitStruct.IclkClockSelection = RCC_CLK48CLKSOURCE_HSI48; + #endif #endif #if defined(MICROPY_HW_RCC_RTC_CLKSOURCE) diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index d481aec1e4..5040ab2889 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -98,7 +98,7 @@ static void mp_usbd_ll_init_fs(void) { const uint32_t otg_alt = GPIO_AF0_USB; #elif defined(STM32L432xx) || defined(STM32L452xx) const uint32_t otg_alt = GPIO_AF10_USB_FS; - #elif defined(STM32H5) || defined(STM32WB) + #elif defined(STM32H5) || defined(STM32U5) || defined(STM32WB) const uint32_t otg_alt = GPIO_AF10_USB; #else const uint32_t otg_alt = GPIO_AF10_OTG_FS; @@ -139,7 +139,7 @@ static void mp_usbd_ll_init_fs(void) { // Enable VDDUSB #if defined(STM32H5) || defined(STM32WB) HAL_PWREx_EnableVddUSB(); - #elif defined(STM32L4) + #elif defined(STM32L4) || defined(STM32U5) if (__HAL_RCC_PWR_IS_CLK_DISABLED()) { __HAL_RCC_PWR_CLK_ENABLE(); HAL_PWREx_EnableVddUSB();