94
94
#ifndef SD_HW_FLOW_CTRL
95
95
#define SD_HW_FLOW_CTRL SDMMC_HARDWARE_FLOW_CONTROL_DISABLE
96
96
#endif
97
+ #ifdef STM32H7xx
98
+ #define SD_CLK_DIV 1
99
+ #else
97
100
#define SD_CLK_DIV SDMMC_TRANSFER_CLK_DIV
101
+ #endif
98
102
/* Definition for MSP SD */
99
103
#define SD_AF GPIO_AF12_SDMMC1
100
104
#elif defined(SDIO )
112
116
#endif
113
117
#define SD_CLK_DIV SDIO_TRANSFER_CLK_DIV
114
118
/* Definition for MSP SD */
119
+ #ifndef STM32F1xx
115
120
#define SD_AF GPIO_AF12_SDIO
121
+ #endif
116
122
#else
117
123
#error "Unknown SD_INSTANCE"
118
124
#endif
119
125
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
+
120
132
/* BSP SD Private Variables */
121
133
static SD_HandleTypeDef uSdHandle ;
122
134
static uint32_t SD_detect_gpio_pin = GPIO_PIN_All ;
123
135
static GPIO_TypeDef * SD_detect_gpio_port = GPIOA ;
124
- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
136
+ #ifndef STM32L1xx
125
137
#define SD_OK HAL_OK
126
138
#define SD_TRANSFER_OK ((uint8_t)0x00)
127
139
#define SD_TRANSFER_BUSY ((uint8_t)0x01)
128
- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
140
+ #else /* STM32L1xx */
129
141
static SD_CardInfo uSdCardInfo ;
130
142
#endif
131
143
@@ -144,7 +156,9 @@ uint8_t BSP_SD_Init(void)
144
156
uSdHandle .Instance = SD_INSTANCE ;
145
157
146
158
uSdHandle .Init .ClockEdge = SD_CLK_EDGE ;
159
+ #ifndef STM32H7xx
147
160
uSdHandle .Init .ClockBypass = SD_CLK_BYPASS ;
161
+ #endif
148
162
uSdHandle .Init .ClockPowerSave = SD_CLK_PWR_SAVE ;
149
163
uSdHandle .Init .BusWide = SD_BUS_WIDE_1B ;
150
164
uSdHandle .Init .HardwareFlowControl = SD_HW_FLOW_CTRL ;
@@ -163,9 +177,9 @@ uint8_t BSP_SD_Init(void)
163
177
BSP_SD_MspInit (& uSdHandle , NULL );
164
178
165
179
/* HAL SD initialization */
166
- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
180
+ #ifndef STM32L1xx
167
181
if (HAL_SD_Init (& uSdHandle ) != SD_OK )
168
- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
182
+ #else /* STM32L1xx */
169
183
if (HAL_SD_Init (& uSdHandle , & uSdCardInfo ) != SD_OK )
170
184
#endif
171
185
{
@@ -240,7 +254,7 @@ uint8_t BSP_SD_ITConfig(void)
240
254
/* Configure Interrupt mode for SD detection pin */
241
255
gpio_init_structure .Pin = SD_detect_gpio_pin ;
242
256
gpio_init_structure .Pull = GPIO_PULLUP ;
243
- gpio_init_structure .Speed = GPIO_SPEED_FAST ;
257
+ gpio_init_structure .Speed = SD_GPIO_SPEED ;
244
258
gpio_init_structure .Mode = GPIO_MODE_IT_RISING_FALLING ;
245
259
HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
246
260
@@ -304,7 +318,7 @@ uint8_t BSP_SD_IsDetected(void)
304
318
status = SD_NOT_PRESENT ;
305
319
}
306
320
307
- return status ;
321
+ return status ;
308
322
}
309
323
310
324
/**
@@ -386,9 +400,10 @@ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
386
400
/* Common GPIO configuration */
387
401
gpio_init_structure .Mode = GPIO_MODE_AF_PP ;
388
402
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
390
405
gpio_init_structure .Alternate = SD_AF ;
391
-
406
+ #endif
392
407
/* GPIOC configuration */
393
408
gpio_init_structure .Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 ;
394
409
@@ -415,7 +430,7 @@ __weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
415
430
gpio_init_structure .Pin = SD_detect_gpio_pin ;
416
431
gpio_init_structure .Mode = GPIO_MODE_INPUT ;
417
432
gpio_init_structure .Pull = GPIO_PULLUP ;
418
- gpio_init_structure .Speed = GPIO_SPEED_HIGH ;
433
+ gpio_init_structure .Speed = SD_GPIO_SPEED ;
419
434
HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
420
435
}
421
436
@@ -428,8 +443,6 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
428
443
{
429
444
UNUSED (hsd );
430
445
UNUSED (Params );
431
- /* Disable NVIC for SDIO interrupts */
432
- HAL_NVIC_DisableIRQ (SDIO_IRQn );
433
446
434
447
/* DeInit GPIO pins can be done in the application
435
448
(by surcharging this __weak function) */
@@ -441,7 +454,7 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
441
454
by surcgarging this __weak function */
442
455
}
443
456
444
- #if defined ( STM32F4xx ) || defined( STM32F7xx ) || defined( STM32L4xx )
457
+ #ifndef STM32L1xx
445
458
/**
446
459
* @brief Gets the current SD card data status.
447
460
* @retval Data transfer state.
@@ -453,7 +466,7 @@ uint8_t BSP_SD_GetCardState(void)
453
466
{
454
467
return ((HAL_SD_GetCardState (& uSdHandle ) == HAL_SD_CARD_TRANSFER ) ? SD_TRANSFER_OK : SD_TRANSFER_BUSY );
455
468
}
456
- #else /* (STM32F1xx) || defined(STM32F2xx) || defined( STM32L1xx) */
469
+ #else /* STM32L1xx */
457
470
/**
458
471
* @brief Gets the current SD card data status.
459
472
* @retval Data transfer state.
0 commit comments