[lightning-ln882h] Change default log output port to UART1#373
[lightning-ln882h] Change default log output port to UART1#373Bl00d-B0b wants to merge 1 commit intolibretiny-eu:masterfrom
Conversation
…ibretiny-eu#373) When LT_UART_SILENT_ALL=1 (set by ESPHome's sdk_silent: all, which is the default), all SDK UART output is suppressed via printf_config.h so the SDK logger serial is never written to. Skipping serial_init() in this case prevents the default UART port from claiming its TX/RX pins via AFIO, allowing them to be used as GPIO. On BK72XX this is not an issue because UART0 is pre-initialized by the Beken bootloader. On LN882H, UART0 is initialized explicitly by lt_init_log(), unconditionally claiming PA2/PA3 even when logger: baud_rate: 0 is set in ESPHome. When serial output is actually needed, ESPHome's logger component or an explicit Serial.begin() call will initialize the hardware.
fc3046c to
8414c94
Compare
|
The A better solution would be to use the There is however another component that uses UART internally in LT - Auto-download-reboot. When it's enabled (the default option), it listens for flashing commands on the default flashing port (depends on the chip). To do that, it needs to initialize the UART. The Note that, on most off-the-shelf devices, the UART used for log output is usually not connected to any other peripherals. Because of this I don't really see the purpose of using these pins for anything else, unless you're using some kind of development board, or have unsoldered the module and use it as a bare module. |
|
Thanks for the detailed explanation, that makes sense. Real-world context: Just to address the skepticism — this is not a dev board or bare module. The device is a DS-101JL dual-gang wall switch. The MCU module is an LN-CB3S V1.0 — a pin-compatible drop-in replacement for the Tuya CB3S (Beken BK7231N) module, but carrying a WL2H-U-2 chip (Tuya's Lightning Semi LN882H variant) instead. Because it reuses the CB3S footprint on a mass-produced PCB, PA2 is physically connected to the right indicator LED on the switch. Reworked: I've updated the PR to use the correct fix — changing |
No, it doesn't.
It doesn't either. This is a separate option, controlled by ESPHome's
Disabling the UART initialization on Your device's LED is connected to GPIOA2, which is also the UART0 TX pin. On the LN-CB3S module, it's available on pad 16 - which corresponds to all other CB3S-like modules (or even ESP12F modules). On all prior Beken-based boards this port was NOT used for the logging output. Per Tuya documentation on WL2H-U, this also applies to LN882x modules - the correct logging output port is UART1, not UART0. Your device was designed with this in mind - the original firmware was most definitely using UART1, so the UART0 port was free to use as the LED indicator. The real solution would probably be to change the default logging port of LibreTiny to UART1 - we usually try to stick to the manufacturer-defined UART usage conventions. The LN882H support was added in PR #312, and apparently it was just implemented incorrectly for this whole time. |
Per Tuya WL2H-U datasheet, UART1 (PB8/PB9) is the designated log output port on LN882H modules. UART0 (PA2/PA3) is the user UART and is typically connected to GPIOs on CB3S-footprint boards (e.g. indicator LEDs on the DS-101JL wall switch). Using UART0 as the default log port was introduced in libretiny-eu#312 and caused PA2/PA3 to be claimed by AFIO, preventing their use as GPIO. Change lt_family.h to prefer UART1 over UART0 as the default, consistent with how beken-72xx defaults to UART2/UART1 and avoids UART0.
2342bb2 to
0e9b9b5
Compare
Per Tuya WL2H-U datasheet, UART1 (PB8/PB9) is the designated log output port on LN882H modules. UART0 (PA2/PA3) is the user UART and is typically connected to GPIOs on CB3S-footprint boards (e.g. indicator LEDs on the DS-101JL wall switch). Using UART0 as the default log port was introduced in libretiny-eu#312 and caused PA2/PA3 to be claimed by AFIO, preventing their use as GPIO. Change lt_family.h to prefer UART1 over UART0 as the default, consistent with how beken-72xx defaults to UART2/UART1 and avoids UART0.
|
Thanks for digging into the root cause — you're right, the correct fix is much simpler. I've reworked the PR: |

Problem
On LN882H,
lt_init_log()unconditionally callsserial_init()during startup, which triggersuart_io_pin_request()→ sets the AFIO pin mux for the default UART port's TX/RX pins. This permanently claims those pins (e.g. PA2/PA3 for UART0) even whenlogger: baud_rate: 0is set in ESPHome, preventing them from being used as GPIO.On BK72XX this is not an issue because UART0 is pre-initialized by the Beken bootloader — LibreTiny never claims it explicitly.
Root cause
Fix
When
LT_UART_SILENT_ALL=1(set by ESPHome'ssdk_silent: all, which is the default), all SDK UART output is already suppressed viaprintf_config.h— the logger serial is never written to. Skippingserial_init()in this case is safe and frees the UART pins for GPIO use.When serial output is actually needed, ESPHome's logger component or an explicit
Serial.begin()call initializes the hardware instead.Effect
With this fix, setting
logger: baud_rate: 0in ESPHome (combined with the defaultsdk_silent: all) frees the default UART TX/RX pins for GPIO use on LN882H — consistent with BK72XX behaviour.Without the fix, users must work around this by setting
LT_UART_DEFAULT_PORT: 1in their ESPHome config to redirect the logger to a different UART port.