zephyr: imx_usdhc: SD-Card mount on MIMXRT1170 Board fails

Describe the bug The SD-Card mounting process often fails on the NXP MIMXRT1170 Eval Board. The board is unable to switch to higher frequencies, and hangs with an error Card never left busy state (-5).

  • What target platform are you using? mimxrt1170_evk_cm7 (NXP MIMXRT1170 Eval Board)

  • What have you tried to diagnose or workaround this issue? I have tried to

  • Is this a regression? If yes, have you been able to “git bisect” it to a specific commit? A similar issue had been reported (https://github.com/zephyrproject-rtos/zephyr/issues/39942), which suggests no-1-8-v as a workaround. This, however, reduces the read write speeds. I have also tried successive mounts, which works around 75% of the time. Also tried to increase the delay

To Reproduce Steps to reproduce the behavior:

static FATFS fs;
static struct fs_mount_t mount = {
	.type = FS_FATFS,
	.fs_data = &fs,
	.mnt_point = "/SD:",
};

int main(void)
{
	int res = fs_mount(&mount));
	if(res) {
		LOG_ERR("Mounting file system failed, Error %d", -EIO);
	}

	return res;
}

Following project variables are enabled:

CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_EXFAT=y
CONFIG_FS_LOG_LEVEL_INF=y
CONFIG_FS_FATFS_MOUNT_MKFS=n
CONFIG_SD_LOG_LEVEL_INF=y
CONFIG_SDHC_LOG_LEVEL_INF=y
CONFIG_SDMMC_LOG_LEVEL_INF=y

Expected behavior The SD-Card mount should be successful, the following logs:

00:00:08.767,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power OFF, voltage 3.3V
[00:00:09.267,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power ON, voltage 3.3V
[00:00:09.788,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 400000Hz, card power ON, voltage 3.3V
[00:00:09.788,000] <dbg> usdhc: imx_usdhc_set_io: BUS CLOCK: 386718
[00:00:09.987,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power ON, voltage 3.3V
[00:00:09.987,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power ON, voltage 1.8V
[00:00:10.017,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 400000Hz, card power ON, voltage 1.8V
[00:00:10.017,000] <dbg> usdhc: imx_usdhc_set_io: BUS CLOCK: 386718
[00:00:10.018,000] <inf> sd: Card switched to 1.8V signaling
[00:00:10.021,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 25000000Hz, card power ON, voltage 1.8V
[00:00:10.021,000] <dbg> usdhc: imx_usdhc_set_io: BUS CLOCK: 24750000
[00:00:10.022,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 4, clock 25000000Hz, card power ON, voltage 1.8V
[00:00:10.115,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 4, clock 208000000Hz, card power ON, voltage 1.8V
[00:00:10.115,000] <dbg> usdhc: imx_usdhc_set_io: BUS CLOCK: 198000000
[00:00:10.196,000] <dbg> fs: fs_mount: fs mounted at /SD:

Actual behavior The SD-Card mount fails, with the following logs:

[00:00:07.596,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power OFF, voltage 3.3V
[00:00:08.096,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 0Hz, card power ON, voltage 3.3V
[00:00:08.617,000] <dbg> usdhc: imx_usdhc_set_io: SDHC I/O: bus width 1, clock 400000Hz, card power ON, voltage 3.3V
[00:00:08.617,000] <dbg> usdhc: imx_usdhc_set_io: BUS CLOCK: 386718
[00:00:19.129,000] <err> sd: Card never left busy state
[00:00:19.129,000] <err> sd: Failed to query card OCR
[00:00:19.129,000] <err> fs: fs mount error (-5)

Impact Prototype: Annoyance Series: Showstopper

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK with West
  • Version used: 3.5.99

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

Thank you @skumg

@danieldegrasse is the AUTO_INIT workaround enough or should we continue to debug more?

The following pull request had actually solved the issue for us: https://github.com/zephyrproject-rtos/zephyr/pull/70311. I shall close this issue as resolved. Sorry for the delay.

Hi @skumg , Thank you for sharing these details. It seems there is some interaction during initialization causing the issue mounting the SD card. I am glad you found the CONFIG_NET_CONFIG_AUTO_INIT=n workaround.

Best regards

Hi @skumg , Yes, I reset the EVK many times in my testing, and I did not see this issue mounting the SD cards I tested.

Also, I do not think https://github.com/zephyrproject-rtos/zephyr/issues/38575 applies to this board. First, in my testing with the RT1170 EVK, I saw from the log that the SDHC driver switched to 1.8 V and was able to mount those cards.

Second, https://github.com/zephyrproject-rtos/zephyr/issues/38575 is specific to how the voltage level is changed on the other MIMXRT685-EVK. On that board, the voltage level for the SDHC pins is controlled by the PCA9420 PMIC regulator, specifically the LDO2_OUT supply rail. So https://github.com/zephyrproject-rtos/zephyr/issues/38575 states the SDHC driver needs to request the PMIC regulator driver to change the voltage of that supply.

But on the MIMXRT1170-EVK board, the MCU signal USDHC1_VSELECT is used to select this voltage, which is controlled by the uSDHC peripheral. No regulator driver required. USDHC1_VSELECT is connected to the board signal SD1_VSELECT, which controls U36 to supply the selected voltage level. So https://github.com/zephyrproject-rtos/zephyr/issues/38575 does not apply to this board.

Best regards

Hi @skumg , I have not been able to replicate this with the MIMXRT1170-EVK and the few uSD cards I have. However, we are looking into the error in your log and what may cause it. Best regards

Hi @skumg , Thank you for reporting this. Since there are two revisions of the RT1170 EVK, can you please confirm if the part number on your board includes EVKB? I see you are building for mimxrt1170_evk_cm7, but I just want to confirm if you are using the original EVK or the latest EVKB. I am not sure yet if that matters for your issue, but I will try to replicate on the same hardware. Thanks

Hi @DerekSnell, I have the MIMXRT1170-EVK (first gen) board, not the EVKB (with SCH-32171 REV C4 / 700-32171 REV A1, in case that helps). Also using the default configuration, and have tested this with 4GB and 16 GB cards (both Class 10).