Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Allow use of UART0 with enabled USB_CDC_CONSOLE #21496

Merged
merged 1 commit into from
Jun 22, 2024

Conversation

rPraml
Copy link
Contributor

@rPraml rPraml commented May 25, 2024

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 rPraml@84ced0f)

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:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • 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
  • The code change is tested and works with Tasmota core ESP32 V.3.0.0
  • I accept the CLA.

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

@Jason2866
Copy link
Collaborator

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
Copy link
Contributor

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
Copy link
Collaborator

Disable Tasmota console could be a way.

@barbudor
Copy link
Contributor

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
Copy link
Contributor Author

rPraml commented May 26, 2024

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 (d5a4f84) 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

Copy link

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 github-actions bot added the stale Action - Issue left behind - Used by the BOT to call for attention label Jun 20, 2024
@arendst arendst self-assigned this Jun 21, 2024
@arendst arendst removed the stale Action - Issue left behind - Used by the BOT to call for attention label Jun 21, 2024
@arendst arendst merged commit f3dcbdc into arendst:development Jun 22, 2024
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems using all 3 UART on ESP32 (tasmota drivers and berry)
4 participants