Page 1 of 1

ESP32 S3 USB TX not working with binary data

Posted: Thu Nov 18, 2021 2:35 am
by chris_zou
Hi,
I created one sample project for ESP32 S3 hardware with the following changes:
1. enable tinyUSB stack
2. enable vendor class with only 2 endpoints for bulk transfer (one IN and one OUT, buffer size are both 64 bytes)
3. ESP32 S3 is recognized as WinUSB device by PC and a test application on PC is used to receive data from ESP32 S3
4. in the main program of ESP32 S3, it is sending 64 bytes to PC every 4ms. The 64 bytes buffer is fixed and each byte is initialized to its index (meaning byte 0 is set to 0, byte 1 is set to 1,.... and byte 63 is set to 0x3F)
5. on the PC side, it is discovered the received data is NOT correct: for every 0x0a sent, ESP32S3 USB stack will automatically insert 0x0d before sending it to PC. It seems ESP32S3 USB is set to text mode and will automatically convert 0x0a (LF) to 0x0d,0x0a (CRLF)
See the attachment for the snapshot of data.

Anyone has encountered the same issue? Is there any setting to let USB work in binary mode?

Re: USB TX not working with binary data

Posted: Thu Nov 18, 2021 2:58 am
by ESP_Sprite
Are you using printf() or something similar to send to the USB serial port? If so, then yes, that subsystem does CR->CRLF translation so data ends up looking properly on most serial terminals. You can change this in menuconfig: Component config → Newlib → Line ending for UART output, set this to 'LF'.

Re: USB TX not working with binary data

Posted: Thu Nov 18, 2021 4:36 am
by chris_zou
Hi ESP_Sprite:
I am not using printf. I am using the vendor class function "tud_vendor_write(BufferPtr, size)" to write data into FIFO which eventually will be sent to PC.

Re: ESP32 S3 USB TX not working with binary data

Posted: Fri Nov 19, 2021 1:47 am
by ESP_Sprite
In that case, there's very little on the ESP32 side that can change the data to insert those LF chars. How do you receive the data on the PC side? Are you sure that whatever terminal program you use doesn't do the conversion?

Re: ESP32 S3 USB TX not working with binary data

Posted: Fri Nov 19, 2021 4:17 am
by chris_zou
Hi ESP_Sprite,
Thank you for the update.
On the PC side, I am using the WinUsb API "WinUsb_ReadPipe(...)" to receive data.
As it is purely for data transfer between endpoints, I doubt WinUsb API will do any pre-processing on the received data.
Probably can capture USB packets to see what the raw data look like.