增加ESP32C3的虚拟串口调试功能
This commit is contained in:
parent
c09ded8f57
commit
0be9f6e079
11
main/main.c
11
main/main.c
@ -54,15 +54,14 @@ void app_main(void)
|
||||
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
|
||||
|
||||
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
Usb_Virtual_serial_port_init();
|
||||
#endif
|
||||
|
||||
Printer_group = xEventGroupCreate();
|
||||
button_init();
|
||||
register_gpio_wakeup();
|
||||
Printer_Bsp_Init();
|
||||
Printer_run_init();
|
||||
// button_init();
|
||||
// register_gpio_wakeup();
|
||||
// Printer_Bsp_Init();
|
||||
// Printer_run_init();
|
||||
// xTaskCreate(light_sleep_task, "light_sleep_task", 4096, NULL, 6, NULL);
|
||||
while (1) {
|
||||
if(xQueueReceive(User_data_queue, &Receive_All_data, portMAX_DELAY))
|
||||
|
||||
@ -4,10 +4,13 @@
|
||||
#include "freertos/task.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "include/Sys_Printer.h"
|
||||
|
||||
#include "driver/usb_serial_jtag.h"
|
||||
|
||||
static const char *TAG = "usb_cdc";
|
||||
|
||||
#define BUF_SIZE (1024)
|
||||
#define ECHO_TASK_STACK_SIZE (4096)
|
||||
|
||||
extern QueueHandle_t User_data_queue;
|
||||
user_data_t Receive_usb_data;
|
||||
|
||||
@ -46,11 +49,40 @@ void tinyusb_cdc_line_state_changed_callback(int itf, cdcacm_event_t *event)
|
||||
int rts = event->line_state_changed_data.rts;
|
||||
ESP_LOGI(TAG, "Line state changed on channel %d: DTR:%d, RTS:%d", itf, dtr, rts);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C3
|
||||
|
||||
static void USB_Serial_rx_task(void *arg)
|
||||
{
|
||||
// Configure a temporary buffer for the incoming data
|
||||
uint8_t *data = (uint8_t *) malloc(BUF_SIZE);
|
||||
if (data == NULL) {
|
||||
ESP_LOGE("usb_serial_jtag echo", "no memory for data");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
||||
int len = usb_serial_jtag_read_bytes(data, (BUF_SIZE - 1), 20 / portTICK_PERIOD_MS);
|
||||
|
||||
// Write data back to the USB SERIAL JTAG
|
||||
if (len) {
|
||||
usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
||||
data[len] = '\0';
|
||||
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void Usb_Virtual_serial_port_init(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "USB initialization");
|
||||
#if CONFIG_IDF_TARGET_ESP32S3
|
||||
const tinyusb_config_t tusb_cfg = {
|
||||
.device_descriptor = NULL,
|
||||
.string_descriptor = NULL,
|
||||
@ -76,7 +108,19 @@ void Usb_Virtual_serial_port_init(void)
|
||||
TINYUSB_CDC_ACM_0,
|
||||
CDC_EVENT_LINE_STATE_CHANGED,
|
||||
&tinyusb_cdc_line_state_changed_callback));
|
||||
#else
|
||||
|
||||
// Configure USB SERIAL JTAG
|
||||
usb_serial_jtag_driver_config_t usb_serial_jtag_config = {
|
||||
.rx_buffer_size = BUF_SIZE,
|
||||
.tx_buffer_size = BUF_SIZE,
|
||||
};
|
||||
|
||||
ESP_ERROR_CHECK(usb_serial_jtag_driver_install(&usb_serial_jtag_config));
|
||||
ESP_LOGI("usb_serial_jtag echo", "USB_SERIAL_JTAG init done");
|
||||
|
||||
xTaskCreate(USB_Serial_rx_task, "USB SERIAL JTAG_echo_task", ECHO_TASK_STACK_SIZE, NULL, 10, NULL);
|
||||
|
||||
#endif
|
||||
ESP_LOGI(TAG, "USB initialization DONE");
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user