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

GPIO regression on esp32 after touch peripheral was merged #1943

Closed
plaes opened this issue Aug 13, 2024 · 2 comments · Fixed by #1956
Closed

GPIO regression on esp32 after touch peripheral was merged #1943

plaes opened this issue Aug 13, 2024 · 2 comments · Fixed by #1956
Assignees
Labels
bug Something isn't working chip:esp32 Issue related to ESP32 chip peripheral:gpio GPIO peripheral
Milestone

Comments

@plaes
Copy link
Contributor

plaes commented Aug 13, 2024

Following example (link to full repository) started failing on esp32 (version 3.0) after PR #1873 was merged:

#![no_std]
#![no_main]

use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};

use esp_backtrace as _;
use esp_println as _;

use esp_hal::{
    clock::ClockControl,
    gpio::{any_pin::AnyPin, Input, Io, Level, Output, Pull},
    peripherals::Peripherals,
    prelude::*,
    system::SystemControl,
    timer::{timg::TimerGroup, ErasedTimer, OneShotTimer},
};

use static_cell::StaticCell;

macro_rules! mk_static {
    ($t:ty,$val:expr) => {{
        static STATIC_CELL: StaticCell<$t> = StaticCell::new();
        STATIC_CELL.uninit().write(($val))
    }};
}

#[main]
async fn main(spawner: Spawner) {
    defmt::debug!("Init!");

    let peripherals = Peripherals::take();
    let system = SystemControl::new(peripherals.SYSTEM);
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks);
    let timer0: ErasedTimer = timg0.timer0.into();
    let timers = [OneShotTimer::new(timer0)];
    let timers = mk_static!([OneShotTimer<ErasedTimer>; 1], timers);

    defmt::debug!("Init clocks!");

    esp_hal_embassy::init(&clocks, timers);

    let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

    defmt::debug!("Prepare GPIO!");

    let prg_button = io.pins.gpio0;
    spawner.spawn(button_detect(AnyPin::new(prg_button))).ok();

    let blue_led = io.pins.gpio2;
    spawner.spawn(led_blinker(AnyPin::new(blue_led))).ok();

    loop {
        defmt::info!("MAIN LOOP!");
        Timer::after(Duration::from_millis(5_000)).await;
    }
}

#[embassy_executor::task]
async fn led_blinker(pin: AnyPin<'static>) {
    let mut led = Output::new(pin, Level::High);

    loop {
        Timer::after(Duration::from_millis(500)).await;
        led.toggle();
    }
}

#[embassy_executor::task]
async fn button_detect(pin: AnyPin<'static>) {
    let mut button = Input::new(pin, Pull::Down);

    loop {
        button.wait_for_any_edge().await;
        if button.is_high() {
            defmt::info!("Button pressed!");
        } else {
            defmt::info!("Button released!");
        }
    }
}

App crashes with following output:

[DEBUG] - Init!
[DEBUG] - Init clocks!
[DEBUG] - Prepare GPIO!
[INFO] - MAIN LOOP!
[ERROR] - panicked at 'Unsupported'
[ERROR] - !! A panic occured in '/home/plaes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/defmt-0.3.8/src/lib.rs', at line 367, column 5:
[ERROR] - "panicked at /home/plaes/.cargo/registry/src/index.crates.io-6f17d22bba15001f/defmt-0.3.8/src/lib.rs:367:5:\nexplicit panic"
[ERROR] - Backtrace:

Reverting just these two lines makes things working again:

diff --git a/esp-hal/src/soc/esp32/gpio.rs b/esp-hal/src/soc/esp32/gpio.rs
index fb8b29ed..69f05196 100644
--- a/esp-hal/src/soc/esp32/gpio.rs
+++ b/esp-hal/src/soc/esp32/gpio.rs
@@ -871,9 +871,11 @@ pub(crate) fn errata36(pin_num: u8, pull_up: Option<bool>, pull_down: Option<boo
 }
 
 crate::gpio::gpio! {
-    (0, 0, InputOutputAnalogTouch (5 => EMAC_TX_CLK) (1 => CLK_OUT1))
+    (0, 0, InputOutputAnalog (5 => EMAC_TX_CLK) (1 => CLK_OUT1))
+    // XXX (0, 0, InputOutputAnalog (5 => EMAC_TX_CLK) (1 => CLK_OUT1))
     (1, 0, InputOutput (5 => EMAC_RXD2) (0 => U0TXD 1 => CLK_OUT3))
-    (2, 0, InputOutputAnalogTouch (1 => HSPIWP 3 => HS2_DATA0 4 => SD_DATA0) (3 => HS2_DATA0 4 => SD_DATA0))
+    (2, 0, InputOutputAnalog (1 => HSPIWP 3 => HS2_DATA0 4 => SD_DATA0) (3 => HS2_DATA0 4 => SD_DATA0))
+    // XXX (2, 0, InputOutputAnalog (1 => HSPIWP 3 => HS2_DATA0 4 => SD_DATA0) (3 => HS2_DATA0 4 => SD_DATA0))
     (3, 0, InputOutput (0 => U0RXD) (1 => CLK_OUT2))
     (4, 0, InputOutputAnalogTouch (1 => HSPIHD 3 => HS2_DATA1 4 => SD_DATA1 5 => EMAC_TX_ER) (3 => HS2_DATA1 4 => SD_DATA1))
     (5, 0, InputOutput (1 => VSPICS0 3 => HS1_DATA6 5 => EMAC_RX_CLK) (3 => HS1_DATA6))

@jounathaen

@plaes plaes changed the title GPIO regression on esp32 after touch peripheral #1873 was merged GPIO regression on esp32 after touch peripheral was merged Aug 13, 2024
@bjoernQ
Copy link
Contributor

bjoernQ commented Aug 14, 2024

I can reproduce this on current main

@jessebraham jessebraham added bug Something isn't working peripheral:gpio GPIO peripheral labels Aug 14, 2024
@MabezDev MabezDev added this to the 0.20.0 milestone Aug 14, 2024
@tom-borcin tom-borcin added the chip:esp32 Issue related to ESP32 chip label Aug 14, 2024
@jounathaen
Copy link
Contributor

Hmm, interesting and unfortunate. Unfortunately, I won't be able to look into it until next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chip:esp32 Issue related to ESP32 chip peripheral:gpio GPIO peripheral
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants