Panic in uart_rx_intr_handler_default with SPI SD Card (Sparkfun ESP32 Thing)

leehambley
Posts: 2
Joined: Wed Oct 30, 2019 9:47 pm

Panic in uart_rx_intr_handler_default with SPI SD Card (Sparkfun ESP32 Thing)

Postby leehambley » Wed Oct 30, 2019 10:13 pm

Dear Forum,

I hope this isn't a re-post, the search feature did not work well with "sd" as a search term.

I am trying to interface a Sparkfun ESP32 thing with their ESP32 Thing Motion Shield to use SPI SD access.

- https://learn.sparkfun.com/tutorials/es ... okup-guide
- https://learn.sparkfun.com/tutorials/es ... okup-guide

Why SPI SD Access? Well in theid docs they're using an Arduino sketch with the SPI driver included, and writing everything as an arduino sketch, not using IDF.

I am using IDF and my task raises this error (I have CPU set to halt, not to reboot)

Code: Select all

I (2209) main.c: Using SPI peripheral for SD
D (2209) sdspi_host: sdspi_host_init_slot: SPI2 miso=19 mosi=23 sck=18 cs=33 cd=38 wp=-1, dma_ch=1
D (2209) spi: SPI2 use gpio matrix.
V (2219) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): checking args
V (2239) intr_alloc: esp_intr_alloc_intrstatus (cpu 1): Args okay. Resulting flags 0x80E
D (2239) intr_alloc: Connected src 30 to int 3 (cpu 1)
D (2249) spi_hal: eff: 400, limit: 26666k(/2), 0 dummy, -1 delay
D (2269) spi_master: SPI2: New device added to CS0, effective clock: 400kHz
I (2269) gpio: GPIO[33]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (2279) gpio: GPIO[6]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400e0d20: ffff0700 ffffffff ffffffff
0x400e0d20: uart_rx_intr_handler_default at /home/leehambley/esp/esp-idf/components/driver/uart.c:890

Core 1 register dump:
PC      : 0x400e0d25  PS      : 0x00060730  A0      : 0x800d6940  A1      : 0x3ffcc720  
0x400e0d25: uart_rx_intr_handler_default at /home/leehambley/esp/esp-idf/components/driver/uart.c:894

A2      : 0x00000001  A3      : 0x3ffcc818  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00060023  A8      : 0x800df0fc  A9      : 0xffffffff  
A10     : 0x00000000  A11     : 0x00000028  A12     : 0x00000027  A13     : 0x00000000  
A14     : 0x00000000  A15     : 0x00000040  SAR     : 0x00000007  EXCCAUSE: 0x00000000  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffe  

ELF file SHA256: ffffffffffffffffffffffffffffffff0007ffffffffffffffffffffffffffff

Backtrace: 0x400e0d22:0x3ffcc720 0x400d693d:0x3ffcc7a0 0x400d5a57:0x3ffcc7e0 0x40090d55:0x3ffcc870
0x400e0d22: uart_rx_intr_handler_default at /home/leehambley/esp/esp-idf/components/driver/uart.c:894
0x400d693d: esp_vfs_fat_sdmmc_mount at /home/leehambley/esp/esp-idf/components/fatfs/vfs/vfs_fat_sdmmc.c:74
0x400d5a57: init_sd_task at /home/leehambley/esp/hello_world/build/../main/hello_world_main.c:149
0x40090d55: vPortTaskWrapper at /home/leehambley/esp/esp-idf/components/freertos/port.c:143

CPU halted.
My code is taken more-or-less from the https://github.com/espressif/esp-idf/tr ... ge/sd_card example, with some minor mods (the pins for the shield combo that I am using)

Code: Select all

#define SD_SCK_PIN (GPIO_NUM_18)
#define SD_DO_PIN (GPIO_NUM_19)
#define SD_DI_PIN (GPIO_NUM_23)
#define SD_CS_PIN (GPIO_NUM_33)
#define SD_CD_PIN (GPIO_NUM_38)
// ... snip ...
static void init_sd_task(void *args)
{
  ESP_LOGI(TAG, "Using SPI peripheral for SD");
  sdmmc_host_t host = SDSPI_HOST_DEFAULT();
  sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
  slot_config.gpio_miso = SD_DO_PIN;
  slot_config.gpio_mosi = SD_DI_PIN;
  slot_config.gpio_sck = SD_SCK_PIN;
  slot_config.gpio_cs = SD_CS_PIN;
  slot_config.gpio_cd = SD_CD_PIN;

  // Options for mounting the filesystem.
  // If format_if_mount_failed is set to true, SD card will be partitioned and
  // formatted in case when mounting fails.
  esp_vfs_fat_sdmmc_mount_config_t mount_config = {
      .format_if_mount_failed = false,
      .max_files = 5,
      .allocation_unit_size = 16 * 1024};

  // Use settings defined above to initialize SD card and mount FAT filesystem.
  // Note: esp_vfs_fat_sdmmc_mount is an all-in-one convenience function.
  // Please check its source code and implement error recovery when developing
  // production applications.
  sdmmc_card_t *card;
  esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);

  if (ret != ESP_OK)
  {
    if (ret == ESP_FAIL)
    {
      ESP_LOGE(TAG, "Failed to mount filesystem. "
                    "If you want the card to be formatted, set format_if_mount_failed = true.");
    }
    else
    {
      ESP_LOGE(TAG, "Failed to initialize the card (%s). "
                    "Make sure SD card lines have pull-up resistors in place.",
               esp_err_to_name(ret));
    }
    return;
  }

  for (;;)
  {
  }
}
// ... snip ...
xTaskCreatePinnedToCore(init_sd_task, "init_sd_card_task", 8196, NULL, 0, NULL, 1);
As far as I know the only problem I *might* have is pull up, or pull down resistors, but I wouldn't expect a CPU halt from that, and I don't have access to any equipment today to check if they are high or low right now (maybe tomorrow)

The Sparkfun docs don't go into enough detail on whether there are any 10k pull-ups on the required pins.

Can anyone offer advice, or debugging help please?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Panic in uart_rx_intr_handler_default with SPI SD Card (Sparkfun ESP32 Thing)

Postby ESP_Sprite » Fri Nov 01, 2019 9:49 am

Hard to say, but first thought is that you may have a short between the pins that are used for flash and other pins?

leehambley
Posts: 2
Joined: Wed Oct 30, 2019 9:47 pm

Re: Panic in uart_rx_intr_handler_default with SPI SD Card (Sparkfun ESP32 Thing)

Postby leehambley » Fri Nov 01, 2019 9:43 pm

Thanks for the suggestion, it was super helpful to have had 24 hours rest, and to take a fresh look at this thing.

In the end the change was easy. Assigning slot_config.gpio_cs and/or slot_config.gpio_cd cause the issue. Removing those lines and allowing them to keep the value from SDSPI_SLOT_CONFIG_DEFAULT() allows me to proceed to my next error, which puts me back on the path with the documentation. Now I need 10k pull-up resistors.

Code: Select all

I (633) wifi: mode : softAP (24:0a:c4:81:79:55)
I (633) wifi: Total power save buffer number: 16
I (633) wifi: Init max length of beacon: 752/752
I (643) wifi: Init max length of beacon: 752/752
I (643) main.c: wifi_init_softap finished. SSID:ochsenzollblitzer password:supersecretpw
I (653) uart: queue free spaces: 16
I (653) nmea_parser: NMEA Parser init OK
I (673) main.c: Using SPI peripheral for SD
I (673) gpio: GPIO[13]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (843) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (843) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (853) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
E (873) main.c: Failed to initialize the card (ESP_ERR_TIMEOUT). Make sure SD card lines have pull-up resistors in place.
E (883) FreeRTOS: FreeRTOS Task "init_sd_card_ta" should not return, Aborting now!
abort() was called at PC 0x40090d47 on core 1
0x40090d47: vPortTaskWrapper at /home/leehambley/esp/esp-idf/components/freertos/port.c:147


ELF file SHA256: 74641408ae20de7fcbf9bfee14b87abc112dc6de6e145b0770b4f822eeb2aa34

Backtrace: 0x4008db2d:0x3ffdabe0 0x4008df25:0x3ffdac00 0x40090d47:0x3ffdac20
0x4008db2d: invoke_abort at /home/leehambley/esp/esp-idf/components/esp32/panic.c:157

0x4008df25: abort at /home/leehambley/esp/esp-idf/components/esp32/panic.c:174
I now have confirmation that the pins don't have pull-ups in place, and can go back to the docs and proceed.

Thanks so much for the help I see you giving to many people across the forum.

Who is online

Users browsing this forum: FrankJensen, MikeMyhre and 121 guests