Skip to content

Commit 29208ce

Browse files
committed
fix: SDMMC2 can be available without SDMMC1
Example for L4P5C(E-G)(T-U)_L4Q5CG(T-U). So ensure to have correct setup in this case. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent e656bc8 commit 29208ce

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/bsp_sd.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,11 @@
4343
/* Definition for BSP SD */
4444
#if defined(SDMMC1) || defined(SDMMC2)
4545
#ifndef SD_INSTANCE
46-
#define SD_INSTANCE SDMMC1
47-
#endif
48-
49-
#define SD_CLK_ENABLE __HAL_RCC_SDMMC1_CLK_ENABLE
50-
#define SD_CLK_DISABLE __HAL_RCC_SDMMC1_CLK_DISABLE
51-
#ifdef SDMMC2
52-
#define SD_CLK2_ENABLE __HAL_RCC_SDMMC2_CLK_ENABLE
53-
#define SD_CLK2_DISABLE __HAL_RCC_SDMMC2_CLK_DISABLE
46+
#if defined(SDMMC1)
47+
#define SD_INSTANCE SDMMC1
48+
#else
49+
#define SD_INSTANCE SDMMC2
50+
#endif
5451
#endif
5552

5653
#define SD_CLK_EDGE SDMMC_CLOCK_EDGE_RISING
@@ -84,8 +81,6 @@
8481

8582
#elif defined(SDIO)
8683
#define SD_INSTANCE SDIO
87-
#define SD_CLK_ENABLE __HAL_RCC_SDIO_CLK_ENABLE
88-
#define SD_CLK_DISABLE __HAL_RCC_SDIO_CLK_DISABLE
8984
#define SD_CLK_EDGE SDIO_CLOCK_EDGE_RISING
9085
#if defined(SDIO_CLOCK_BYPASS_DISABLE)
9186
#define SD_CLK_BYPASS SDIO_CLOCK_BYPASS_DISABLE
@@ -518,15 +513,20 @@ __weak void BSP_SD_MspInit(SD_HandleTypeDef *hsd, void *Params)
518513
#endif
519514
#endif
520515
/* Enable SD clock */
521-
#if defined(SDMMC1) && defined(SDMMC2)
516+
#if defined(SDMMC1) || defined(SDMMC2)
517+
#if defined(SDMMC1)
522518
if (hsd->Instance == SDMMC1) {
523-
SD_CLK_ENABLE();
524-
} else {
525-
SD_CLK2_ENABLE();
519+
__HAL_RCC_SDMMC1_CLK_ENABLE();
520+
}
521+
#endif
522+
#if defined(SDMMC2)
523+
if (hsd->Instance == SDMMC2) {
524+
__HAL_RCC_SDMMC2_CLK_ENABLE();
526525
}
526+
#endif
527527
#else
528528
UNUSED(hsd);
529-
SD_CLK_ENABLE();
529+
__HAL_RCC_SDIO_CLK_ENABLE();
530530
#endif
531531
}
532532

@@ -584,15 +584,20 @@ __weak void BSP_SD_MspDeInit(SD_HandleTypeDef *hsd, void *Params)
584584
#endif
585585

586586
/* Disable SD clock */
587-
#if defined(SDMMC1) && defined(SDMMC2)
587+
#if defined(SDMMC1) || defined(SDMMC2)
588+
#if defined(SDMMC1)
588589
if (hsd->Instance == SDMMC1) {
589-
SD_CLK_DISABLE();
590-
} else {
591-
SD_CLK2_DISABLE();
590+
__HAL_RCC_SDMMC1_CLK_DISABLE();
592591
}
592+
#endif
593+
#if defined(SDMMC2)
594+
if (hsd->Instance == SDMMC2) {
595+
__HAL_RCC_SDMMC2_CLK_DISABLE();
596+
}
597+
#endif
593598
#else
594599
UNUSED(hsd);
595-
SD_CLK_DISABLE();
600+
__HAL_RCC_SDIO_CLK_DISABLE();
596601
#endif
597602
}
598603

0 commit comments

Comments
 (0)