Page 1 of 1
ESP32-C3 CDC-ACM must printf "\n" after putchar
Posted: Fri Mar 04, 2022 3:30 am
by Archi.Xie
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!
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
Posted: Fri Mar 04, 2022 4:43 am
by ESP_Sprite
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
Posted: Fri Mar 04, 2022 5:48 am
by Archi.Xie
ESP_Sprite wrote: ↑Fri Mar 04, 2022 4:43 am
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?
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()".
Best regards!
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
Posted: Fri Mar 04, 2022 6:43 am
by Archi.Xie
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);
}
}
Re: ESP32-C3 CDC-ACM must printf "\n" after putchar
Posted: Wed Jan 18, 2023 4:57 pm
by 1321457900
你可以使用
Code: Select all
printf("%s\033[s\033[1A\n\033[u", data);
来在打印换行符之后再回到上一行