Skip to content

Commit 4b9c459

Browse files
iabdalkaderdpgeorge
authored andcommitted
mimxrt/sdio: Add support for the 117x series.
Signed-off-by: iabdalkader <[email protected]>
1 parent fbe5855 commit 4b9c459

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

ports/mimxrt/sdio.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@
3838
#if MICROPY_HW_SDIO_SDMMC == 1
3939
#define SDMMC USDHC1
4040
#define SDMMC_IRQn USDHC1_IRQn
41+
#ifdef MIMXRT117x_SERIES
42+
#define SDMMC_CLOCK_MUX kCLOCK_USDHC1_ClockRoot_MuxSysPll2Pfd2
43+
#define SDMMC_CLOCK_ROOT kCLOCK_Root_Usdhc1
44+
#else
4145
#define SDMMC_CLOCK_DIV kCLOCK_Usdhc1Div
4246
#define SDMMC_CLOCK_MUX kCLOCK_Usdhc1Mux
47+
#define SDMMC_CLOCK_ROOT kCLOCK_Usdhc1ClkRoot
48+
#endif
4349
#ifndef MICROPY_HW_SDIO_CLK_ALT
4450
#define MICROPY_HW_SDIO_CMD_ALT (0)
4551
#define MICROPY_HW_SDIO_CLK_ALT (0)
@@ -51,8 +57,14 @@
5157
#else
5258
#define SDMMC USDHC2
5359
#define SDMMC_IRQn USDHC2_IRQn
60+
#ifdef MIMXRT117x_SERIES
61+
#define SDMMC_CLOCK_MUX kCLOCK_USDHC2_ClockRoot_MuxSysPll2Pfd2
62+
#define SDMMC_CLOCK_ROOT kCLOCK_Root_Usdhc2
63+
#else
5464
#define SDMMC_CLOCK_DIV kCLOCK_Usdhc2Div
5565
#define SDMMC_CLOCK_MUX kCLOCK_Usdhc2Mux
66+
#define SDMMC_CLOCK_ROOT kCLOCK_Usdhc2ClkRoot
67+
#endif
5668
#ifndef MICROPY_HW_SDIO_CLK_ALT
5769
#define MICROPY_HW_SDIO_CMD_ALT (6)
5870
#define MICROPY_HW_SDIO_CLK_ALT (6)
@@ -95,7 +107,11 @@ typedef enum {
95107
} sdio_xfer_flags_t;
96108

97109
static uint32_t sdio_base_clk(void) {
98-
return CLOCK_GetSysPfdFreq(kCLOCK_Pfd0) / (CLOCK_GetDiv(kCLOCK_Usdhc1Div) + 1U);
110+
#ifdef MIMXRT117x_SERIES
111+
return CLOCK_GetRootClockFreq(SDMMC_CLOCK_ROOT);
112+
#else
113+
return CLOCK_GetClockRootFreq(SDMMC_CLOCK_ROOT);
114+
#endif
99115
}
100116

101117
static uint32_t sdio_response_type(uint32_t cmd) {
@@ -144,19 +160,30 @@ void sdio_init(uint32_t irq_pri) {
144160
machine_pin_config(MICROPY_HW_SDIO_D2, PIN_MODE_ALT, PIN_PULL_UP_100K, PIN_DRIVE_6, 0, MICROPY_HW_SDIO_D2_ALT);
145161
machine_pin_config(MICROPY_HW_SDIO_D3, PIN_MODE_ALT, PIN_PULL_UP_100K, PIN_DRIVE_6, 0, MICROPY_HW_SDIO_D3_ALT);
146162

163+
#ifdef MIMXRT117x_SERIES
164+
CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd2, 24);
165+
166+
clock_root_config_t rootCfg = { 0 };
167+
rootCfg.mux = SDMMC_CLOCK_MUX;
168+
rootCfg.div = 2;
169+
CLOCK_SetRootClock(SDMMC_CLOCK_ROOT, &rootCfg);
170+
#else
147171
// Configure PFD0 of PLL2 (system PLL) fractional divider to 24 resulting in:
148172
// with PFD0_clk = PLL2_clk * 18 / N
149173
// PFD0_clk = 528MHz * 18 / 24 = 396MHz
150174
CLOCK_InitSysPfd(kCLOCK_Pfd0, 24U);
151175
CLOCK_SetDiv(SDMMC_CLOCK_DIV, 1U); // USDHC_input_clk = PFD0_clk / 2
152176
CLOCK_SetMux(SDMMC_CLOCK_MUX, 1U); // Select PFD0 as clock input for USDHC
177+
#endif
153178

154179
// Initialize USDHC
155180
const usdhc_config_t config = {
156181
.endianMode = kUSDHC_EndianModeLittle,
157182
.dataTimeout = 0xFU,
183+
#ifndef MIMXRT117x_SERIES
158184
.readBurstLen = 0,
159185
.writeBurstLen = 0,
186+
#endif
160187
.readWatermarkLevel = 128U,
161188
.writeWatermarkLevel = 128U,
162189
};

0 commit comments

Comments
 (0)