Skip to content

Commit

Permalink
Fix esp32 timer issues (#2697)
Browse files Browse the repository at this point in the history
HostTests fails on esp32 due to following issues:

**Flawed `hw_timer2_read()` implementation**

Without setting update bit counter value won't change. Probably worked previously because some other code did this.

**WDT with callback timers**

Checked against IDF implementations and there's a missing flag which keeps interrupts initially disabled during setup.

**Callbacks missing during timer testing**

Offending code looks like this:

```
Timer timer;
String s;
s += timer; //<< Not what I expected
```

The above line actually calls the `Timer` copy constructor. Delete this and the compiler catches the error. The corrected line now reads `s += String(timer)`.
  • Loading branch information
mikee47 authored Jan 8, 2024
1 parent 2ab9794 commit e890519
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Sming/Arch/Esp32/Components/driver/hw_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class TimerConfig
#else
int source = timer_group_periph_signals.groups[group].timer_irq_id[index];
#endif
esp_intr_alloc_intrstatus(source, ESP_INTR_FLAG_IRAM, status_reg, mask, timerIsr, this, &isr_handle);
esp_intr_alloc_intrstatus(source, ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_INTRDISABLED, status_reg, mask, timerIsr,
this, &isr_handle);
clear_intr_status();
enable_intr(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ uint32_t hw_timer1_read(void);
__forceinline static uint32_t hw_timer2_read(void)
{
#if CONFIG_ESP_TIMER_IMPL_TG0_LAC
REG_WRITE(TIMG_LACTUPDATE_REG(0), 1);
return REG_READ(TIMG_LACTLO_REG(0));
#elif ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 4, 0)
systimer_ll_counter_snapshot(&SYSTIMER, 0);
Expand Down
7 changes: 6 additions & 1 deletion Sming/Core/CallbackTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ template <typename ApiDef> struct CallbackTimerApi {
return ApiDef::typeName();
}

CallbackTimerApi()
{
}

CallbackTimerApi(const CallbackTimerApi&) = delete;

String name() const
{
String s;
Expand All @@ -50,7 +56,6 @@ template <typename ApiDef> struct CallbackTimerApi {
s += static_cast<const ApiDef*>(this)->getInterval();
s += ", ticks = ";
s += static_cast<const ApiDef*>(this)->ticks();
// s += ApiDef::Clock::ticks();
return s;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/HostTests/host-tests-esp32.hw
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"base_config": "host-tests",
"partitions": {
"factory": {
"size": "1M"
"size": "1600K"
}
}
}
2 changes: 1 addition & 1 deletion tests/HostTests/modules/Timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CallbackTimerTest : public TestGroup
String s;
s += system_get_time();
s += " ";
s += statusTimer;
s += String(statusTimer);
s += " fired, timercount = ";
s += activeTimerCount;
s += ", mem = ";
Expand Down

0 comments on commit e890519

Please sign in to comment.