Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

f7: migrate sdcard to hal #10526

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmake/stm32f7.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(STM32F7_HAL_SRC
stm32f7xx_ll_tim.c
stm32f7xx_ll_usb.c
stm32f7xx_ll_utils.c
stm32f7xx_hal_sd.c
stm32f7xx_ll_sdmmc.c
)
list(TRANSFORM STM32F7_HAL_SRC PREPEND "${STM32F7_HAL_DIR}/Src/")

Expand Down Expand Up @@ -74,7 +76,7 @@ main_sources(STM32F7_SRC
drivers/system_stm32f7xx.c
drivers/serial_uart_stm32f7xx.c
drivers/serial_uart_hal.c
drivers/sdcard/sdmmc_sdio_f7xx.c
drivers/sdcard/sdmmc_sdio_hal.c
)

main_sources(STM32F7_MSC_SRC
Expand Down
2 changes: 1 addition & 1 deletion cmake/stm32h7.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ main_sources(STM32H7_SRC
drivers/serial_uart_stm32h7xx.c
drivers/serial_uart_hal.c
drivers/sdio.h
drivers/sdcard/sdmmc_sdio_h7xx.c
drivers/sdcard/sdmmc_sdio_hal.c
)

main_sources(STM32H7_MSC_SRC
Expand Down
31 changes: 17 additions & 14 deletions src/main/drivers/sdcard/sdcard_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ static bool sdcardSdio_isFunctional(void)
*/
static void sdcardSdio_reset(void)
{
if (SD_Init() != 0) {
sdcard.failureCount++;
if (sdcard.failureCount >= SDCARD_MAX_CONSECUTIVE_FAILURES || !sdcard_isInserted()) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
} else {
sdcard.operationStartTime = millis();
sdcard.state = SDCARD_STATE_RESET;
}
if (!sdcard_isInserted()) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
return;
}
if (SD_Init() != SD_OK) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
return;
}

sdcard.failureCount++;
if (sdcard.failureCount >= SDCARD_MAX_CONSECUTIVE_FAILURES) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
} else {
sdcard.operationStartTime = millis();
sdcard.state = SDCARD_STATE_RESET;
}
}

Expand Down Expand Up @@ -573,17 +580,13 @@ void sdcardSdio_init(void)
return;
}

if (!SD_Initialize_LL(sdcard.dma->ref)) {
if (!SD_Initialize_LL(sdcard.dma)) {
sdcard.dma = NULL;
sdcard.state = SDCARD_STATE_NOT_PRESENT;
return;
}
#else
if (!SD_Initialize_LL(0)) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
return;
}
#endif

// We don't support hot insertion
if (!sdcard_isInserted()) {
sdcard.state = SDCARD_STATE_NOT_PRESENT;
Expand Down
21 changes: 3 additions & 18 deletions src/main/drivers/sdcard/sdmmc_sdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,7 @@
#if defined(USE_SDCARD_SDIO)

#include "platform.h"

#ifdef STM32F4
#include "stm32f4xx.h"
#endif

#ifdef STM32F7
#include "stm32f7xx.h"
#endif

#ifdef STM32H7
#include "stm32h7xx.h"
#endif

#ifdef AT32F43x
#include "at32f435_437.h"
#endif
#include "drivers/dma.h"

/* SDCARD pinouts
*
Expand Down Expand Up @@ -221,9 +206,9 @@ extern SD_CardType_t SD_CardType;

#ifdef AT32F43x
// TODO:AT32 TARGES NOT USE SD CARD ANT TF CARD FOR NOW
void SD_Initialize_LL (dma_channel_type *dma);
void SD_Initialize_LL (DMA_t dma);
#else
bool SD_Initialize_LL (DMA_Stream_TypeDef *dma);
bool SD_Initialize_LL (DMA_t dma);
#endif
bool SD_Init(void);
bool SD_IsDetected(void);
Expand Down
4 changes: 3 additions & 1 deletion src/main/drivers/sdcard/sdmmc_sdio_f4xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,8 +1356,10 @@ static SD_Error_t SD_FindSCR(uint32_t *pSCR)
/**
* @brief Initialize the SDIO module, DMA, and IO
*/
bool SD_Initialize_LL(DMA_Stream_TypeDef *dmaRef)
bool SD_Initialize_LL(DMA_t dma)
{
DMA_Stream_TypeDef *dmaRef = dma->ref;

// Sanity check DMA stread - we only support two possible
if (((uint32_t)dmaRef != (uint32_t)DMA2_Stream3) && ((uint32_t)dmaRef != (uint32_t)DMA2_Stream6)) {
return false;
Expand Down
Loading
Loading