New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pinMode is much slower in 2.0.3 (and 2.0.4) #7049
Comments
Speed improvement is always nice to have. Dropping the manipulating of registers and using IDF is imho a good decision. Otoh there is a bit more overhead for some functions, which can decrease speed. The better solution imho is to adopt the code (to the new general conditions) to be (more) timing tolerant, as to hope that a speed increase will happen |
Ah this is a plausible explanation why the Dallas plugin and several others like DHTxx no longer seem to work on ESP32 in ESPEasy. |
That looks like an easy approach to speed up switching the mode by simply keeping track of the register and bitmask for a given pin. I will at least implement this for my One Wire implementation and probably also for other timing critical plugins like those DHTxx units. |
Apparently the `pinMode` call on ESP SDK 2.0.3 and 2.0.4 now takes 16 usec to complete, compared to 4 msec before. The [OneWire library maintained by PaulStoffregen](https://github.com/PaulStoffregen/OneWire/blob/master/OneWire.cpp) does perform direct GPIO handling on the registers instead of searching for the pins. This is apparently working as reported [here by @Jason2866](espressif/arduino-esp32#7049 (comment)) So I replaced all time critical calls for the Dallas plugins with the macros from Paul's library.
@TD-er, GPIO has been changed to use the IDF API, rather than directly writing to registers in order to have support for new chips. I'm closing this and adding label "won't fix", as there is nothing to do about this issue. |
Not 100% sure it is something that can't be done. Also I have no idea how good or bad "my" implementation is and what side-effects this may have on the IDF implementation of GPIO-handling. TL;DR I don't think just dismissing it "as is -> won't fix" is the best solution here. |
Board
All boards
Device Description
Tested with featheresp32
Hardware Configuration
DS18B20 connected to A0
Version
v2.0.3
IDE Name
not applicable
Operating System
not applicable
Flash frequency
not applicable
PSRAM enabled
no
Upload speed
not applicable
Description
In version 2.0.3 the GPIO handing was rewritten using IDF instead of the old implementation.
This caused the time pinMode takes to finish from ~4us to ~16us.
In ESPHome the one wire implementation uses the normal Arduino calls to manipulate GPIO, and this change is probably the cause of One Wire not working in ESPHome when using Arduino 2.0.3.
esphome/issues#3401
Is it possible to speed up pinMode?
After studying the ESPHome and Arduino code, I see that when ESPHome is compiled using ESP-IDF, it uses a different approach than Arduino for setting pin mode.
ESPHome https://github.com/esphome/esphome/blob/ed26c57d990c77cf9eed9bd54da2681f8f7881c9/esphome/components/esp32/gpio_idf.cpp#L83-L106
Arduino
arduino-esp32/cores/esp32/esp32-hal-gpio.c
Lines 92 to 133 in 178aee8
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: