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

GPIO0 (button in my case) re-initialized when sdmmc component fails to find valid card (IDFGH-14570) #15328

Open
3 tasks done
LucienMP opened this issue Feb 4, 2025 · 1 comment
Assignees
Labels
Status: Reviewing Issue is being reviewed Type: Bug bugs in IDF

Comments

@LucienMP
Copy link

LucienMP commented Feb 4, 2025

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.4.0

Espressif SoC revision.

ESP32-S3 (v0.2)

Operating System used.

Windows

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

PowerShell

Development Kit.

LilyGo T-Dongle

Power Supply used.

USB

What is the expected behavior?

When combining the SDMMC driver and the Button driver and no sdcard inserted I expect the sdcard to fail, and the button(on GPIO0) to continue to work. What I expect to happen is the initialization function copies GPIO_NUM_NC for unused D[7-1] pins depending on the width of the TF card slot, or that the deinit_slot routines account for width and only deinit pins they used.

What is the actual behavior?

After the SDCARD fails to detect the GPIO pin is re-verted to some uninitialized state and the button no longer works.

What appears to be happening is that the SDMMC fails to find a card and so it enters a state of de-initializing the card slot.
(See: sdmmc_host_deinit_slot_internal ). However this does not consider the width of the slot specified, nor does the initialization copy the config data for non-connected pins across resulting in potentially all of the unused D7-D1 pins being defaulted to 0 and re-initializing the GPIO0 pin (at best).

See file:
https://github.com/espressif/esp-idf/blob/master/components/esp_driver_sdmmc/src/sdmmc_host.c

Initialization

#if SOC_SDMMC_USE_GPIO_MATRIX
    if (use_gpio_matrix) {
        /* Save pin configuration for this slot */
        slot_gpio->clk = slot_config->clk;
        slot_gpio->cmd = slot_config->cmd;
        slot_gpio->d0 = slot_config->d0;
...

then at de-initialization ALL pins are de-initialized causing whatever value was in the slot_gpio->d#n to be put back onto the pin state.

    for (size_t i = 0; i < (sizeof(gpio->val) / (sizeof(gpio->val[0]))); i++) {
        gpio_pin_num = gpio->val[i];
        if (gpio_pin_num != GPIO_NUM_NC && GPIO_IS_VALID_GPIO(gpio_pin_num)) {
            gpio_reset_pin(gpio_pin_num);
        }
    }

This conflicted on the LillyGo T-Dongle when the button is in use as its on GPIO0. Fortunately it seems the structure is initialized to zero, but I could guess there are case it could contain random corrupted values.

Image

Steps to reproduce.

  1. Setup a design to contain button and sdmmc components
  2. Initialize the button and driver
  3. Flash the board, but leave the sdcard out of the socket (no card installed)
  4. Wait for the design to fail to find the card
  5. Try to use the button - it will show "button pin low" as it has now been re-initialized by the failing sdcard
    ...

Debug Logs.

None, as you have to visually see the button not functioning

More Information.

Attached is the workaround I put into the sdmmc_host,c

Image

@LucienMP LucienMP added the Type: Bug bugs in IDF label Feb 4, 2025
@github-actions github-actions bot changed the title GPIO0 (button in my case) re-initialized when sdmmc component fails to find valid card GPIO0 (button in my case) re-initialized when sdmmc component fails to find valid card (IDFGH-14570) Feb 4, 2025
@espressif-bot espressif-bot added the Status: Opened Issue is new label Feb 4, 2025
@igrr
Copy link
Member

igrr commented Feb 4, 2025

However this does not consider the width of the slot specified

Thanks for the issue report and for finding the root cause. We'll get this fixed!

@espressif-bot espressif-bot added Status: In Progress Work is in progress Status: Reviewing Issue is being reviewed and removed Status: Opened Issue is new Status: In Progress Work is in progress labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Reviewing Issue is being reviewed Type: Bug bugs in IDF
Projects
None yet
Development

No branches or pull requests

3 participants