Tasmota icon indicating copy to clipboard operation
Tasmota copied to clipboard

FIX: Allow use of UART0 with enabled USB_CDC_CONSOLE

Open rPraml opened this issue 1 year ago • 5 comments

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:

  • [x] The pull request is done against the latest development branch
  • [x] Only relevant files were touched
  • [x] Only one feature/fix was added per PR and the code change compiles without warnings
  • [ ] The code change is tested and works with Tasmota core ESP8266 V.2.7.6
  • [x] The code change is tested and works with Tasmota core ESP32 V.3.0.0
  • [x] I accept the CLA.

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

rPraml avatar May 25 '24 19:05 rPraml

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.

Jason2866 avatar May 26 '24 15:05 Jason2866

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 ?

barbudor avatar May 26 '24 16:05 barbudor

Disable Tasmota console could be a way.

Jason2866 avatar May 26 '24 17:05 Jason2866

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

barbudor avatar May 26 '24 18:05 barbudor

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:

  • When Tasmota is compiled with USE_USB_CDC_CONSOLE - It seems, that I can use all 3 UARTs, if there is an USB-connection detected on boot.
  • If I move the device to production (which means, that USB is disconnected in most cases...), the serial communication gets unstable (in my case, some bytes were consumed by the SML driver, some by the console)
  • If I compile without USE_USB_CDC_CONSOLE. the ClaimSerial() works as expected (it disables the serial console, when a driver uses the last UART. There was a commit (https://github.com/arendst/Tasmota/commit/d5a4f8441bfc0b98d6b482b684cc542d5ed4969b) that added this functionality to all drivers that were using uarts.

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

rPraml avatar May 26 '24 19:05 rPraml

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.

github-actions[bot] avatar Jun 20 '24 19:06 github-actions[bot]