CDC communication speed with TWR-K21F120M is wrong

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CDC communication speed with TWR-K21F120M is wrong

Jump to solution
1,122 Views
evgenik
Contributor IV

I am working with development board TWR-K21F120M and using "SDK_2.3.1_TWR-K21F120M\boards\twrk21f120m\usb_examples\usb_device_cdc_vcom" project for me as base for FW application with CDC communication. To check the speed of the communication I wrote an application on CSharp that send to TWR board 1000 packets of 64 bytes and the board reply to the PC with 5 bytes reply. At the end of the communication, I print the test results as transferred bytes, communication time, and communication baud rate. To my surprise, I found that CDC communication doesn't work with speed as defined in FW and SW configuration. Instead baud rate 115200 I have received 36800bits/sec. I tried to check other examples from NXP but received the same result. Attached the project that I am using for serial communication test: for VS and project from MCUXpresso "SDK_2.3.1_TWR-K21F120M\boards\twrk21f120m\usb_examples\usb_device_cdc_vcom". The file virtual_com.c is a little updated for successful communication with CDC (in 2 places wheres performed updates I wrote "updated by Evgeni").

Where is a problem? In the code configuration or in the TWR-K21F120M board design? Has anyone encountered the same problem?

Thanks.

Evgeni

0 Kudos
1 Solution
1,069 Views
evgenik
Contributor IV

Hi Mark.

While I was trying to check serial port speed with an external application, I decided to check the speed of the USB port in half-duplex mode and changed the program only to send the date from the microcontroller to the PC. I saw that the transfer rate, without receiving data, is very high. After that, I changed the program so that it only works on reception. And in this case, I also saw that the data reception rate is just as high. This means that the problem of low baud rate was on the PC side. I have found the problem and fixed the program on the PC. After that, the data transfer rate from PC to MCU via USB CDC protocol reached approximately 53.514 bytes/sec. This is enough for me.

Thanks a lot for your help.

View solution in original post

0 Kudos
6 Replies
1,106 Views
mjbcswitzerland
Specialist V

Hi

The USB-CDC class allows emulation of a COM port (RS232 - UART) but if there is no CDC to UART bridge in the path the Baud rate set by the class control has no meaning since there is nothing in the communication path throttling the speed. On the K21's FS USB interface I would expect a rate of a few MBit/s although also the source/sink at the PC host can limit this to a degree if it doesn't supply or consume data faster than the USB bulk endpoint can handle it.

If your setup does has a CDC to USB bridge you need to look at the UART baud rate that is set and verify that it is correctly following the CDC class control "SET LINE CODING" 0x20 correctly. With a UART in the path the throughput will be 'naturally' throttled by its much lower speed.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT, including USB for Kinetis FS/HS and i.MX RT HS parts]

0 Kudos
1,088 Views
evgenik
Contributor IV

Hi Mark.

I checked the code and found no bridge of the connection between USB and UART. The project is attached. I also wanted to check the real USB speed from FW by USB_DeviceKhciControl(khciState, kUSBDeviceControlGetSpeed, speed), where speed is defined as an int value. But the program returns a constant USB_SPEED_FULL (and this is not the real USB speed).

Maybe you or any other can find something that I have not found in the project definitions, that will allow me to work with USB High Speed.

Thanks a lot.

0 Kudos
1,085 Views
mjbcswitzerland
Specialist V

Hi

The USB speed that you request is just returning the USB speed of the device and not the throughput. The K21F has only Full-Speed USB (12Mb/s) and not High Speed USB (480MB/s) and so can't be changed.

If you get stuck requiring a quality solution for USB on your part you can also use the open source uTasker project on GITHUB which ensures high throughput (industrially proven in many products since 2011).
At https://www.utasker.com/kinetis/TWR-K21F120M.html there is a binary that can be loaded to your board showing a 6 USB-CDC composite with high speed (non-throttled) on the first interface and real USB-CDC-UART bridges on 5 others (to physical UARTs) where the UART Baud Rates follows the setting sent by the USB host.

Regards

Mark
[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
1,070 Views
evgenik
Contributor IV

Hi Mark.

While I was trying to check serial port speed with an external application, I decided to check the speed of the USB port in half-duplex mode and changed the program only to send the date from the microcontroller to the PC. I saw that the transfer rate, without receiving data, is very high. After that, I changed the program so that it only works on reception. And in this case, I also saw that the data reception rate is just as high. This means that the problem of low baud rate was on the PC side. I have found the problem and fixed the program on the PC. After that, the data transfer rate from PC to MCU via USB CDC protocol reached approximately 53.514 bytes/sec. This is enough for me.

Thanks a lot for your help.

0 Kudos
1,064 Views
mjbcswitzerland
Specialist V

Hi

That is 5% of FS USB speed (and 0.015% of HS USB speed) so there is presumably room for improvement somewhere if ever needed.

Regards

Mark

0 Kudos
1,112 Views
myke_predko
Senior Contributor III

Hi @evgenik,

I've seen the same thing but haven't been too concerned about it because for my application the speed is acceptable.  

I would be curious to understand why this is happening and what the solution is (you never know what you need in the future).

Thanx for bringing it up,

myke

0 Kudos