Skip to content

Commit

Permalink
h7: sdio: allow custom clock divider (betaflight#14167)
Browse files Browse the repository at this point in the history
* add SDIO_CLOCK_DIV define to allow compatibility with a wide range of SD cards

* Update src/platform/STM32/sdio_h7xx.c

Co-authored-by: Petr Ledvina <[email protected]>

---------

Co-authored-by: Petr Ledvina <[email protected]>
  • Loading branch information
dakejahl and ledvinap authored Jan 16, 2025
1 parent 892da2d commit 83beeaf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/platform/STM32/sdio_h7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,14 @@ static SD_Error_t SD_DoInit(void)
hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B; // FIXME untested
}
hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_ENABLE;
#if defined(STM32H730xx)
hsd1.Init.ClockDiv = 2; // 200Mhz / (2 * 2 ) = 50Mhz, used for "UltraHigh speed SD card" only, see HAL_SD_ConfigWideBusOperation, SDMMC_HSpeed_CLK_DIV, 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
#if !defined(SDIO_CLOCK_DIV)
# if defined(STM32H730xx)
# define SDIO_CLOCK_DIV 2 // 200Mhz / (2 * 2 ) = 50Mhz, used for "UltraHigh speed SD card" only, see HAL_SD_ConfigWideBusOperation, SDMMC_HSpeed_CLK_DIV, SDMMC_NSpeed_CLK_DIV
# else
# define SDIO_CLOCK_DIV 1 // 200Mhz / (2 * 1 ) = 100Mhz, used for "UltraHigh speed SD card" only, see HAL_SD_ConfigWideBusOperation, SDMMC_HSpeed_CLK_DIV, SDMMC_NSpeed_CLK_DIV
# endif
#endif
hsd1.Init.ClockDiv = SDIO_CLOCK_DIV;
status = HAL_SD_Init(&hsd1); // Will call HAL_SD_MspInit

if (status != HAL_OK) {
Expand Down

0 comments on commit 83beeaf

Please sign in to comment.