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

esp32 - Spi Drivers freeze app and triggers TG1WDT_SYS_RESET #422

Open
Vollbrecht opened this issue May 22, 2024 · 3 comments
Open

esp32 - Spi Drivers freeze app and triggers TG1WDT_SYS_RESET #422

Vollbrecht opened this issue May 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Vollbrecht
Copy link
Collaborator

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));
    }
}

``
@Vollbrecht Vollbrecht added the bug Something isn't working label Jun 21, 2024
@DaneSlattery
Copy link
Contributor

DaneSlattery commented Jul 16, 2024

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?

  • CLK on GPIO15
  • MISO on GPIO17
  • MOSI on GPIO16
  • CS1 on GPIO18

(PS, the example file comments are lying).

rust-esp32-demo uses these pins:

  • CLK GPIO13
  • MISO on GPIO12
  • MOSI on GPIO26
  • CS on GPIO14

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

  • CLK on GPIO14
  • MISO on GPIO12
  • MOSI on GPIO13
  • CS1 on GPIO15

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

  • CLK on GPIO14
  • MISO on GPIO12
  • MOSI on GPIO13
  • CS on GPIO15

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
Copy link
Collaborator Author

Vollbrecht commented Jul 17, 2024

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants