35
35
36
36
/* Includes ------------------------------------------------------------------*/
37
37
#include "bsp_sd.h"
38
+ #include "interrupt.h"
38
39
#include "PeripheralPins.h"
40
+ #include "stm32yyxx_ll_gpio.h"
39
41
40
42
#ifdef SDMMC1
41
43
/* Definition for BSP SD */
75
77
76
78
/* BSP SD Private Variables */
77
79
static SD_HandleTypeDef uSdHandle ;
78
- static uint32_t SD_detect_gpio_pin = GPIO_PIN_All ;
80
+ static uint32_t SD_detect_ll_gpio_pin = LL_GPIO_PIN_ALL ;
79
81
static GPIO_TypeDef * SD_detect_gpio_port = GPIOA ;
80
82
#ifndef STM32L1xx
81
83
#define SD_OK HAL_OK
@@ -106,7 +108,7 @@ uint8_t BSP_SD_Init(void)
106
108
uSdHandle .Init .HardwareFlowControl = SD_HW_FLOW_CTRL ;
107
109
uSdHandle .Init .ClockDiv = SD_CLK_DIV ;
108
110
109
- if (SD_detect_gpio_pin != GPIO_PIN_All ) {
111
+ if (SD_detect_ll_gpio_pin != LL_GPIO_PIN_ALL ) {
110
112
/* Msp SD Detect pin initialization */
111
113
BSP_SD_Detect_MspInit (& uSdHandle , NULL );
112
114
if (BSP_SD_IsDetected () != SD_PRESENT ) { /* Check if SD card is present */
@@ -170,7 +172,7 @@ uint8_t BSP_SD_DeInit(void)
170
172
uint8_t BSP_SD_DetectPin (GPIO_TypeDef * port , uint32_t pin )
171
173
{
172
174
if (port != 0 ) {
173
- SD_detect_gpio_pin = pin ;
175
+ SD_detect_ll_gpio_pin = pin ;
174
176
SD_detect_gpio_port = port ;
175
177
return MSD_OK ;
176
178
}
@@ -181,61 +183,67 @@ uint8_t BSP_SD_DetectPin(GPIO_TypeDef *port, uint32_t pin)
181
183
* @brief Configures Interrupt mode for SD detection pin.
182
184
* @retval Status
183
185
*/
184
- uint8_t BSP_SD_DetectITConfig (void )
186
+ uint8_t BSP_SD_DetectITConfig (void ( * callback )( void ) )
185
187
{
186
- uint8_t sd_state = MSD_OK ;
187
- GPIO_InitTypeDef gpio_init_structure ;
188
- IRQn_Type sd_detect_EXTI_IRQn = EXTI0_IRQn ;
189
-
190
- /* Configure Interrupt mode for SD detection pin */
191
- gpio_init_structure .Pin = SD_detect_gpio_pin ;
192
- gpio_init_structure .Pull = GPIO_PULLUP ;
193
- gpio_init_structure .Speed = SD_GPIO_SPEED ;
194
- gpio_init_structure .Mode = GPIO_MODE_IT_RISING_FALLING ;
195
- HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
196
-
197
- if (SD_detect_gpio_pin == GPIO_PIN_0 ) {
198
- sd_detect_EXTI_IRQn = EXTI0_IRQn ;
199
- } else {
200
- if (SD_detect_gpio_pin == GPIO_PIN_1 ) {
201
- sd_detect_EXTI_IRQn = EXTI1_IRQn ;
202
- } else {
203
- if (SD_detect_gpio_pin == GPIO_PIN_2 ) {
204
- sd_detect_EXTI_IRQn = EXTI2_IRQn ;
205
- } else {
206
- if (SD_detect_gpio_pin == GPIO_PIN_3 ) {
207
- sd_detect_EXTI_IRQn = EXTI3_IRQn ;
208
- } else {
209
- if (SD_detect_gpio_pin == GPIO_PIN_4 ) {
210
- sd_detect_EXTI_IRQn = EXTI4_IRQn ;
211
- } else {
212
- if ((SD_detect_gpio_pin == GPIO_PIN_5 ) || \
213
- (SD_detect_gpio_pin == GPIO_PIN_6 ) || \
214
- (SD_detect_gpio_pin == GPIO_PIN_7 ) || \
215
- (SD_detect_gpio_pin == GPIO_PIN_8 ) || \
216
- (SD_detect_gpio_pin == GPIO_PIN_9 )) {
217
- sd_detect_EXTI_IRQn = EXTI9_5_IRQn ;
218
- } else {
219
- if ((SD_detect_gpio_pin == GPIO_PIN_10 ) || \
220
- (SD_detect_gpio_pin == GPIO_PIN_11 ) || \
221
- (SD_detect_gpio_pin == GPIO_PIN_12 ) || \
222
- (SD_detect_gpio_pin == GPIO_PIN_13 ) || \
223
- (SD_detect_gpio_pin == GPIO_PIN_14 ) || \
224
- (SD_detect_gpio_pin == GPIO_PIN_15 )) {
225
- sd_detect_EXTI_IRQn = EXTI15_10_IRQn ;
226
- } else {
227
- sd_state = MSD_ERROR ;
228
- }
229
- }
230
- }
231
- }
232
- }
188
+ uint8_t sd_state = MSD_ERROR ;
189
+ if (SD_detect_ll_gpio_pin != LL_GPIO_PIN_ALL ) {
190
+ LL_GPIO_SetPinPull (SD_detect_gpio_port , SD_detect_ll_gpio_pin , LL_GPIO_PULL_UP );
191
+ uint16_t SD_detect_gpio_pin = GPIO_PIN_All ;
192
+ switch (SD_detect_ll_gpio_pin ) {
193
+ case LL_GPIO_PIN_0 :
194
+ SD_detect_gpio_pin = GPIO_PIN_0 ;
195
+ break ;
196
+ case LL_GPIO_PIN_1 :
197
+ SD_detect_gpio_pin = GPIO_PIN_1 ;
198
+ break ;
199
+ case LL_GPIO_PIN_2 :
200
+ SD_detect_gpio_pin = GPIO_PIN_2 ;
201
+ break ;
202
+ case LL_GPIO_PIN_3 :
203
+ SD_detect_gpio_pin = GPIO_PIN_3 ;
204
+ break ;
205
+ case LL_GPIO_PIN_4 :
206
+ SD_detect_gpio_pin = GPIO_PIN_4 ;
207
+ break ;
208
+ case LL_GPIO_PIN_5 :
209
+ SD_detect_gpio_pin = GPIO_PIN_5 ;
210
+ break ;
211
+ case LL_GPIO_PIN_6 :
212
+ SD_detect_gpio_pin = GPIO_PIN_6 ;
213
+ break ;
214
+ case LL_GPIO_PIN_7 :
215
+ SD_detect_gpio_pin = GPIO_PIN_7 ;
216
+ break ;
217
+ case LL_GPIO_PIN_8 :
218
+ SD_detect_gpio_pin = GPIO_PIN_8 ;
219
+ break ;
220
+ case LL_GPIO_PIN_9 :
221
+ SD_detect_gpio_pin = GPIO_PIN_9 ;
222
+ break ;
223
+ case LL_GPIO_PIN_10 :
224
+ SD_detect_gpio_pin = GPIO_PIN_10 ;
225
+ break ;
226
+ case LL_GPIO_PIN_11 :
227
+ SD_detect_gpio_pin = GPIO_PIN_11 ;
228
+ break ;
229
+ case LL_GPIO_PIN_12 :
230
+ SD_detect_gpio_pin = GPIO_PIN_12 ;
231
+ break ;
232
+ case LL_GPIO_PIN_13 :
233
+ SD_detect_gpio_pin = GPIO_PIN_13 ;
234
+ break ;
235
+ case LL_GPIO_PIN_14 :
236
+ SD_detect_gpio_pin = GPIO_PIN_14 ;
237
+ break ;
238
+ case LL_GPIO_PIN_15 :
239
+ SD_detect_gpio_pin = GPIO_PIN_15 ;
240
+ break ;
241
+ default :
242
+ Error_Handler ();
243
+ break ;
233
244
}
234
- }
235
- if (sd_state == MSD_OK ) {
236
- /* Enable and set SD detect EXTI Interrupt to the lowest priority */
237
- HAL_NVIC_SetPriority (sd_detect_EXTI_IRQn , 0x0F , 0x00 );
238
- HAL_NVIC_EnableIRQ (sd_detect_EXTI_IRQn );
245
+ stm32_interrupt_enable (SD_detect_gpio_port , SD_detect_gpio_pin , callback , GPIO_MODE_IT_RISING_FALLING );
246
+ sd_state = MSD_OK ;
239
247
}
240
248
return sd_state ;
241
249
}
@@ -246,13 +254,11 @@ uint8_t BSP_SD_DetectITConfig(void)
246
254
*/
247
255
uint8_t BSP_SD_IsDetected (void )
248
256
{
249
- uint8_t status = SD_PRESENT ;
250
-
257
+ uint8_t status = SD_NOT_PRESENT ;
251
258
/* Check SD card detect pin */
252
- if (HAL_GPIO_ReadPin (SD_detect_gpio_port , SD_detect_gpio_pin ) == GPIO_PIN_SET ) {
253
- status = SD_NOT_PRESENT ;
259
+ if (! LL_GPIO_IsInputPinSet (SD_detect_gpio_port , SD_detect_ll_gpio_pin ) ) {
260
+ status = SD_PRESENT ;
254
261
}
255
-
256
262
return status ;
257
263
}
258
264
@@ -371,14 +377,15 @@ __weak void BSP_SD_Detect_MspInit(SD_HandleTypeDef *hsd, void *Params)
371
377
{
372
378
UNUSED (hsd );
373
379
UNUSED (Params );
374
- GPIO_InitTypeDef gpio_init_structure ;
375
380
376
381
/* GPIO configuration in input for uSD_Detect signal */
377
- gpio_init_structure .Pin = SD_detect_gpio_pin ;
378
- gpio_init_structure .Mode = GPIO_MODE_INPUT ;
379
- gpio_init_structure .Pull = GPIO_PULLUP ;
380
- gpio_init_structure .Speed = SD_GPIO_SPEED ;
381
- HAL_GPIO_Init (SD_detect_gpio_port , & gpio_init_structure );
382
+ #ifdef LL_GPIO_SPEED_FREQ_VERY_HIGH
383
+ LL_GPIO_SetPinSpeed (SD_detect_gpio_port , SD_detect_ll_gpio_pin , LL_GPIO_SPEED_FREQ_VERY_HIGH );
384
+ #else
385
+ LL_GPIO_SetPinSpeed (SD_detect_gpio_port , SD_detect_ll_gpio_pin , LL_GPIO_SPEED_FREQ_HIGH );
386
+ #endif
387
+ LL_GPIO_SetPinMode (SD_detect_gpio_port , SD_detect_ll_gpio_pin , LL_GPIO_MODE_INPUT );
388
+ LL_GPIO_SetPinPull (SD_detect_gpio_port , SD_detect_ll_gpio_pin , LL_GPIO_PULL_UP );
382
389
}
383
390
384
391
/**
0 commit comments