esp-rs / esp8266-hal

A experimental hardware abstraction layer for the esp8266 written in Rust.
Apache License 2.0
157 stars 16 forks source link

GPIO interrupt is not working as expected. #16

Open m1el opened 3 years ago

m1el commented 3 years ago

I have tried to set up a GPIO interrupt handler the following way:

#[interrupt(gpio)]
fn gpio_intr() {
  // do something
}
#[entry]
fn main() -> ! {
   enable_interrupt(InterruptType::GPIO);
   // ...
}

Full code here: https://gist.github.com/m1el/41b2c1c210d92b45ff015483c9dd59d8 However, the chip hangs immediately upon receiving an interrupt. With some help and reading the manuals, it was discovered that the interrupt routine is getting repeatedly called. This happens because GPIO interrupt status is not getting cleared. After adding (*target::GPIO::ptr()).gpio_status_w1tc.write(|w| w.bits(0xffff)) to the interrupt handler, the code works as expected.

Since interrupt_trampoline clears interrupt status with xtensa_lx::interrupt::clear(mask), one would expect it to clear GPIO interrupt status as well.