Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
#endif
#ifdef ARDUINO_ARCH_ESP32
#include "driver/gpio.h"
#endif

extern "C" void usePWMFixedNMI();

Expand Down Expand Up @@ -368,13 +371,16 @@ void WLED::setup()
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detection
#endif

#ifdef ARDUINO_ARCH_ESP32
pinMode(hardwareRX, INPUT_PULLDOWN); delay(1); // suppress noise in case RX pin is floating (at low noise energy) - see issue #3128
#endif
#ifdef WLED_BOOTUPDELAY
delay(WLED_BOOTUPDELAY); // delay to let voltage stabilize, helps with boot issues on some setups
#endif
Serial.begin(115200);
#ifdef ARDUINO_ARCH_ESP32
// Pull down RX pin to suppress noise when floating, without breaking UART0 IOMUX mapping.
// pinMode() routes GPIO through the GPIO matrix and detaches UART0 RX - use gpio_pulldown_en() instead.
// See issue #3128.
gpio_pulldown_en((gpio_num_t)hardwareRX);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all that is needed is to replace pinMode(hardwareRX, INPUT_PULLDOWN); with this line, nothing else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DedeHai originally the pinMode() call was located before Serial.Begin(), to avoid side-effects when Serial initializes its pins. 🤔 Do you think gpio_pulldown_en() should happen before Serial.Begin(), or keep it after? I don't have much experience with the under-the-hood pin config tools in esp-idf.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should stay where it was, the API calls are very low level and will directly write the GPIO registers, enabling the pulldown with no fuss.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm the fix working, all that is needed is this:
replace
pinMode(hardwareRX, INPUT_PULLDOWN);
with
gpio_pulldown_en((gpio_num_t)hardwareRX);
and maybe add a comment that pinMode() sets the gpio mux and breaks UART.

no additional includes, nothing.

#endif
Comment thread
softhack007 marked this conversation as resolved.
#if !ARDUINO_USB_CDC_ON_BOOT
Serial.setTimeout(50); // this causes troubles on new MCUs that have a "virtual" USB Serial (HWCDC)
#else
Expand Down
Loading