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

fix h7 sdcard init #10512

Merged
merged 2 commits into from
Dec 8, 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
12 changes: 12 additions & 0 deletions src/main/drivers/sdcard/sdcard_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,20 @@ static bool sdcardSdio_poll(void)
break; // Timeout not reached yet so keep waiting
}
// Timeout has expired, so fall through to convert to a fatal error
FALLTHROUGH;

case SDCARD_RECEIVE_ERROR:
sdcardSdio_reset();

if (sdcard.pendingOperation.callback) {
sdcard.pendingOperation.callback(
SDCARD_BLOCK_OPERATION_READ,
sdcard.pendingOperation.blockIndex,
NULL,
sdcard.pendingOperation.callbackData
);
}

goto doMore;
break;
}
Expand Down
26 changes: 15 additions & 11 deletions src/main/drivers/sdcard/sdmmc_sdio_h7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ void HAL_SD_MspInit(SD_HandleTypeDef* hsd)

if (sdioHardware->instance == SDMMC1) {
__HAL_RCC_SDMMC1_CLK_DISABLE();
__HAL_RCC_SDMMC1_CLK_ENABLE();

__HAL_RCC_SDMMC1_FORCE_RESET();
__HAL_RCC_SDMMC1_RELEASE_RESET();
__HAL_RCC_SDMMC1_CLK_ENABLE();
} else if (sdioHardware->instance == SDMMC2) {
__HAL_RCC_SDMMC2_CLK_DISABLE();
__HAL_RCC_SDMMC2_CLK_ENABLE();

__HAL_RCC_SDMMC2_FORCE_RESET();
__HAL_RCC_SDMMC2_RELEASE_RESET();
__HAL_RCC_SDMMC2_CLK_ENABLE();
}

const IO_t clk = IOGetByTag(sdioPin[SDIO_PIN_CK].pin);
Expand Down Expand Up @@ -248,28 +250,30 @@ bool SD_GetState(void)

bool SD_Init(void)
{
HAL_StatusTypeDef status;

memset(&hsd1, 0, sizeof(hsd1));

hsd1.Instance = sdioHardware->instance;

hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_ENABLE;
// falling seems to work better ?? no idea whats "right" here
hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_FALLING;

// drastically increases the time to respond from the sdcard
// lets leave it off
hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
#ifdef SDCARD_SDIO_4BIT
hsd1.Init.BusWide = SDMMC_BUS_WIDE_4B;
#else
hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B; // FIXME untested
hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B;
#endif
hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE;
#ifdef SDCARD_SDIO_NORMAL_SPEED
hsd1.Init.ClockDiv = SDMMC_NSpeed_CLK_DIV;
hsd1.Init.ClockDiv = SDMMC_NSpeed_CLK_DIV;
#else
hsd1.Init.ClockDiv = 1; // 200Mhz / (2 * 1 ) = 100Mhz, used for "UltraHigh speed SD card" only, see HAL_SD_ConfigWideBusOperation, SDMMC_HSpeed_CLK_DIV, SDMMC_NSpeed_CLK_DIV
hsd1.Init.ClockDiv = SDMMC_HSpeed_CLK_DIV; // lets not go too crazy :)
#endif

status = HAL_SD_Init(&hsd1); // Will call HAL_SD_MspInit

// Will call HAL_SD_MspInit
const HAL_StatusTypeDef status = HAL_SD_Init(&hsd1);
if (status != HAL_OK) {
return SD_ERROR;
}
Expand Down
Loading