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

Teensy41 support SDHC - Storage init Error #42227

Closed
EmbedWise opened this issue Jan 27, 2022 · 13 comments · Fixed by #42379 or #77301
Closed

Teensy41 support SDHC - Storage init Error #42227

EmbedWise opened this issue Jan 27, 2022 · 13 comments · Fixed by #42379 or #77301
Assignees
Labels
area: Boards area: Storage Storage subsystem bug The issue is a bug, or the PR is fixing a bug platform: NXP NXP priority: low Low impact/importance bug

Comments

@EmbedWise
Copy link

Describe the bug
Working on the Teensy41 and trying to get the SD Card functionality to work. For this using the application developed by @bdkrae / @ufechner7. See https://github.com/bdkrae/zephyr_teensy4_test. Which is based on the zephyr/samples/subsys/fs/fat_fs.

Please also mention any information which could help others to understand
the problem you're facing:

  • Using a Teensy41
  • SanDisk Edge 4GB Micro SD, both tried with a formatted (MS-DOS and ExFAT partition)

I have also tried to follow the instructions

Card voltage switch
Teensy 4.1 has no hardware to switch card voltage. As a workaround in the file zephyr/drivers/disk/usdhc.c the line 502 needs to be changed:

#define SDMMCHOST_NOT_SUPPORT USDHC_HOST_CTRL_CAP_VS18(1)

This prevents the driver from trying to switch over to 1,8V supply for the card. Also, a dummy pin is defined in board defs.

I cannot find this Macro where that is defined. I already tried using the FLAG directly USDHC_HOST_CTRL_CAP_VS18_MASK. Still the same error.

To Reproduce
Using Zephyr 2.7.1

Expected behavior
SD Card should have been mounted

Logs and console output

[00:00:00.501,000] <inf> usdhc: USDHC detection other than GPIO
[00:00:00.501,000] <err> sdhc: Storage init ERROR!

Environment:

  • OS: MacOS
  • Toolchain GNU 10.3.1
  • Zephyr 2.7.1
@EmbedWise EmbedWise added the bug The issue is a bug, or the PR is fixing a bug label Jan 27, 2022
@EmbedWise
Copy link
Author

EmbedWise commented Jan 28, 2022

I tested the interface with Arduino and the same SD card. Which works and shows both information and files on the SD card. So this confirms it is setting/driver related

@EmbedWise
Copy link
Author

When the function usdhc_board_access_init is ran in zephyr/driver/disk/usdhc.c

if (!priv->detect_gpio) {
		LOG_INF("USDHC detection other than GPIO");
		priv->inserted = true;
		/* DATA3 does not monitor card insertion */
		base->PROT_CTRL &= ~USDHC_PROT_CTRL_D3CD_MASK;
		if ((base->PRES_STATE & USDHC_PRES_STATE_CINST_MASK) != 0) {
			priv->inserted = true;
		} else {
			priv->inserted = false;
			return -ENODEV;
		}
	} else {
		ret = usdhc_cd_gpio_init(priv->detect_gpio,
				config->detect_pin,
				config->detect_flags,
				&priv->detect_cb);
		if (ret) {
			return ret;
		}
		ret = gpio_pin_get(priv->detect_gpio, config->detect_pin);
		if (ret < 0) {
			return ret;
		}

		gpio_level = ret;

		if (gpio_level == 0) {
			priv->inserted = false;
			LOG_ERR("NO SD inserted!");

			return -ENODEV;
		}

		priv->inserted = true;
		LOG_INF("SD inserted!");
	}

Additional information:
The card present switch is not connected to the i.mxrt of the Teensy 4.1 .

So the cd-gpios in the dts should not be there.

The statement if ((base->PRES_STATE & USDHC_PRES_STATE_CINST_MASK) != 0) { evaluates false and therefore does not detect the SD card. I could not find where this flag should be set.

Result is the card is never detected

A dirty workaround is to add this to the dts or overlay and then it works:

&usdhc1 {
	status = "okay";
	no-1-8-v;
	cd-gpios = < &gpio3 21 GPIO_ACTIVE_HIGH>;
};

Note that I also add no-1-8-v;
Which applicable to the Teensy4.1

@jfischer-no
Copy link
Collaborator

@EmbedWise , would you like to open a PR to fix it in boards/arm/teensy4/teensy41.dts please?

@danieldegrasse
Copy link
Collaborator

@EmbedWise I don't have a teensy board to test this fix on, but looking at the schematic for the board it looks like the chip detect line for the SD card is not routed. The USDHC driver supports detecting a card via the internal pull up resistor on the DAT3 line. I've opened a PR (#42379) to switch the teensy41 board to using the DAT3 method of detecting SD card presence, instead of the dummy GPIO that was in use. Can you test that PR and verify it works for you? I would use the tests/drivers/disk test.

carlescufi pushed a commit that referenced this issue Feb 2, 2022
teensy41 has no chip detect signal for SD slot. Use DAT3 pull card
detection. Remove software defined chip detect IOMUXC selection that was
used as a dummy pin.

Fixes #42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
@danieldegrasse
Copy link
Collaborator

The PR is in main now, so you should be able to verify the fix with the latest version of Zephyr. I tested the fix on an RT1060 EVK, which has the same SoC as the teensy 4.1, but I would still like to get your feedback if possible to ensure the fix was valid @EmbedWise

@EmbedWise
Copy link
Author

@danieldegrasse I will test it and revert back to you.

@EmbedWise
Copy link
Author

EmbedWise commented Feb 9, 2022

The PR is in main now, so you should be able to verify the fix with the latest version of Zephyr. I tested the fix on an RT1060 EVK, which has the same SoC as the teensy 4.1, but I would still like to get your feedback if possible to ensure the fix was valid @EmbedWise

I verified it on the Teensy 4.1 board but it is not detecting the SD card. Code that I used can be found on Github https://github.com/EmbedWise/zephyr_teensy4_app

And used a775606 of the Zephyr repository.

If I change it to a dummy GPIO it works and detects the card.

@danieldegrasse
Copy link
Collaborator

@EmbedWise, taking another look at this, there is no power control circuitry for the SD card, so that may be causing the SD card detection with DAT3 to fail. What specific error do you see when using DAT3 card detection, as opposed to the dummy GPIO?

@EmbedWise
Copy link
Author

@danieldegrasse there is indeed no power control circuit. The error I see it the following:

[00:00:02.001,000] <inf> main: Started zephyr 3.0.0 on board arm/teensy41.
[00:00:05.000,000] <inf> usdhc: USDHC detection other than GPIO
[00:00:05.001,000] <inf> usdhc: USDHC detection using DAT3 pull
[00:00:05.001,000] <err> sdhc: Storage init ERROR!

@bearsh
Copy link
Contributor

bearsh commented Aug 20, 2024

I just tried the samples/subsys/usb/mass example and it still does not work out of the box...

maybe this issue should get reopened.

@danieldegrasse
Copy link
Collaborator

I just tried the samples/subsys/usb/mass example and it still does not work out of the box...

maybe this issue should get reopened.

Probably so, I'll go ahead and do that. This board doesn't have any card detect circuitry, so I think the best solution may be to modify the driver to assume a card is present if no card detect method is configured.

danieldegrasse added a commit to nxp-upstream/zephyr that referenced this issue Aug 20, 2024
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes zephyrproject-rtos#42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
@danieldegrasse
Copy link
Collaborator

danieldegrasse commented Aug 20, 2024

@bearsh can you try #77301 on your board? or just try the latest main, as that PR has merged

@nashif nashif closed this as completed in 17f71e1 Aug 22, 2024
nordic-bami pushed a commit to nordic-bami/zephyr that referenced this issue Aug 23, 2024
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes zephyrproject-rtos#42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
@bearsh
Copy link
Contributor

bearsh commented Aug 26, 2024

@bearsh can you try #77301 on your board? or just try the latest main, as that PR has merged

yes, works! thanks!

danieldegrasse added a commit to nxp-upstream/zephyr that referenced this issue Aug 26, 2024
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes zephyrproject-rtos#42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
(cherry picked from commit 17f71e1)
Chenhongren pushed a commit to Chenhongren/zephyr that referenced this issue Aug 29, 2024
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes zephyrproject-rtos#42227

(cherry picked from commit 17f71e1)

Original-Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
GitOrigin-RevId: 17f71e1
Cr-Build-Id: 8738819815572775377
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8738819815572775377
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I2205284a9c94d4f9b6b0592ab17417686b4ead19
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5807813
Reviewed-by: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Commit-Queue: Eric Yilun Lin <yllin@google.com>
nashif pushed a commit that referenced this issue Aug 31, 2024
The imx USDHC driver previously queried the peripheral's internal card
detect signal to check card presence if no card detect method was
configured. However, some boards do not route the card detect signal and
do not work correctly with the DAT3 detection method supported by this
peripheral. As a fallback, assume the card is present in the slot but
log a warning to the user.

Fixes #42227

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
(cherry picked from commit 17f71e1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Boards area: Storage Storage subsystem bug The issue is a bug, or the PR is fixing a bug platform: NXP NXP priority: low Low impact/importance bug
Projects
None yet
5 participants