Description
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.
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.
Arduino
arduino-esp32/cores/esp32/esp32-hal-gpio.c
Lines 92 to 133 in 178aee8
Sketch
This is the sketch I ran using 2.0.2 and 2.0.3. pinMode was the only one with different timing
#include <Arduino.h>
void test()
{
auto d1 = micros();
pinMode(A0, OUTPUT);
auto d2 = micros();
digitalWrite(A0, LOW);
auto d3 = micros();
pinMode(A0, INPUT_PULLUP);
auto d4 = micros();
digitalRead(A0);
auto d5 = micros();
Serial.println(d2 - d1);
Serial.println(d3 - d2);
Serial.println(d4 - d3);
Serial.println(d5 - d4);
Serial.println();
}
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println("Hello");
test();
test();
test();
test();
}
void loop()
{
// put your main code here, to run repeatedly:
}
Debug Message
not applicable
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
Labels
Type
Projects
Status