Skip to content

Commit 9d69b14

Browse files
authored
Merge pull request #10526 from bkleiner/bkleiner/fix-f7-sdcard
f7: migrate sdcard to hal
2 parents b2bacd4 + 3561fee commit 9d69b14

15 files changed

+203
-2255
lines changed

cmake/stm32f7.cmake

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ set(STM32F7_HAL_SRC
3838
stm32f7xx_ll_tim.c
3939
stm32f7xx_ll_usb.c
4040
stm32f7xx_ll_utils.c
41+
stm32f7xx_hal_sd.c
42+
stm32f7xx_ll_sdmmc.c
4143
)
4244
list(TRANSFORM STM32F7_HAL_SRC PREPEND "${STM32F7_HAL_DIR}/Src/")
4345

@@ -74,7 +76,7 @@ main_sources(STM32F7_SRC
7476
drivers/system_stm32f7xx.c
7577
drivers/serial_uart_stm32f7xx.c
7678
drivers/serial_uart_hal.c
77-
drivers/sdcard/sdmmc_sdio_f7xx.c
79+
drivers/sdcard/sdmmc_sdio_hal.c
7880
)
7981

8082
main_sources(STM32F7_MSC_SRC

cmake/stm32h7.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ main_sources(STM32H7_SRC
161161
drivers/serial_uart_stm32h7xx.c
162162
drivers/serial_uart_hal.c
163163
drivers/sdio.h
164-
drivers/sdcard/sdmmc_sdio_h7xx.c
164+
drivers/sdcard/sdmmc_sdio_hal.c
165165
)
166166

167167
main_sources(STM32H7_MSC_SRC

src/main/drivers/sdcard/sdcard_sdio.c

+17-14
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,21 @@ static bool sdcardSdio_isFunctional(void)
9595
*/
9696
static void sdcardSdio_reset(void)
9797
{
98-
if (SD_Init() != 0) {
99-
sdcard.failureCount++;
100-
if (sdcard.failureCount >= SDCARD_MAX_CONSECUTIVE_FAILURES || !sdcard_isInserted()) {
101-
sdcard.state = SDCARD_STATE_NOT_PRESENT;
102-
} else {
103-
sdcard.operationStartTime = millis();
104-
sdcard.state = SDCARD_STATE_RESET;
105-
}
98+
if (!sdcard_isInserted()) {
99+
sdcard.state = SDCARD_STATE_NOT_PRESENT;
100+
return;
101+
}
102+
if (SD_Init() != SD_OK) {
103+
sdcard.state = SDCARD_STATE_NOT_PRESENT;
104+
return;
105+
}
106+
107+
sdcard.failureCount++;
108+
if (sdcard.failureCount >= SDCARD_MAX_CONSECUTIVE_FAILURES) {
109+
sdcard.state = SDCARD_STATE_NOT_PRESENT;
110+
} else {
111+
sdcard.operationStartTime = millis();
112+
sdcard.state = SDCARD_STATE_RESET;
106113
}
107114
}
108115

@@ -573,17 +580,13 @@ void sdcardSdio_init(void)
573580
return;
574581
}
575582

576-
if (!SD_Initialize_LL(sdcard.dma->ref)) {
583+
if (!SD_Initialize_LL(sdcard.dma)) {
577584
sdcard.dma = NULL;
578585
sdcard.state = SDCARD_STATE_NOT_PRESENT;
579586
return;
580587
}
581-
#else
582-
if (!SD_Initialize_LL(0)) {
583-
sdcard.state = SDCARD_STATE_NOT_PRESENT;
584-
return;
585-
}
586588
#endif
589+
587590
// We don't support hot insertion
588591
if (!sdcard_isInserted()) {
589592
sdcard.state = SDCARD_STATE_NOT_PRESENT;

src/main/drivers/sdcard/sdmmc_sdio.h

+3-18
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,7 @@
3131
#if defined(USE_SDCARD_SDIO)
3232

3333
#include "platform.h"
34-
35-
#ifdef STM32F4
36-
#include "stm32f4xx.h"
37-
#endif
38-
39-
#ifdef STM32F7
40-
#include "stm32f7xx.h"
41-
#endif
42-
43-
#ifdef STM32H7
44-
#include "stm32h7xx.h"
45-
#endif
46-
47-
#ifdef AT32F43x
48-
#include "at32f435_437.h"
49-
#endif
34+
#include "drivers/dma.h"
5035

5136
/* SDCARD pinouts
5237
*
@@ -221,9 +206,9 @@ extern SD_CardType_t SD_CardType;
221206

222207
#ifdef AT32F43x
223208
// TODO:AT32 TARGES NOT USE SD CARD ANT TF CARD FOR NOW
224-
void SD_Initialize_LL (dma_channel_type *dma);
209+
void SD_Initialize_LL (DMA_t dma);
225210
#else
226-
bool SD_Initialize_LL (DMA_Stream_TypeDef *dma);
211+
bool SD_Initialize_LL (DMA_t dma);
227212
#endif
228213
bool SD_Init(void);
229214
bool SD_IsDetected(void);

src/main/drivers/sdcard/sdmmc_sdio_f4xx.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,10 @@ static SD_Error_t SD_FindSCR(uint32_t *pSCR)
13561356
/**
13571357
* @brief Initialize the SDIO module, DMA, and IO
13581358
*/
1359-
bool SD_Initialize_LL(DMA_Stream_TypeDef *dmaRef)
1359+
bool SD_Initialize_LL(DMA_t dma)
13601360
{
1361+
DMA_Stream_TypeDef *dmaRef = dma->ref;
1362+
13611363
// Sanity check DMA stread - we only support two possible
13621364
if (((uint32_t)dmaRef != (uint32_t)DMA2_Stream3) && ((uint32_t)dmaRef != (uint32_t)DMA2_Stream6)) {
13631365
return false;

0 commit comments

Comments
 (0)