stmhal/sdcard: Use mp_hal_pin_config function instead of HAL_GPIO_Init.

There is a minor functional change with this patch, that the GPIO are now
configured in fast mode, whereas they were in high speed mode before.  But
the SDIO should still work because SD CK frequency is at most 25MHz.
This commit is contained in:
Damien George 2016-12-22 14:53:03 +11:00
parent ed559de063
commit e202b6f586
4 changed files with 28 additions and 15 deletions

View File

@ -37,4 +37,10 @@ SW,PA13
SD,PC13
MMA_INT,PB2
MMA_AVDD,PB5
SD_D0,PC8
SD_D1,PC9
SD_D2,PC10
SD_D3,PC11
SD_CK,PC12
SD_CMD,PD2
UART1_TX,PA9

1 B13 PB13
37 SD PC13
38 MMA_INT PB2
39 MMA_AVDD PB5
40 SD_D0 PC8
41 SD_D1 PC9
42 SD_D2 PC10
43 SD_D3 PC11
44 SD_CK PC12
45 SD_CMD PD2
46 UART1_TX PA9

View File

@ -33,6 +33,12 @@ AUDIO_SCL,PH7
EXT_SDA,PB9
EXT_SCL,PB8
EXT_RST,PG3
SD_D0,PC8
SD_D1,PC9
SD_D2,PC10
SD_D3,PC11
SD_CK,PC12
SD_CMD,PD2
SD_SW,PI15
LCD_BL_CTRL,PK3
LCD_INT,PI13

1 A0 PA0
33 EXT_SDA PB9
34 EXT_SCL PB8
35 EXT_RST PG3
36 SD_D0 PC8
37 SD_D1 PC9
38 SD_D2 PC10
39 SD_D3 PC11
40 SD_CK PC12
41 SD_CMD PD2
42 SD_SW PI15
43 LCD_BL_CTRL PK3
44 LCD_INT PI13

View File

@ -31,6 +31,12 @@ AUDIO_SCL,PH7
EXT_SDA,PB9
EXT_SCL,PB8
EXT_RST,PG3
SD_D0,PC8
SD_D1,PC9
SD_D2,PC10
SD_D3,PC11
SD_CK,PC12
SD_CMD,PD2
SD_SW,PC13
LCD_BL_CTRL,PK3
LCD_INT,PI13

1 A0 PA0
31 EXT_SDA PB9
32 EXT_SCL PB8
33 EXT_RST PG3
34 SD_D0 PC8
35 SD_D1 PC9
36 SD_D2 PC10
37 SD_D3 PC11
38 SD_CK PC12
39 SD_CMD PD2
40 SD_SW PC13
41 LCD_BL_CTRL PK3
42 LCD_INT PI13

View File

@ -81,30 +81,25 @@ static SD_HandleTypeDef sd_handle;
static DMA_HandleTypeDef sd_rx_dma, sd_tx_dma;
void sdcard_init(void) {
GPIO_InitTypeDef GPIO_Init_Structure;
// invalidate the sd_handle
sd_handle.Instance = NULL;
// configure SD GPIO
// we do this here an not in HAL_SD_MspInit because it apparently
// makes it more robust to have the pins always pulled high
GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
GPIO_Init_Structure.Pull = GPIO_PULLUP;
GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
GPIO_Init_Structure.Alternate = GPIO_AF12_SDIO;
GPIO_Init_Structure.Pin = GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12;
HAL_GPIO_Init(GPIOC, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_2;
HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);
// Note: the mp_hal_pin_config function will configure the GPIO in
// fast mode which can do up to 50MHz. This should be plenty for SDIO
// which clocks up to 25MHz maximum.
mp_hal_pin_config(&pin_C8, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&pin_C9, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&pin_C10, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&pin_C11, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&pin_C12, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
mp_hal_pin_config(&pin_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, GPIO_AF12_SDIO);
// configure the SD card detect pin
// we do this here so we can detect if the SD card is inserted before powering it on
GPIO_Init_Structure.Mode = GPIO_MODE_INPUT;
GPIO_Init_Structure.Pull = MICROPY_HW_SDCARD_DETECT_PULL;
GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
GPIO_Init_Structure.Pin = MICROPY_HW_SDCARD_DETECT_PIN.pin_mask;
HAL_GPIO_Init(MICROPY_HW_SDCARD_DETECT_PIN.gpio, &GPIO_Init_Structure);
mp_hal_pin_config(&MICROPY_HW_SDCARD_DETECT_PIN, MP_HAL_PIN_MODE_INPUT, MICROPY_HW_SDCARD_DETECT_PULL, 0);
}
void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {