diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index fa0f1c5eb42c..49b5f6f114f6 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -437,14 +437,10 @@ HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_,\ ) endif -ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),g0 g4)) -HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_fdcan.c) -endif - -ifeq ($(CMSIS_MCU),$(filter $(CMSIS_MCU),STM32H743xx STM32H747xx STM32H750xx STM32H7A3xx STM32H7A3xxQ STM32H7B3xx STM32H7B3xxQ)) -HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_fdcan.c) -else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 f4 f7 h7)) +ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),f0 f4 f7)) HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_can.c) +else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),g0 g4 h7)) +HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/stm32$(MCU_SERIES)xx_, hal_fdcan.c) else ifeq ($(MCU_SERIES),$(filter $(MCU_SERIES),l4)) HAL_SRC_C += $(addprefix $(STM32LIB_HAL_BASE)/Src/Legacy/stm32$(MCU_SERIES)xx_, hal_can.c) $(BUILD)/$(STM32LIB_HAL_BASE)/Src/Legacy/stm32$(MCU_SERIES)xx_hal_can.o: CFLAGS += -Wno-error=cpp diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c index 2df1bde19aa4..ba09c612d7cf 100644 --- a/ports/stm32/adc.c +++ b/ports/stm32/adc.c @@ -160,7 +160,8 @@ #define VBAT_DIV (4) #elif defined(STM32G0) || defined(STM32G4) #define VBAT_DIV (3) -#elif defined(STM32H743xx) || defined(STM32H747xx) || \ +#elif defined(STM32H723xx) || defined(STM32H733xx) || \ + defined(STM32H743xx) || defined(STM32H747xx) || \ defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || \ defined(STM32H7B3xx) || defined(STM32H7B3xxQ) || \ defined(STM32H750xx) diff --git a/ports/stm32/flash.c b/ports/stm32/flash.c index 16af49c3cfb8..2cc6c390ba01 100644 --- a/ports/stm32/flash.c +++ b/ports/stm32/flash.c @@ -133,7 +133,14 @@ static const flash_layout_t flash_layout[] = { #error Unsupported processor #endif -#if (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32H7) +#if defined(STM32H723xx) + +// get the bank of a given flash address +static uint32_t get_bank(uint32_t addr) { + return FLASH_BANK_1; +} + +#elif (defined(STM32L4) && defined(SYSCFG_MEMRMP_FB_MODE)) || defined(STM32H7) // get the bank of a given flash address static uint32_t get_bank(uint32_t addr) { diff --git a/ports/stm32/machine_adc.c b/ports/stm32/machine_adc.c index 1a478cd1cffb..34319e975332 100644 --- a/ports/stm32/machine_adc.c +++ b/ports/stm32/machine_adc.c @@ -315,7 +315,13 @@ STATIC void adc_config_channel(ADC_TypeDef *adc, uint32_t channel, uint32_t samp #if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) ADC_Common_TypeDef *adc_common = ADC12_COMMON; #elif defined(STM32H7) + #if defined(ADC_VER_V5_V90) + if (adc != ADC3) { + adc->PCSEL_RES0 |= 1 << channel; + } + #else adc->PCSEL |= 1 << channel; + #endif ADC_Common_TypeDef *adc_common = adc == ADC3 ? ADC3_COMMON : ADC12_COMMON; #elif defined(STM32L4) ADC_Common_TypeDef *adc_common = ADCx_COMMON; diff --git a/ports/stm32/main.c b/ports/stm32/main.c index 511da7d8afb6..e5ad14fcf770 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -379,8 +379,10 @@ void stm32_main(uint32_t reset_mode) { // Enable D2 SRAM1/2/3 clocks. __HAL_RCC_D2SRAM1_CLK_ENABLE(); __HAL_RCC_D2SRAM2_CLK_ENABLE(); + #if defined(__HAL_RCC_D2SRAM3_CLK_ENABLE) __HAL_RCC_D2SRAM3_CLK_ENABLE(); #endif + #endif MICROPY_BOARD_EARLY_INIT(); diff --git a/ports/stm32/powerctrl.c b/ports/stm32/powerctrl.c index 498fb79d71c8..0ab80b487a67 100644 --- a/ports/stm32/powerctrl.c +++ b/ports/stm32/powerctrl.c @@ -33,11 +33,9 @@ #if defined(STM32H7) #define RCC_SR RSR -#if defined(STM32H743xx) || defined(STM32H750xx) -#define RCC_SR_SFTRSTF RCC_RSR_SFTRSTF -#elif defined(STM32H747xx) +#if defined(STM32H747xx) #define RCC_SR_SFTRSTF RCC_RSR_SFT2RSTF -#elif defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) +#else #define RCC_SR_SFTRSTF RCC_RSR_SFTRSTF #endif #define RCC_SR_RMVF RCC_RSR_RMVF @@ -48,6 +46,8 @@ defined(STM32H7B3xx) || defined(STM32H7B3xxQ) // TODO #define POWERCTRL_GET_VOLTAGE_SCALING() PWR_REGULATOR_VOLTAGE_SCALE0 +#elif defined(STM32H723xx) +#define POWERCTRL_GET_VOLTAGE_SCALING() LL_PWR_GetRegulVoltageScaling() #else #define POWERCTRL_GET_VOLTAGE_SCALING() \ (((PWR->CSR1 & PWR_CSR1_ACTVOS) && (SYSCFG->PWRCR & SYSCFG_PWRCR_ODEN)) ? \ diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index d0f519d45670..b6880da2d618 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -135,6 +135,26 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { if (hpcd->Instance == USB_OTG_HS) { #if MICROPY_HW_USB_HS_IN_FS + // Configure USB GPIO's. + + #if defined(STM32H723xx) + + // These MCUs don't have an alternate function for USB but rather require + // the pins to be disconnected from all peripherals, ie put in analog mode. + + #if defined(MICROPY_HW_USB_OTG_ID_PIN) + const uint32_t otg_alt = GPIO_AF10_OTG1_FS; + #endif + + mp_hal_pin_config(pin_A11, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0); + mp_hal_pin_config_speed(pin_A11, GPIO_SPEED_FREQ_VERY_HIGH); + mp_hal_pin_config(pin_A12, MP_HAL_PIN_MODE_ANALOG, MP_HAL_PIN_PULL_NONE, 0); + mp_hal_pin_config_speed(pin_A12, GPIO_SPEED_FREQ_VERY_HIGH); + + #else + + // Other MCUs have an alternate function for GPIO's to be in USB mode. + #if defined(STM32H7A3xx) || defined(STM32H7A3xxQ) || defined(STM32H7B3xx) || defined(STM32H7B3xxQ) const uint32_t otg_alt = GPIO_AF10_OTG1_FS; #elif defined(STM32H7) @@ -143,12 +163,13 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { const uint32_t otg_alt = GPIO_AF12_OTG_HS_FS; #endif - // Configure USB FS GPIOs mp_hal_pin_config(pin_B14, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, otg_alt); mp_hal_pin_config_speed(pin_B14, GPIO_SPEED_FREQ_VERY_HIGH); mp_hal_pin_config(pin_B15, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_NONE, otg_alt); mp_hal_pin_config_speed(pin_B15, GPIO_SPEED_FREQ_VERY_HIGH); + #endif + #if defined(MICROPY_HW_USB_VBUS_DETECT_PIN) // Configure VBUS Pin mp_hal_pin_config(MICROPY_HW_USB_VBUS_DETECT_PIN, MP_HAL_PIN_MODE_INPUT, MP_HAL_PIN_PULL_NONE, 0);