Repository navigation
PWM ISR watchdog - #3681
PWM ISR watchdog#3681
Conversation
CapnBry
left a comment
There was a problem hiding this comment.
Seems like a nice safety measure. I'm willing to bet that the ESP is doing just fine because its low voltage limit is insanely low, but the RF chip usually will start glitching first and it is likely doing something that's causing our code to just get caught in a loop somewhere.
At least this should stop it, but I did not figure out a way to reproduce the behavior for testing. It ran for an hour though against my ESP32 capture tester with no weird behavior and max 1600ns deviation in any sampling period (150 cycles)
(ns) mean=1499962 min=1499212 max=1500662 range=1450 (1600)
(ns) mean=1499987 min=1499225 max=1500675 range=1450 (1600)
(ns) mean=1499962 min=1499250 max=1500687 range=1437 (1600)
(ns) mean=1500012 min=1499362 max=1500712 range=1350 (1600)
(ns) mean=1499962 min=1499225 max=1500712 range=1487 (1600)
(ns) mean=1500000 min=1499237 max=1500675 range=1438 (1600)
(ns) mean=1500000 min=1499237 max=1500687 range=1450 (1600)
(ns) mean=1499975 min=1499262 max=1500637 range=1375 (1600)
(ns) mean=1500012 min=1499212 max=1500712 range=1500 (1600)
(ns) mean=1499987 min=1499525 max=1500662 range=1137 (1600)
(ns) mean=1499987 min=1499275 max=1500600 range=1325 (1600)
(ns) mean=1500000 min=1499187 max=1500700 range=1513 (1600)
(ns) mean=1500012 min=1499312 max=1500675 range=1363 (1600)
(ns) mean=1499975 min=1499250 max=1500687 range=1437 (1600)
(ns) mean=1499975 min=1499187 max=1500700 range=1513 (1600)
(ns) mean=1499975 min=1499200 max=1500700 range=1500 (1600)
|
Whoa that's sort of nuts that PWM keeps, but the SuperP has register-based hardware PWM so a brown out event could possibly leave some of those registers and peripheral mux values set until software boots and clears it all back to a known state. I wonder if it is in the bootloader doing PWM because that would be pretty nuts and difficult to stop. Is UART0 connected to the logic analyzer? There's that There's no place we could put this PR's code on ESP32 though, maybe attach a pin interrupt to the first servo pin and check this PWMWD there? Or create another RTOS task on the other core with a tiny stack that checks the same thing? I'm not sure the disposition of the other core in this situation but we might have to put that off if we want to get 4.1 out and save ESP32 for 4.2. |
|
I still approve of this change |





Summary
This PR should fix the runaway behaviour seen on ESP8285-based receivers using PWM/servo outputs.
Also included in this PR is an early reset of PWM modules (MCPWM, LEDC & RMT) on ESP32 devices.
Problem
On ESP8266/ESP8285, PWM is provided by a timer ISR, PWM output generation continues inside the waveform ISR after the last pulse configuration has been written. If channel updates stop, or the servo task stops servicing outputs, the last programmed waveform can keep running indefinitely. In the worst case that leaves motors/servos holding the last command instead of cleanly entering failsafe. This has been seen when there is a semi-brownout condition on the RX; not enough for the MCU to detect a brownout, but enough for the MCU main loop to hang, and the timer interrupts still fire.
On ESP32 devices when the device reboots the ROM, and bootloader do NOT reset the modules! This means that PWM signals are running until ExpressLRS's setup function starts and clears the pins. This is also after some initialization on our side, so could be about 1 second!
What changed
Expected result