Keep the Elecrow's touch bus free of the USB PHY after Wi-Fi starts (0.2.94, firmware 0.2.80)
The GT911 of the CrowPanel 7.0" sits on GPIO 19 and 20, the ESP32-S3's USB pins. Firmware 0.2.79 freed them once, in a static constructor; the Wi-Fi PHY library then kept the USB PHY on (CONFIG_ESP_PHY_ENABLE_USB, on by default on an ESP32-S3) and the touch went quiet once Wi-Fi came up. The board file turns that option off, frees the pins again in BOOT_TOUCH after Wi-Fi started, and a one-second watchdog frees them whenever anything takes them, with a log line.
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
#pragma once
|
||||
// The Elecrow CrowPanel 7.0" wires its GT911 touch I2C to GPIO19 and GPIO20, the ESP32-S3's USB D- and D+. The ROM
|
||||
// leaves the USB_SERIAL_JTAG PHY on those pads, and ESP-IDF's I2C driver cannot take them back: the bus reads as
|
||||
// "I2C software timeout" and the touch never answers (esphome/esphome#15356, ESPHome 2026.3+). This runs before any
|
||||
// ESPHome component (a static constructor at priority 101): the PHY lets the pads go, and both become plain GPIOs
|
||||
// with their pull-ups, as the I2C driver expects to find them. The board's USB-C port is a CH340 on UART0, so nothing
|
||||
// is lost.
|
||||
// "I2C software timeout" and the touch never answers (esphome/esphome#15356, ESPHome 2026.3+). release_usb_pads() lets
|
||||
// the pads go: the PHY drops them, and both become plain GPIOs with their pull-ups, as the I2C driver expects to find
|
||||
// them. The board's USB-C port is a CH340 on UART0, so nothing is lost.
|
||||
//
|
||||
// It runs three times, because three things hand the pads back to the PHY: once before any ESPHome component (a
|
||||
// static constructor at priority 101, after the ROM), once in the board's BOOT_TOUCH hook (the core's on_boot at
|
||||
// priority -100, after Wi-Fi started: the Wi-Fi PHY library keeps the USB PHY unless CONFIG_ESP_PHY_ENABLE_USB is
|
||||
// off, which the board file sets as well), and from a one-second interval that reads the pad bit and releases the pads
|
||||
// again when anything took them (ESPHome's logger keeps the USB-Serial-JTAG secondary console, and a Wi-Fi restart
|
||||
// re-enables the PHY). The interval logs once per event, so the log says whether it ever had to.
|
||||
//
|
||||
// ESPHome includes every header of the component in every build, so the code is behind a flag only the Elecrow's board
|
||||
// file sets (`-DESP_SCREENS_FREE_USB_PADS=1`, packages/boards/elecrow-crowpanel7.yaml): the CYD has no such peripheral,
|
||||
@@ -15,7 +21,10 @@
|
||||
#include "soc/usb_serial_jtag_reg.h"
|
||||
|
||||
namespace elecrow {
|
||||
static __attribute__((constructor(101))) void release_usb_pads() {
|
||||
// True while the USB PHY holds GPIO19 and GPIO20.
|
||||
inline bool usb_pads_taken() { return REG_GET_BIT(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE) != 0; }
|
||||
|
||||
inline void release_usb_pads() {
|
||||
usb_serial_jtag_ll_phy_enable_pad(false);
|
||||
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_USB_PAD_ENABLE);
|
||||
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
|
||||
@@ -26,5 +35,7 @@ static __attribute__((constructor(101))) void release_usb_pads() {
|
||||
REG_CLR_BIT(reg, FUN_PD);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((constructor(101))) void release_usb_pads_early() { release_usb_pads(); }
|
||||
} // namespace elecrow
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user