arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.71k stars 4.72k forks source link

FIX: Allow use of UART0 with enabled USB_CDC_CONSOLE #21496

Closed rPraml closed 1 week ago

rPraml commented 1 month ago

Description:

When tasmota is compiled with USE_USB_CDC_CONSOLE, the ´ClaimSerial` method will return immediately and will not release UART0

This makes sense, as long as USB is used for console, but if we fall back to serial, because no USB is connected, we must release the console, so that all 3 UARTs on the ESP32 can be used. (Possible broken since https://github.com/rPraml/Tasmota/commit/84ced0fcab6f3af26602cd8fc23df5ba7bcc8c1f)

In my case I tried to connect 3 SML meters to a ESP32 and I always had some garbage in the web console, when all 3 UARTs were used, as the serial data was read by the SML driver and the SerialConsole.

Related issue (if applicable): fixes #20324

Checklist:

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

Jason2866 commented 1 month ago

With reducing the build variants (no different builds for CDC and UART) this is a side effect of auto detecting how the MCU is connected to the PC. Since no SOF packets are detected on the HWCDC port the serial console is routed to an UART port. Yes that means only 2 UARTS are useable when the HWCDC port is not connected to a PC. By design. Not a bug.

barbudor commented 1 month ago

Which I see as a problem

If I choose a CPU/Board where the USB/CDC is available for debug in order to dedicate every UART for external peripherals, what can I do to insure I will always have every UART available for those peripherals when USB is not plugged ?

I understand the need for a fallback mode in standard builds but how can I prevent that auto mode when I don't want it ?

Jason2866 commented 1 month ago

Disable Tasmota console could be a way.

barbudor commented 1 month ago

It would require a different build to debug (one with console) and run (without console) Having a #define which allows to disable the fallback (enforce CDC) and free all UART would be great

rPraml commented 1 month ago

Disable Tasmota console could be a way.

How? I searched the docs and found only SerialLog 0 which woud disable the output. What I need is, that the serial input is not processed here https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota.ino#L812 and this can be done by setting TasmotaGlobal.serial_local = true which is done only in ClaimSerial.

To summarize:

I would expect, that the serial console is deactivated automatically, if I explicitly use the third uart by any driver... nevertheless if compiled with CDC console (and fallback) or not. So I'm unsure if this is

By design. Not a bug.

In this case, I would really appreciate a warning being printed here: Not claiming UART0 when CDC console is enabled This would have saved me a lot of time ;)

Thanks, Roland

github-actions[bot] commented 2 weeks ago

This PR has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.