You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Task1: Loop: Toggle GPIO3, wait 2500us, toggle, wait 9876us
Task2: Loop: Waits for edge on GPIO21 (connected to GPIO3), debounced with 2500us using select (not sure if that is relevant)
After a somewhat random amount of toggles, the whole thing freezes (apparently).
If I change one of the 2500us delays to for example 2480us, it happens with a lower probability per toggle.
If the delays are more than 50us apart, it doesnt happen at all (or I didn't wait long enough). So timing is key I guess.
If I start the debugger and press pause in this seemingly frozen state, I always see the following stack trace:
#![no_std]
#![no_main]
#![feature(impl_trait_in_assoc_type)]
use defmt as _;
use embassy_futures::select::{Either, select};
use esp_hal_embassy::InterruptExecutor;
use panic_rtt_target as _;
use defmt::info;
use embassy_executor::Spawner;
use embassy_time::Timer;
use esp_hal::{
clock::CpuClock,
gpio::{DriveMode, GpioPin, Input, InputConfig, Level, Output, OutputConfig, Pull},
interrupt::{Priority, software::SoftwareInterruptControl},
timer::systimer::SystemTimer,
};
use static_cell::StaticCell;
static INTERRUPT_EXECUTOR: StaticCell<InterruptExecutor<0>> = StaticCell::new();
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
rtt_target::rtt_init_defmt!();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let p = esp_hal::init(config);
let system_timer = SystemTimer::new(p.SYSTIMER);
esp_hal_embassy::init(system_timer.alarm0);
info!("Initialized!");
let software_interrupts = SoftwareInterruptControl::new(p.SW_INTERRUPT);
let interrupt_exeuctor = INTERRUPT_EXECUTOR.init_with(|| InterruptExecutor::new(software_interrupts.software_interrupt0));
let interrupt_spwaner = interrupt_exeuctor.start(Priority::Priority1);
interrupt_spwaner.must_spawn(stepper_decoder_task(p.GPIO21));
interrupt_spwaner.must_spawn(toggle_task(p.GPIO3));
}
#[embassy_executor::task]
pub async fn toggle_task(pin: GpioPin<3>) {
let output_config = OutputConfig::default().with_drive_mode(DriveMode::PushPull);
let mut output = Output::new(pin, Level::Low, output_config);
loop {
output.toggle();
Timer::after_micros(2500).await;
// the following is just to have a visible indicator if it is still running or not
output.toggle();
Timer::after_micros(9876).await; // this timeout doesn't seem to change anything about that at all
}
}
#[embassy_executor::task]
pub async fn stepper_decoder_task(pin: GpioPin<21>) {
let input_config = InputConfig::default().with_pull(Pull::Down);
let mut input = Input::new(pin, input_config);
loop {
wait_for_input_changes_debounced(&mut input, 2500).await;
}
}
async fn wait_for_input_changes_debounced(input: &mut Input<'_>, microseconds: u64) {
input.wait_for_any_edge().await;
loop {
let res = select(input.wait_for_any_edge(), Timer::after_micros(microseconds)).await;
if let Either::Second(_) = res {
break;
}
}
}
Expected behavior
Keep running. I don't think the code creates any race condition in itself
Environment
Target device: ESP32-C6
Crate name and version: esp-hal-1.0.0-beta.0
The text was updated successfully, but these errors were encountered:
Bug description
I have the following code, which does:
Task1: Loop: Toggle GPIO3, wait 2500us, toggle, wait 9876us
Task2: Loop: Waits for edge on GPIO21 (connected to GPIO3), debounced with 2500us using select (not sure if that is relevant)
After a somewhat random amount of toggles, the whole thing freezes (apparently).
If I change one of the 2500us delays to for example 2480us, it happens with a lower probability per toggle.
If the delays are more than 50us apart, it doesnt happen at all (or I didn't wait long enough). So timing is key I guess.
If I start the debugger and press pause in this seemingly frozen state, I always see the following stack trace:
The following loop seems to never end:
esp-hal/esp-hal/src/gpio/mod.rs
Line 2394 in 0876bac
To Reproduce
Expected behavior
Keep running. I don't think the code creates any race condition in itself
Environment
The text was updated successfully, but these errors were encountered: