Hello,
My project is using ESP32-C3, I'm working on USB CDC-ACM,My program wish use CDC-ACM to putchar and getchar,but not want putchar's next must follow printf("\n") to trigger output, How can I solve this?Thanks!
1. idf.py menuconfig -> Component config -> ESP System Setting -> Channel for console output -> USB Serial/JTAG Controlller
2. On Standard Unix Enviroment:
a. fflush(stdout)
b. setvbuf(stdout,NULL,_IONBF,0)
But ESP32C3 USB CDC-ACM seems to be hardware implementation, a/b methods could not work, Sincerely looking forward to answer。
Best Regards!
ESP32-C3 CDC-ACM must printf "\n" after putchar
-
- Posts: 9764
- Joined: Thu Nov 26, 2015 4:08 am
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
That is odd... there indeed is a flush system in the usb-jtag-serial hardware that needs to be triggered, but from what I can tell that should be hooked up to the fflush() call. Can you try manually calling usb_serial_jtag_ll_txfifo_flush(), see if that fixes it?
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
Ok,Thanks for reply, but which header file should be contained for using "usb_serial_jtag_ll_txfifo_flush()"? I searched whole file under esp-idf-v4.4 but don't find "usb_serial_jtag_ll_txfifo_flush()".ESP_Sprite wrote: ↑Fri Mar 04, 2022 4:43 amThat is odd... there indeed is a flush system in the usb-jtag-serial hardware that needs to be triggered, but from what I can tell that should be hooked up to the fflush() call. Can you try manually calling usb_serial_jtag_ll_txfifo_flush(), see if that fixes it?
Best regards!
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
I solve this issue by manual set register USB_SERIAL_JTAG_EP1_CONF_REG's USB_SERIAL_JTAG_WR_DONE bit, here is the source code and test picture, hope could help more people!
static void usb_cdc_transfer_task(void *arg)
{
while(1)
{
int USB_CDC_Recv_Byte = -1;
uint32_t EP1_Conf_Reg = 0x00;
uint32_t Send_Byte_Cnt = 0x00;
while((USB_CDC_Recv_Byte = getc(stdin)) != EOF)
{
putc((char)USB_CDC_Recv_Byte, stdout);
Send_Byte_Cnt++;
}
/* Replace (fflush(stdout) or printf("\n"))'s function!!! */
if(Send_Byte_Cnt > 0)
{
/* Read USB_SERIAL_JTAG_EP1_CONF_REG (BaseAddr: 0x60043000 Offset: 0x0004) */
EP1_Conf_Reg = *((uint32_t*)(0x60043004));
/* Set 'USB_SERIAL_JTAG_WR_DONE' bit*/
EP1_Conf_Reg |= 0x01;
/* Write USB_SERIAL_JTAG_EP1_CONF_REG Back */
*((uint32_t*)(0x60043004)) = EP1_Conf_Reg;
Send_Byte_Cnt = 0;
}
vTaskDelay(1);
}
}
static void usb_cdc_transfer_task(void *arg)
{
while(1)
{
int USB_CDC_Recv_Byte = -1;
uint32_t EP1_Conf_Reg = 0x00;
uint32_t Send_Byte_Cnt = 0x00;
while((USB_CDC_Recv_Byte = getc(stdin)) != EOF)
{
putc((char)USB_CDC_Recv_Byte, stdout);
Send_Byte_Cnt++;
}
/* Replace (fflush(stdout) or printf("\n"))'s function!!! */
if(Send_Byte_Cnt > 0)
{
/* Read USB_SERIAL_JTAG_EP1_CONF_REG (BaseAddr: 0x60043000 Offset: 0x0004) */
EP1_Conf_Reg = *((uint32_t*)(0x60043004));
/* Set 'USB_SERIAL_JTAG_WR_DONE' bit*/
EP1_Conf_Reg |= 0x01;
/* Write USB_SERIAL_JTAG_EP1_CONF_REG Back */
*((uint32_t*)(0x60043004)) = EP1_Conf_Reg;
Send_Byte_Cnt = 0;
}
vTaskDelay(1);
}
}
- Attachments
-
- ESP32-C3使用USB CDC-ACM实现接收和发送.png (112.79 KiB) Viewed 2937 times
-
- Posts: 1
- Joined: Wed Jan 18, 2023 4:54 pm
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
你可以使用来在打印换行符之后再回到上一行
Code: Select all
printf("%s\033[s\033[1A\n\033[u", data);
Who is online
Users browsing this forum: Baidu [Spider], Gaston1980, Google [Bot] and 135 guests