From 63a1a4e4d7341c24978482cac46b19b3846a28c5 Mon Sep 17 00:00:00 2001 From: DrZlo13 Date: Sat, 30 Jan 2021 19:01:48 +1000 Subject: [PATCH] fix some bugs with sd spi (#320) * change sd init speed * add pullup on bus --- firmware/targets/f4/Src/spi.c | 6 +++--- firmware/targets/f4/api-hal/api-hal-spi-config.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/targets/f4/Src/spi.c b/firmware/targets/f4/Src/spi.c index d1fd0669..8fe11eaa 100644 --- a/firmware/targets/f4/Src/spi.c +++ b/firmware/targets/f4/Src/spi.c @@ -156,21 +156,21 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) // SD Card need faster spi gpio GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = SPI_D_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(SPI_D_MOSI_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = SPI_D_SCK_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(SPI_D_SCK_GPIO_Port, &GPIO_InitStruct); diff --git a/firmware/targets/f4/api-hal/api-hal-spi-config.c b/firmware/targets/f4/api-hal/api-hal-spi-config.c index 792df528..7751b2a1 100644 --- a/firmware/targets/f4/api-hal/api-hal-spi-config.c +++ b/firmware/targets/f4/api-hal/api-hal-spi-config.c @@ -37,7 +37,7 @@ const SPIDevice sd_slow_spi = { .CLKPolarity = SPI_POLARITY_LOW, .CLKPhase = SPI_PHASE_1EDGE, .NSS = SPI_NSS_SOFT, - .BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256, + .BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32, .FirstBit = SPI_FIRSTBIT_MSB, .TIMode = SPI_TIMODE_DISABLE, .CRCCalculation = SPI_CRCCALCULATION_DISABLE,