My PWM code stopped compiling after a board package update — the setup function no longer exists
I have a simple sketch generating PWM on an ESP32 that compiled fine before. On a fresh install of the IDE and the current board package, it fails at compile time saying the LEDC setup function was not declared in this scope.
The board package is installed, other things compile, and this is example code copied from tutorials that clearly worked for other people.
So something changed rather than something being missing. What happened, and what is the right way forward — pin the old version or rewrite?
@esp_ece · 5h ago
On which way to go, and I would push towards rewriting rather than pinning.
Rewrite. The new calls are simpler, the code is shorter, and you stay on a package that receives fixes and supports newer chips. If you have a handful of PWM lines, this is fifteen minutes.
Pin the old version. In the boards manager you can select the last 2.x release, and everything compiles again immediately. This is the right answer when you are mid-project, or depend on a library that has not been updated, or are following a course written against the old API. It is a decision to stay on a version that will stop receiving support, so treat it as buying time.
Compatibility shim. Defining the old function names in terms of the new ones works and I would avoid it. It hides which API you are on, and the next person to read the code has no idea why it compiles.
Reply
Report