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

esp32c3 redirection of uart serial to usb serial ? #2772

Closed
profjmer opened this issue May 7, 2024 · 4 comments
Closed

esp32c3 redirection of uart serial to usb serial ? #2772

profjmer opened this issue May 7, 2024 · 4 comments

Comments

@profjmer
Copy link

profjmer commented May 7, 2024

On esp32c3 super mini board, I can flash from USB, but serial.println are using uart on other pins.
If in menuconfig->component config->esp system settings->channel for console output(usb serial/JTAG controller) is chosen, then output is written to USB-CDC but chip is always resetting rapidly.
What would be the procedure to enable redirection of serial.println() to USB-CDC ?

@mikee47
Copy link
Contributor

mikee47 commented May 7, 2024

Sming doesn't use the IDF console code so alternative output mechanisms won't work.

The C3 doesn't have real USB hardware but instead provides ROM functions (esp_rom_uart_xxx()) to access USB/CDC port.

The issue with Serial specifically is that it refers to an instance of HardwareSerial which is a wrapper for the low-level uart driver: code is in Sming/Arch/Esp32/Components/driver/uart.cpp. The Esp8266 implementation supports 'virtual' ports to allow redirection inside GDB, so a similar approach could be taken here. However, serial input would need to be polled as there's no interrupt provision for the C3 that I can see.

An initial, simpler approach would be to implement a Stream class to provide access specifically for the C3.

If you only require the port for debug_x functions then provide an m_nputs implementation and pass it to m_setPuts().

The boot loop (rapid resetting) cause could be caused by a number of issues but can usually be diagnosed via bootloader messages.

@profjmer
Copy link
Author

profjmer commented May 7, 2024

thanks for info

@profjmer profjmer closed this as completed May 7, 2024
@mikee47
Copy link
Contributor

mikee47 commented Jul 3, 2024

Just looking at this issue again and I was wrong about the use of esp_rom_uart_xxx. In fact, it's got a well-defined set of low-level routines with interrupts available which can be used. I'm working up an extension to the esp32 uart driver so this can be used easily.

@mikee47
Copy link
Contributor

mikee47 commented Jul 3, 2024

The reference code is in the IDF under components/driver/usb_serial_jtag.

slaff pushed a commit that referenced this issue Jul 4, 2024
This PR adds UART driver support for esp32 variants with an integrated USB JTAG/Serial port, such as esp32c3.
Requires ESP-IDF version 5.2 or later.

Example usage::

```
#ifdef UART_ID_SERIAL_USB_JTAG
  Serial.setPort(UART_ID_SERIAL_USB_JTAG);
#endif
Serial.begin(...);
```

See issue #2772
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

No branches or pull requests

2 participants