Skip to content

Commit e871e7d

Browse files
committed
Add sd card support -- sdioio module
1 parent 5c09d8b commit e871e7d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

ports/stm/boards/daisy_seed_with_sdram/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ MCU_PACKAGE = UFBGA176
1313
LD_COMMON = boards/common_tcm.ld
1414
LD_FILE = boards/STM32H750.ld
1515

16-
# CIRCUITPY_SDIOIO = 1
16+
CIRCUITPY_SDIOIO = 1

ports/stm/common-hal/sdioio/SDCard.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
104104
uint8_t num_data, const mcu_pin_obj_t **data, uint32_t frequency) {
105105

106106
int periph_index = check_pins(self, clock, command, num_data, data);
107+
#ifdef STM32H750xx
108+
SDMMC_TypeDef *SDMMCx = mcu_sdio_banks[periph_index - 1];
109+
#else
107110
SDIO_TypeDef *SDIOx = mcu_sdio_banks[periph_index - 1];
111+
#endif
108112

109113
GPIO_InitTypeDef GPIO_InitStruct = {0};
110114

@@ -128,6 +132,16 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
128132
GPIO_InitStruct.Pin = pin_mask(clock->number);
129133
HAL_GPIO_Init(pin_port(clock->port), &GPIO_InitStruct);
130134

135+
#ifdef STM32H750xx
136+
__HAL_RCC_SDMMC1_CLK_ENABLE();
137+
138+
self->handle.Init.ClockDiv = SDMMC_NSPEED_CLK_DIV;
139+
self->handle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
140+
self->handle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
141+
self->handle.Init.BusWide = SDMMC_BUS_WIDE_1B;
142+
self->handle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
143+
self->handle.Instance = SDMMCx;
144+
#else
131145
__HAL_RCC_SDIO_CLK_ENABLE();
132146

133147
self->handle.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
@@ -137,6 +151,7 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
137151
self->handle.Init.BusWide = SDIO_BUS_WIDE_1B;
138152
self->handle.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
139153
self->handle.Instance = SDIOx;
154+
#endif
140155

141156
HAL_StatusTypeDef r = HAL_SD_Init(&self->handle);
142157
if (r != HAL_OK) {
@@ -150,9 +165,14 @@ void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self,
150165
}
151166

152167
self->num_data = 1;
168+
#ifdef STM32H750xx
169+
uint32_t bus_wide_opt = SDMMC_BUS_WIDE_4B;
170+
#else
171+
uint32_t bus_wide_opt = SDIO_BUS_WIDE_4B;
172+
#endif
153173
if (num_data == 4) {
154-
if ((r = HAL_SD_ConfigWideBusOperation(&self->handle, SDIO_BUS_WIDE_4B)) == HAL_SD_ERROR_NONE) {
155-
self->handle.Init.BusWide = SDIO_BUS_WIDE_4B;
174+
if ((r = HAL_SD_ConfigWideBusOperation(&self->handle, bus_wide_opt)) == HAL_SD_ERROR_NONE) {
175+
self->handle.Init.BusWide = bus_wide_opt;
156176
self->num_data = 4;
157177
} else {
158178
}

0 commit comments

Comments
 (0)