diff --git a/ports/stm/Makefile b/ports/stm/Makefile index 37924d78d25a..5acefd8d7c5b 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -134,7 +134,6 @@ SRC_STM32 = $(addprefix $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_,\ hal_gpio.c \ hal_i2c.c \ hal_i2c_ex.c \ - hal_ospi.c \ hal_pcd.c \ hal_pcd_ex.c \ hal_pwr.c \ @@ -173,6 +172,10 @@ ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F765xx STM32F767xx STM32F769xx SRC_STM32 += $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_hal_uart_ex.c endif +ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32H723xx)) + SRC_STM32 += $(HAL_DIR)/Src/stm32$(MCU_SERIES_LOWER)xx_hal_ospi.c +endif + SRC_STM32 += boards/system_stm32$(MCU_SERIES_LOWER)xx.c SRC_C += \ diff --git a/ports/stm/boards/weact-h723vg-lcd/mpconfigboard.mk b/ports/stm/boards/weact-h723vg-lcd/mpconfigboard.mk index c773389330c8..2300c7eb02b4 100644 --- a/ports/stm/boards/weact-h723vg-lcd/mpconfigboard.mk +++ b/ports/stm/boards/weact-h723vg-lcd/mpconfigboard.mk @@ -36,6 +36,7 @@ CIRCUITPY_AUDIOIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 1 CIRCUITPY_SDCARDIO = 1 +CIRCUITPY_SDIOIO = 1 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CTARGET = 0 diff --git a/ports/stm/common-hal/sdioio/SDCard.c b/ports/stm/common-hal/sdioio/SDCard.c index ab0f8bb7dfce..bf9d0d6f2c60 100644 --- a/ports/stm/common-hal/sdioio/SDCard.c +++ b/ports/stm/common-hal/sdioio/SDCard.c @@ -104,7 +104,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, uint8_t num_data, const mcu_pin_obj_t **data, uint32_t frequency) { int periph_index = check_pins(self, clock, command, num_data, data); - SDIO_TypeDef *SDIOx = mcu_sdio_banks[periph_index - 1]; + SD_TypeDef *SDIOx = mcu_sdio_banks[periph_index - 1]; GPIO_InitTypeDef GPIO_InitStruct = {0}; @@ -128,14 +128,22 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, GPIO_InitStruct.Pin = pin_mask(clock->number); HAL_GPIO_Init(pin_port(clock->port), &GPIO_InitStruct); + #if CPY_STM32H7 + __HAL_RCC_SDMMC1_CLK_ENABLE(); + self->handle.Init.ClockDiv = SDMMC_NSPEED_CLK_DIV; + self->handle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; + self->handle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; + self->handle.Init.BusWide = SDMMC_BUS_WIDE_1B; + self->handle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE; + #else __HAL_RCC_SDIO_CLK_ENABLE(); - self->handle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV; self->handle.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; self->handle.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; self->handle.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; self->handle.Init.BusWide = SDIO_BUS_WIDE_1B; self->handle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; + #endif self->handle.Instance = SDIOx; HAL_StatusTypeDef r = HAL_SD_Init(&self->handle); @@ -149,6 +157,15 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, mp_raise_ValueError_varg(MP_ERROR_TEXT("SDIO GetCardInfo Error %d"), (int)r); } + #if CPY_STM32H7 + self->num_data = 1; + if (num_data == 4) { + if ((r = HAL_SD_ConfigWideBusOperation(&self->handle, SDMMC_BUS_WIDE_4B)) == HAL_SD_ERROR_NONE) { + self->handle.Init.BusWide = SDMMC_BUS_WIDE_4B; + self->num_data = 4; + } + } + #else self->num_data = 1; if (num_data == 4) { if ((r = HAL_SD_ConfigWideBusOperation(&self->handle, SDIO_BUS_WIDE_4B)) == HAL_SD_ERROR_NONE) { @@ -157,6 +174,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, } else { } } + #endif self->capacity = info.BlockNbr * (info.BlockSize / 512); self->frequency = 25000000; diff --git a/ports/stm/peripherals/stm32h7/clocks.c b/ports/stm/peripherals/stm32h7/clocks.c index 701ee2e90ef5..b33497d3740e 100644 --- a/ports/stm/peripherals/stm32h7/clocks.c +++ b/ports/stm/peripherals/stm32h7/clocks.c @@ -14,6 +14,7 @@ #endif #ifdef STM32H723xx #include "stm32h7/stm32h723xx/clocks.h" +#define RCC_PERIPHCLK_QSPI RCC_PERIPHCLK_OSPI #endif void stm32_peripherals_clocks_init(void) { @@ -79,7 +80,7 @@ void stm32_peripherals_clocks_init(void) { // Set up non-bus peripherals // TODO: I2S settings go here PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC | RCC_PERIPHCLK_USART3 - | RCC_PERIPHCLK_USB | RCC_PERIPHCLK_OSPI; + | RCC_PERIPHCLK_USB | RCC_PERIPHCLK_QSPI; #if (BOARD_HAS_LOW_SPEED_CRYSTAL) PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; #else @@ -99,12 +100,18 @@ void stm32_peripherals_clocks_init(void) { PeriphClkInitStruct.PLL2.PLL2RGE = RCC_PLL2VCIRANGE_3; PeriphClkInitStruct.PLL2.PLL2VCOSEL = RCC_PLL2VCOWIDE; PeriphClkInitStruct.PLL2.PLL2FRACN = 0; + #ifdef RCC_OSPICLKSOURCE_PLL2 PeriphClkInitStruct.OspiClockSelection = RCC_OSPICLKSOURCE_PLL2; + #else + PeriphClkInitStruct.QspiClockSelection = RCC_QSPICLKSOURCE_PLL2; + #endif HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); + #ifdef __HAL_RCC_OSPI1_CLK_ENABLE /* OCTOSPI1 clock enable */ __HAL_RCC_OCTOSPIM_CLK_ENABLE(); __HAL_RCC_OSPI1_CLK_ENABLE(); + #endif // Enable USB Voltage detector HAL_PWREx_EnableUSBVoltageDetector(); diff --git a/ports/stm/peripherals/stm32h7/stm32h723xx/periph.c b/ports/stm/peripherals/stm32h7/stm32h723xx/periph.c index 0a72cbd549a4..018989a2cd0d 100644 --- a/ports/stm/peripherals/stm32h7/stm32h723xx/periph.c +++ b/ports/stm/peripherals/stm32h7/stm32h723xx/periph.c @@ -238,3 +238,25 @@ const mcu_tim_pin_obj_t mcu_tim_pin_list[58] = { TIM(8, 3, 3, &pin_PK00), TIM(1, 1, 1, &pin_PK01), }; + +// SDIO +SDMMC_TypeDef *mcu_sdio_banks[1] = {SDMMC1}; + +const mcu_periph_obj_t mcu_sdio_clock_list[1] = { + PERIPH(1, 12, &pin_PC12), +}; +const mcu_periph_obj_t mcu_sdio_command_list[1] = { + PERIPH(1, 12, &pin_PD02), +}; +const mcu_periph_obj_t mcu_sdio_data0_list[1] = { + PERIPH(1, 12, &pin_PC08), +}; +const mcu_periph_obj_t mcu_sdio_data1_list[1] = { + PERIPH(1, 12, &pin_PC09), +}; +const mcu_periph_obj_t mcu_sdio_data2_list[1] = { + PERIPH(1, 12, &pin_PC10), +}; +const mcu_periph_obj_t mcu_sdio_data3_list[1] = { + PERIPH(1, 12, &pin_PC11), +}; diff --git a/ports/stm/peripherals/stm32h7/stm32h723xx/periph.h b/ports/stm/peripherals/stm32h7/stm32h723xx/periph.h index d155ca40387a..983ccf708fd4 100644 --- a/ports/stm/peripherals/stm32h7/stm32h723xx/periph.h +++ b/ports/stm/peripherals/stm32h7/stm32h723xx/periph.h @@ -31,3 +31,13 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[26]; #define TIM_PIN_ARRAY_LEN 58 extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN]; extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; + +// SDIO +extern SDMMC_TypeDef *mcu_sdio_banks[1]; + +extern const mcu_periph_obj_t mcu_sdio_clock_list[1]; +extern const mcu_periph_obj_t mcu_sdio_command_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data0_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data1_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data2_list[1]; +extern const mcu_periph_obj_t mcu_sdio_data3_list[1]; diff --git a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.c b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.c index afea41445481..0a72cbd549a4 100644 --- a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.c +++ b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.c @@ -175,8 +175,8 @@ const mcu_periph_obj_t mcu_uart_rx_list[26] = { // Timers // TIM6 and TIM7 are basic timers that are only used by DAC, and don't have pins // TODO: H7 has more timers than this, but are they tied to pins? -TIM_TypeDef *mcu_tim_banks[14] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, NULL, NULL, - NULL, TIM12, TIM13, TIM14}; +TIM_TypeDef *mcu_tim_banks[17] = {TIM1, TIM2, TIM3, TIM4, TIM5, NULL, NULL, TIM8, NULL, NULL, + NULL, TIM12, TIM13, TIM14, TIM15, TIM16, TIM17}; const mcu_tim_pin_obj_t mcu_tim_pin_list[58] = { TIM(2, 1, 1, &pin_PA00), diff --git a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h index fa4ec7f6e562..d155ca40387a 100644 --- a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h +++ b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h @@ -27,6 +27,7 @@ extern const mcu_periph_obj_t mcu_uart_tx_list[25]; extern const mcu_periph_obj_t mcu_uart_rx_list[26]; // Timers -#define TIM_BANK_ARRAY_LEN 14 +#define TIM_BANK_ARRAY_LEN 17 #define TIM_PIN_ARRAY_LEN 58 extern TIM_TypeDef *mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; diff --git a/ports/stm/supervisor/usb.c b/ports/stm/supervisor/usb.c index f957d4a9564c..cf3151cd8cce 100644 --- a/ports/stm/supervisor/usb.c +++ b/ports/stm/supervisor/usb.c @@ -13,34 +13,38 @@ #include "common-hal/microcontroller/Pin.h" +#ifndef USB_OTG_FS +#define USB_OTG_FS USB_OTG_HS +#endif + static void init_usb_vbus_sense(void) { #if (BOARD_NO_VBUS_SENSE) // Disable VBUS sensing #ifdef USB_OTG_GCCFG_VBDEN // Deactivate VBUS Sensing B - USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN; + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN; #if (BOARD_NO_USB_OTG_ID_SENSE) - USB_OTG_HS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD; - USB_OTG_HS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; + USB_OTG_FS->GUSBCFG &= ~USB_OTG_GUSBCFG_FHMOD; + USB_OTG_FS->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD; #endif // B-peripheral session valid override enable - USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN; - USB_OTG_HS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL; + USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN; + USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL; #else - USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; - USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; #endif #else // Enable VBUS hardware sensing #ifdef USB_OTG_GCCFG_VBDEN - USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN; #else - USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; - USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; // B Device sense + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; // B Device sense #endif #endif }