9494#ifndef SD_HW_FLOW_CTRL
9595#define SD_HW_FLOW_CTRL SDMMC_HARDWARE_FLOW_CONTROL_DISABLE
9696#endif
97+ #ifdef STM32H7xx
98+ #define SD_CLK_DIV 1
99+ #else
97100#define SD_CLK_DIV SDMMC_TRANSFER_CLK_DIV
101+ #endif
98102/* Definition for MSP SD */
99103#define SD_AF GPIO_AF12_SDMMC1
100104#elif defined(SDIO )
112116#endif
113117#define SD_CLK_DIV SDIO_TRANSFER_CLK_DIV
114118/* Definition for MSP SD */
119+ #ifndef STM32F1xx
115120#define SD_AF GPIO_AF12_SDIO
121+ #endif
116122#else
117123#error "Unknown SD_INSTANCE"
118124#endif
119125
126+ #ifdef GPIO_SPEED_FREQ_VERY_HIGH
127+ #define SD_GPIO_SPEED GPIO_SPEED_FREQ_VERY_HIGH
128+ #else
129+ #define SD_GPIO_SPEED GPIO_SPEED_FREQ_HIGH
130+ #endif
131+
120132/* BSP SD Private Variables */
121133static SD_HandleTypeDef uSdHandle ;
122134static uint32_t SD_detect_gpio_pin = GPIO_PIN_All ;
123135static GPIO_TypeDef * SD_detect_gpio_port = GPIOA ;
124- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
136+ #ifndef STM32L1xx
125137#define SD_OK HAL_OK
126138#define SD_TRANSFER_OK ((uint8_t)0x00)
127139#define SD_TRANSFER_BUSY ((uint8_t)0x01)
128- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
140+ #else /* STM32L1xx */
129141static SD_CardInfo uSdCardInfo ;
130142#endif
131143
@@ -144,7 +156,9 @@ uint8_t BSP_SD_Init(void)
144156 uSdHandle .Instance = SD_INSTANCE ;
145157
146158 uSdHandle .Init .ClockEdge = SD_CLK_EDGE ;
159+ #ifndef STM32H7xx
147160 uSdHandle .Init .ClockBypass = SD_CLK_BYPASS ;
161+ #endif
148162 uSdHandle .Init .ClockPowerSave = SD_CLK_PWR_SAVE ;
149163 uSdHandle .Init .BusWide = SD_BUS_WIDE_1B ;
150164 uSdHandle .Init .HardwareFlowControl = SD_HW_FLOW_CTRL ;
@@ -163,9 +177,9 @@ uint8_t BSP_SD_Init(void)
163177 BSP_SD_MspInit (& uSdHandle , NULL );
164178
165179 /* HAL SD initialization */
166- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
180+ #ifndef STM32L1xx
167181 if (HAL_SD_Init (& uSdHandle ) != SD_OK )
168- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
182+ #else /* STM32L1xx */
169183 if (HAL_SD_Init (& uSdHandle , & uSdCardInfo ) != SD_OK )
170184#endif
171185 {
@@ -240,7 +254,7 @@ uint8_t BSP_SD_ITConfig(void)
240254 /* Configure Interrupt mode for SD detection pin */
241255 gpio_init_structure .Pin = SD_detect_gpio_pin ;
242256 gpio_init_structure .Pull = GPIO_PULLUP ;
243- gpio_init_structure .Speed = GPIO_SPEED_FAST ;
257+ gpio_init_structure .Speed = SD_GPIO_SPEED ;
244258 gpio_init_structure .Mode = GPIO_MODE_IT_RISING_FALLING ;
245259 HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
246260
@@ -304,7 +318,7 @@ uint8_t BSP_SD_IsDetected(void)
304318 status = SD_NOT_PRESENT ;
305319 }
306320
307- return status ;
321+ return status ;
308322}
309323
310324/**
@@ -386,9 +400,10 @@ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
386400 /* Common GPIO configuration */
387401 gpio_init_structure .Mode = GPIO_MODE_AF_PP ;
388402 gpio_init_structure .Pull = GPIO_PULLUP ;
389- gpio_init_structure .Speed = GPIO_SPEED_HIGH ;
403+ gpio_init_structure .Speed = SD_GPIO_SPEED ;
404+ #ifndef STM32F1xx
390405 gpio_init_structure .Alternate = SD_AF ;
391-
406+ #endif
392407 /* GPIOC configuration */
393408 gpio_init_structure .Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 ;
394409
@@ -415,7 +430,7 @@ __weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
415430 gpio_init_structure .Pin = SD_detect_gpio_pin ;
416431 gpio_init_structure .Mode = GPIO_MODE_INPUT ;
417432 gpio_init_structure .Pull = GPIO_PULLUP ;
418- gpio_init_structure .Speed = GPIO_SPEED_HIGH ;
433+ gpio_init_structure .Speed = SD_GPIO_SPEED ;
419434 HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
420435}
421436
@@ -428,8 +443,6 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
428443{
429444 UNUSED (hsd );
430445 UNUSED (Params );
431- /* Disable NVIC for SDIO interrupts */
432- HAL_NVIC_DisableIRQ (SDIO_IRQn );
433446
434447 /* DeInit GPIO pins can be done in the application
435448 (by surcharging this __weak function) */
@@ -441,7 +454,7 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
441454 by surcgarging this __weak function */
442455}
443456
444- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
457+ #ifndef STM32L1xx
445458/**
446459 * @brief Gets the current SD card data status.
447460 * @retval Data transfer state.
@@ -453,7 +466,7 @@ uint8_t BSP_SD_GetCardState(void)
453466{
454467 return ((HAL_SD_GetCardState (& uSdHandle ) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY );
455468}
456- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
469+ #else /* STM32L1xx */
457470/**
458471 * @brief Gets the current SD card data status.
459472 * @retval Data transfer state.
0 commit comments