Skip to content

Commit 0877845

Browse files
committed
Use SD pins mapping
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent e802ea7 commit 0877845

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

src/bsp_sd.c

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080

8181
/* Includes ------------------------------------------------------------------*/
8282
#include "bsp_sd.h"
83+
#include "PeripheralPins.h"
8384

8485
#ifdef SDMMC1
8586
/* Definition for BSP SD */
@@ -99,8 +100,6 @@
99100
#else
100101
#define SD_CLK_DIV SDMMC_TRANSFER_CLK_DIV
101102
#endif
102-
/* Definition for MSP SD */
103-
#define SD_AF GPIO_AF12_SDMMC1
104103
#elif defined(SDIO)
105104
/* Definition for BSP SD */
106105
#define SD_INSTANCE SDIO
@@ -115,20 +114,10 @@
115114
#define SD_HW_FLOW_CTRL SDIO_HARDWARE_FLOW_CONTROL_DISABLE
116115
#endif
117116
#define SD_CLK_DIV SDIO_TRANSFER_CLK_DIV
118-
/* Definition for MSP SD */
119-
#ifndef STM32F1xx
120-
#define SD_AF GPIO_AF12_SDIO
121-
#endif
122117
#else
123118
#error "Unknown SD_INSTANCE"
124119
#endif
125120

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-
132121
/* BSP SD Private Variables */
133122
static SD_HandleTypeDef uSdHandle;
134123
static uint32_t SD_detect_gpio_pin = GPIO_PIN_All;
@@ -408,31 +397,16 @@ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
408397
{
409398
UNUSED(hsd);
410399
UNUSED(Params);
411-
GPIO_InitTypeDef gpio_init_structure;
400+
401+
/* Configure SD GPIOs */
402+
const PinMap *map = PinMap_SD;
403+
while (map->pin != NC) {
404+
pin_function(map->pin, map->function);
405+
map++;
406+
}
412407

413408
/* Enable SDIO clock */
414409
SD_CLK_ENABLE();
415-
416-
/* Enable GPIOs clock */
417-
__HAL_RCC_GPIOC_CLK_ENABLE();
418-
__HAL_RCC_GPIOD_CLK_ENABLE();
419-
420-
/* Common GPIO configuration */
421-
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
422-
gpio_init_structure.Pull = GPIO_PULLUP;
423-
gpio_init_structure.Speed = SD_GPIO_SPEED;
424-
#ifndef STM32F1xx
425-
gpio_init_structure.Alternate = SD_AF;
426-
#endif
427-
/* GPIOC configuration */
428-
gpio_init_structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
429-
430-
HAL_GPIO_Init(GPIOC, &gpio_init_structure);
431-
432-
/* GPIOD configuration */
433-
gpio_init_structure.Pin = GPIO_PIN_2;
434-
HAL_GPIO_Init(GPIOD, &gpio_init_structure);
435-
436410
}
437411

438412
/**

src/bsp_sd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ extern "C" {
4848
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01050000)
4949
#include "variant.h"
5050
#endif
51-
51+
#if !defined(STM32_CORE_VERSION) || (STM32_CORE_VERSION <= 0x01060100)
52+
#error "This library version required a STM32 core version > 1.6.1.\
53+
Please update the core or install previous libray version."
54+
#endif
5255
/* Could be redefined in variant.h or using build_opt.h */
5356
#ifndef SD_DATATIMEOUT
5457
#define SD_DATATIMEOUT 100000000U

0 commit comments

Comments
 (0)