With the ESP32-Arduino, I learned that we can exchange data with USB-CDC just as we do with a physical UART port,
using the same functions as with a physical UART port, such as Serial.print() and Serial.read().
I also learned that ESP-IDF allows interactive data exchange between the PC and ESP32-C3 using the esp_console component.
However, in order to exchange data in a free format, for example without line feed codes,
I would like to communicate with ESP32-C3+ESP-IDF using USB-CDC in the same way as with a regular UART.
Is there any easy way to Tx/Rx data via USB-CDC using ESP32-C3 + ESP-IDF?
Can the ESP32-C3's USB-CDC port be used like a UART?
-
- Posts: 3
- Joined: Thu Jan 19, 2023 12:52 pm
Re: Can the ESP32-C3's USB-CDC port be used like a UART?
I found it on the website https://blog.csdn.net/ai_ljh/article/details/126999395
It works.
It works.
- #include <stdio.h>
- #include "sdkconfig.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "esp_system.h"
- #include "esp_spi_flash.h"
- #include "string.h"
- #include "hal/usb_serial_jtag_ll.h"
- void mytask1(void *pvParameter)
- {
- uint8_t *rxbuf;
- int cnt;
- rxbuf = (uint8_t *)malloc(64);
- int rxcnt;
- while (1)
- {
- if (usb_serial_jtag_ll_rxfifo_data_available())
- {
- rxcnt = usb_serial_jtag_ll_read_rxfifo(rxbuf,64);
- cnt = (int)usb_serial_jtag_ll_write_txfifo((const uint8_t *)rxbuf, rxcnt);
- usb_serial_jtag_ll_txfifo_flush();
- //printf("Send %d characters to host \n", cnt);
- }
- vTaskDelay(pdMS_TO_TICKS(10));
- }
- free(rxbuf);
- vTaskDelete(NULL);
- }
- void app_main(void)
- {
- xTaskCreate(mytask1, "mytask1", 1024 * 5, NULL, 1, NULL);
- }
Re: Can the ESP32-C3's USB-CDC port be used like a UART?
Hi,
the datasheet say:
so, try to clear USB_SERIAL_JTAG_DP_PULLUP bit and then just use standard uart functions (uart_param_config, uart_set_pin, uart_driver_install, uart_write_bytes, uart_read_bytes, etc)
the datasheet say:
Code: Select all
USB - GPIO18 and GPIO19 are USB pins. The pull-up value of a USB pin is controlled by the pin’s pull-up
value together with USB pull-up value. If any of the two pull-up values is 1, the pin’s pull-up resistor will be
enabled. The pull-up resistors of USB pins are controlled by USB_SERIAL_JTAG_DP_PULLUP bit.
Code: Select all
CLEAR_PERI_REG_MASK(USB_SERIAL_JTAG_CONF0_REG, USB_SERIAL_JTAG_DP_PULLUP);
Who is online
Users browsing this forum: Baidu [Spider] and 292 guests