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

sdspi_host_init_slot truncates CD and WP GPIO numbers larger than 32 (IDFGH-2196) #4348

Closed
andyfinity opened this issue Nov 15, 2019 · 0 comments

Comments

@andyfinity
Copy link

Environment

  • Development Kit: none
  • Kit version:
  • Module or chip used: ESP32
  • IDF version: v4.0-beta2-70-g0a03a55c1
  • Build System: CMake
  • Compiler version: 8.2.0
  • Operating System: Linux
  • Power Supply: external 5V

Problem Description

CD and WP in sdspi_slot_config_t used in sdspi_host_init_slot(...) are truncated during a bit shift inside the driver.

Even though pull-up resistors can't be enabled on some pins, their use shouldn't be prohibited. At worst a warning should be displayed. Maybe a note in the SDSPI docs would be worthwhile.

Expected Behavior

Set CD to GPIO_NUM_38 and WP to GPIO_NUM_37 should set CD to GPIO 38 and WP to GPIO 37.

Actual Behavior

Set CD to GPIO_NUM_38 and WP to GPIO_NUM_37 results in GPIO 6 and 5 getting the configuration. Numbers less than 32 work as expected.

As an exciting byproduct, GPIO 6 is used for flash, leading to an immediate core panic.

Code

sdmmc_host_t host = SDSPI_HOST_DEFAULT();
host.slot = VSPI_HOST;

sdspi_slot_config_t slot_cfg = SDSPI_SLOT_CONFIG_DEFAULT();
slot_cfg.gpio_miso = GPIO_NUM_19;
slot_cfg.gpio_mosi = GPIO_NUM_23;
slot_cfg.gpio_sck = GPIO_NUM_18;
slot_cfg.gpio_cs = GPIO_NUM_17;
slot_cfg.gpio_cd = GPIO_NUM_38;

esp_vfs_fat_sdmmc_mount_config_t mount_cfg = { .format_if_mount_failed =
		false, .max_files = 5, .allocation_unit_size = 16 * 1024 };

auto ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_cfg, &mount_cfg,
		&sd_card);

Debug Logs

Notice cd=38 in the first line and GPIO[6] referenced on the second-to-last line.

D (886) sdspi_host: sdspi_host_init_slot: SPI3 miso=19 mosi=23 sck=18 cs=17 cd=38 wp=-1, dma_ch=1
D (895) spi: SPI3 use iomux pins.
D (898) intr_alloc: Connected src 31 to int 17 (cpu 0)
D (903) spi_hal: eff: 400, limit: 80000k(/0), 0 dummy, -1 delay
D (909) spi_master: SPI3: New device added to CS0, effective clock: 400kHz
I (916) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (926) gpio: GPIO[6]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
Guru Meditation Error: Core  0 panic'ed (IllegalInstruction) at pc=400ee149. Setting bp and returning..

After patching bit shifts from (1 << ...) to (1LL << ...) on lines 336 and 343 of components/driver/sdspi_host.c.

D (886) sdspi_host: sdspi_host_init_slot: SPI3 miso=19 mosi=23 sck=18 cs=17 cd=38 wp=-1, dma_ch=1
D (895) spi: SPI3 use iomux pins.
D (898) intr_alloc: Connected src 31 to int 17 (cpu 0)
D (903) spi_hal: eff: 400, limit: 80000k(/0), 0 dummy, -1 delay
D (909) spi_master: SPI3: New device added to CS0, effective clock: 400kHz
I (916) gpio: GPIO[17]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (926) gpio: GPIO[38]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
@github-actions github-actions bot changed the title sdspi_host_init_slot truncates CD and WP GPIO numbers larger than 32 sdspi_host_init_slot truncates CD and WP GPIO numbers larger than 32 (IDFGH-2196) Nov 15, 2019
0xFEEDC0DE64 pushed a commit to 0xFEEDC0DE64/esp-idf that referenced this issue May 5, 2021
* If WebServer.handleClient is run in a tight loop, it will starve other processes.  So, if there is no connection, throw in a delay(1).  Fixes espressif#4348

* Made a variable to control the delay behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant