Skip to content

hw_timer_t can't be retriggered from inside an interrupt in 2.0.2+ #6693

Closed
@sweetlilmre

Description

@sweetlilmre

Board

ESP32 Dev Module

Device Description

https://www.banggood.com/ESP32-WiFi-+-bluetooth-Development-Board-Ultra-Low-Power-Consumption-Dual-Core-ESP-32-ESP-32S-Similar-ESP8266-Geekcreit-for-Arduino-products-that-work-with-official-Arduino-boards-p-1175488.html

Hardware Configuration

16x2 LCD connected via I2C
SD card connected via SDMMC pins
Rotary encoder connected to general IO

Version

v2.0.2

IDE Name

Platformio 4.2.0 Visual Studio Code

Operating System

Windows 10 x64

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

The code below works in framework-arduinoespressif32 3.20001.0 (2.0.1) and below, but not 2.0.2 and above, including https://github.com/espressif/arduino-esp32.git#142fceb8563cd1795d619829e0a103770a344e1a (which I believe is 2.0.3 as based on the info from this issue: #6689 )

In 2.0.1 or below the serial output shows an increasing value for 'tick', but in any framework version greater than 2.0.1, 'tick' stays at 1 indicating that the interrupt is not retriggered by the timer code inside of it.

Using the PIO Arduino support 4.1.0 (2.0.1) <- Works, tick increments
Using the PIO Arduino support 4.2.0 (2.0.2) <- Does not work, tick is 1 (interrupt fired once)
Using the PIO Arduino support 4.2.0 (2.0.3 from the git hash mentioned above) <- Does not work, tick is 1 (interrupt fired once)

Sketch

#include <Arduino.h>

hw_timer_t *signalTimer;
#define IDLE_TIMER_EXECUTE 1000
volatile uint32_t tick = 0;

void IRAM_ATTR signalTimerFunc()
{
  tick++;
  timerWrite(signalTimer, 0);
  // IDLE_TIMER_EXECUTE is used here for simplicity. The actual next interval would be calculated in the ISR
  timerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
  timerAlarmEnable(signalTimer);
}

void startTimer()
{
  signalTimer = timerBegin(0, 40, true);
  timerAttachInterrupt(signalTimer, &signalTimerFunc, true);
  timerWrite(signalTimer, 0);
  timerAlarmWrite(signalTimer, IDLE_TIMER_EXECUTE, false);
  timerAlarmEnable(signalTimer);
}

void stopTimer()
{
  timerAlarmDisable(signalTimer);
  timerDetachInterrupt(signalTimer);
  timerEnd(signalTimer);
  signalTimer = NULL;
}

void setup()
{
  Serial.begin(115200);
  Serial.println("Starting timer");
  startTimer();
}

void loop()
{
  delay(10);
  Serial.printf("tick: %d\n", tick);
}

Debug Message

No debug, just the serial output as described.

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions