-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
disables interrupts as a side effect
#6669
Comments
Issue confirmed with the latest Arduino Core Version 2.0.3-RC1. @P-R-O-C-H-Y, PTAL |
Hmm I think this also affects PWM. |
Hi @quentinmit
|
Hi @TD-er, If you setup some PWM peripheral like LEDC on a pin, when you call pinMode on same pin, the configuration will set the pin function to be GPIO and the signal from peripheral will be no longer connected to the pin. |
Yep, found that too, after updating to IDF4.4 |
I have read you description again and it make sense, to keep the state interrupt state so when changing pinMode, it won't be disabled. I will add this to roadmap :) |
Hi @P-R-O-C-H-Y. Your sample code is invalid because |
Hi @quentinmit |
Board
ESP32-DevKitC
Device Description
DevKitC
Hardware Configuration
For the demo code below, connect a switch or square wave to pin 19.
Version
v2.0.2
IDE Name
PlatformIO
Operating System
macOS
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
115200
Description
The
pinMode
call, in addition to changing pullups/whether a pin is driving the output or not/etc, appears to disable pin interrupts as a side effect. In the ESP-IDF version of the code,intr_type
is explicitly set toGPIO_INTR_DISABLE
. In the older register code, the field is accidentally overwritten by the write toGPIO.pin[x].val
when it's really just trying to setGPIO.pin[x].pad_driver
.This is a problem because while
pinMode
isIRAM_ATTR
and safe to call from interrupt handlers,attachInterrupt
is not (and it's also rather heavyweight), so it's not possible to re-enable the interrupt ifpinMode
is being used in an ISR.pinMode
should just preserve whatever previous state of interrupts existed; if the user has an interrupt configured on a pin and wants to change the pin mode, they probably know what they are doing. If they want to disable the interrupt they can calldetachInterrupt
directly.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: