ESP32 S3 USB TX not working with binary data

chris_zou
Posts: 7
Joined: Tue Nov 02, 2021 1:59 am

ESP32 S3 USB TX not working with binary data

Postby chris_zou » Thu Nov 18, 2021 2:35 am

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?
Attachments
ESP32S3_TX_Insert_0x0D_for_0x0A.JPG
ESP32 S3 USB converts 0x0a(LF) to 0x0d0a(CRLF) for TX data automatically
ESP32S3_TX_Insert_0x0D_for_0x0A.JPG (63.81 KiB) Viewed 4284 times
Last edited by chris_zou on Thu Nov 18, 2021 5:58 am, edited 1 time in total.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: USB TX not working with binary data

Postby ESP_Sprite » Thu Nov 18, 2021 2:58 am

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'.

chris_zou
Posts: 7
Joined: Tue Nov 02, 2021 1:59 am

Re: USB TX not working with binary data

Postby chris_zou » Thu Nov 18, 2021 4:36 am

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.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32 S3 USB TX not working with binary data

Postby ESP_Sprite » Fri Nov 19, 2021 1:47 am

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?

chris_zou
Posts: 7
Joined: Tue Nov 02, 2021 1:59 am

Re: ESP32 S3 USB TX not working with binary data

Postby chris_zou » Fri Nov 19, 2021 4:17 am

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.

Who is online

Users browsing this forum: No registered users and 176 guests