esp-rs / esp-idf-hal

embedded-hal implementation for Rust on ESP32 and ESP-IDF
https://docs.esp-rs.org/esp-idf-hal/
Apache License 2.0
478 stars 172 forks source link

esp32 - Spi Drivers freeze app and triggers TG1WDT_SYS_RESET #422

Open Vollbrecht opened 6 months ago

Vollbrecht commented 6 months ago

By esp32 -> classical esp32

Key observation is that it does work with gpio 15-18 for sclk,mosi,miso,cs and some minimal random other pin combinations, changing one or two of them, but most combinations of pinnumbers will freeze the esp and trigger a reset after varying seconds.

Use default cargo generate template.

Minimal repo:


use esp_idf_svc::hal::peripherals::Peripherals;
use esp_idf_svc::hal::spi::{SpiDeviceDriver, SpiDriverConfig, SPI2};

fn main() {
    esp_idf_svc::sys::link_patches();
    esp_idf_svc::log::EspLogger::initialize_default();

    // Bind the log crate to the ESP Logging facilities
    let peripherals = Peripherals::take().unwrap();

    let sclk = peripherals.pins.gpio15;
    let miso = peripherals.pins.gpio12;
    let mosi = peripherals.pins.gpio11;
    let cs = peripherals.pins.gpio13;

    let driver_conf = SpiDriverConfig::new();
    let driver = SpiDeviceDriver::new_single::<SPI2>(
        peripherals.spi2,
        sclk,
        miso,
        Some(mosi),
        Some(cs),
        &driver_conf,
        &Default::default(),
    )
    .unwrap();

    loop {
        log::info!("Hello, world!");
        std::thread::sleep(std::time::Duration::from_secs(1));
    }
}

``
DaneSlattery commented 4 months ago

Does this mean that SPI will not work at all when assigned to different pins on the esp32, or is this a rare bug?

What pins actually can be used?

Those given in the esp-idf-hal/examples/loopback?

(PS, the example file comments are lying).

rust-esp32-demo uses these pins:

The ESP-IDF docs suggests the use of these pins for SPI2

And finally, esp-idf C examples suggest these pins:

I had intended to connect to a KSZ8851SNL and an SD Card via SPI, and I don't want to get my pin assignments wrong when I submit to the PCB manufacturer

Vollbrecht commented 4 months ago

The recommendation is to use this special gpio's because of potential minimal latency gains, since this gpio's dont need to go through the gpio matrix. Though they claim that any gpio can be used for the SPI2 device. quote: "However, the signals can also be routed to any other available pins using the less direct GPIO matrix." And that should be certainly true. I tried to debug it a bit but for some unknown reason my esp hard crashes and it's hard to debug the issue currently. I only know that it happens somewhere in the initiation phase inside the gpio matrix code path.

DaneSlattery commented 4 months ago

I guess my question is, which special GPIOs actually do work? And which devices are affected?