Skip to content

Commit 3cc7d32

Browse files
committed
bsp: stm32f407-micu: add SDIO support
1 parent 9370f81 commit 3cc7d32

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

bsp/stm32/stm32f407-micu/board/CubeMX_Config/Inc/stm32f4xx_hal_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/* #define HAL_RNG_MODULE_ENABLED */
6161
/* #define HAL_RTC_MODULE_ENABLED */
6262
/* #define HAL_SAI_MODULE_ENABLED */
63-
/* #define HAL_SD_MODULE_ENABLED */
63+
#define HAL_SD_MODULE_ENABLED
6464
/* #define HAL_MMC_MODULE_ENABLED */
6565
#define HAL_SPI_MODULE_ENABLED
6666
/* #define HAL_TIM_MODULE_ENABLED */

bsp/stm32/stm32f407-micu/board/CubeMX_Config/Src/stm32f4xx_hal_msp.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,90 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
211211

212212
}
213213

214+
/**
215+
* @brief SD MSP Initialization
216+
* This function configures the hardware resources used in this example
217+
* @param hsd: SD handle pointer
218+
* @retval None
219+
*/
220+
void HAL_SD_MspInit(SD_HandleTypeDef* hsd)
221+
{
222+
GPIO_InitTypeDef GPIO_InitStruct = {0};
223+
if(hsd->Instance==SDIO)
224+
{
225+
/* USER CODE BEGIN SDIO_MspInit 0 */
226+
227+
/* USER CODE END SDIO_MspInit 0 */
228+
/* Peripheral clock enable */
229+
__HAL_RCC_SDIO_CLK_ENABLE();
230+
231+
__HAL_RCC_GPIOC_CLK_ENABLE();
232+
__HAL_RCC_GPIOD_CLK_ENABLE();
233+
/**SDIO GPIO Configuration
234+
PC8 ------> SDIO_D0
235+
PC9 ------> SDIO_D1
236+
PC10 ------> SDIO_D2
237+
PC11 ------> SDIO_D3
238+
PC12 ------> SDIO_CK
239+
PD2 ------> SDIO_CMD
240+
*/
241+
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
242+
|GPIO_PIN_12;
243+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
244+
GPIO_InitStruct.Pull = GPIO_NOPULL;
245+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
246+
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
247+
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
248+
249+
GPIO_InitStruct.Pin = GPIO_PIN_2;
250+
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
251+
GPIO_InitStruct.Pull = GPIO_NOPULL;
252+
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
253+
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
254+
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
255+
256+
/* USER CODE BEGIN SDIO_MspInit 1 */
257+
258+
/* USER CODE END SDIO_MspInit 1 */
259+
}
260+
261+
}
262+
263+
/**
264+
* @brief SD MSP De-Initialization
265+
* This function freeze the hardware resources used in this example
266+
* @param hsd: SD handle pointer
267+
* @retval None
268+
*/
269+
void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd)
270+
{
271+
if(hsd->Instance==SDIO)
272+
{
273+
/* USER CODE BEGIN SDIO_MspDeInit 0 */
274+
275+
/* USER CODE END SDIO_MspDeInit 0 */
276+
/* Peripheral clock disable */
277+
__HAL_RCC_SDIO_CLK_DISABLE();
278+
279+
/**SDIO GPIO Configuration
280+
PC8 ------> SDIO_D0
281+
PC9 ------> SDIO_D1
282+
PC10 ------> SDIO_D2
283+
PC11 ------> SDIO_D3
284+
PC12 ------> SDIO_CK
285+
PD2 ------> SDIO_CMD
286+
*/
287+
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
288+
|GPIO_PIN_12);
289+
290+
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2);
291+
292+
/* USER CODE BEGIN SDIO_MspDeInit 1 */
293+
294+
/* USER CODE END SDIO_MspDeInit 1 */
295+
}
296+
297+
}
214298
/* USER CODE BEGIN 1 */
215299

216300
/* USER CODE END 1 */

bsp/stm32/stm32f407-micu/board/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ menu "On-chip Peripheral Drivers"
8888
select BSP_SPI2_TX_USING_DMA
8989
default n
9090
endif
91+
92+
config BSP_USING_SDIO
93+
bool "Enable SDIO"
94+
select RT_USING_SDIO
95+
select RT_USING_DFS
96+
default n
97+
98+
config SDIO_MAX_FREQ
99+
int "sdio max freq"
100+
range 0 24000000
101+
depends on BSP_USING_SDIO
102+
default 1000000
91103
source "$(BSP_DIR)/../libraries/HAL_Drivers/drivers/Kconfig"
92104

93105
endmenu

0 commit comments

Comments
 (0)