From 8f46bade7afe7b38f861b9da8c7284b3988dd7b9 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 28 Jun 2021 15:44:30 +0300 Subject: [PATCH] Fix hardware timers Fixes: https://github.com/espressif/arduino-esp32/issues/5337 Fixes: https://github.com/espressif/arduino-esp32/issues/4743 Thanks to @maxgerhardt --- cores/esp32/esp32-hal-timer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-timer.c b/cores/esp32/esp32-hal-timer.c index d6570383..12555fd3 100644 --- a/cores/esp32/esp32-hal-timer.c +++ b/cores/esp32/esp32-hal-timer.c @@ -47,7 +47,7 @@ #define HWTIMER_LOCK() portENTER_CRITICAL(timer->lock) #define HWTIMER_UNLOCK() portEXIT_CRITICAL(timer->lock) -typedef struct { +typedef volatile struct { union { struct { uint32_t reserved0: 10; @@ -272,6 +272,12 @@ void timerEnd(hw_timer_t *timer){ } void timerAttachInterrupt(hw_timer_t *timer, void (*fn)(void), bool edge){ +#if CONFIG_IDF_TARGET_ESP32 + if(edge){ + log_w("EDGE timer interrupt does not work properly on ESP32! Setting to LEVEL..."); + edge = false; + } +#endif static bool initialized = false; static intr_handle_t intr_handle = NULL; if(intr_handle){