Author Topic: CH340 USB-UART Speed tests ?  (Read 1745 times)

0 Members and 1 Guest are viewing this topic.

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
CH340 USB-UART Speed tests ?
« on: July 03, 2019, 10:57:40 pm »
I'm curious if anyone has done speed tests on CH340 ?
Search finds a few threads here using CH340, but none mention actual throughput measurements / scope shots etc
Data mentions 460800、921600、1500000、2000000 baud speeds, but what continual Send and Receive speeds can the CH340 sustain ?
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #1 on: July 03, 2019, 11:01:04 pm »
I routinely use them at 1.0 and 1.5 Mbps for 'printf debugging'. No problems with that application. I haven't tried to determine max throughput or possible data loss at high bps.
 

Offline GromBeestje

  • Regular Contributor
  • *
  • Posts: 110
  • Country: nl
Re: CH340 USB-UART Speed tests ?
« Reply #2 on: July 04, 2019, 04:54:42 pm »
I haven't actually tested this, but I have reasons to believe the CH340 can communicate at arbitrary speeds. The reason why I believe this to be true it is possible to the a CH340 to connect to an AVR microcontroller over debugWire. This doesn't show it can run fast, but it shows it can run at non-standard speeds.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 1818
  • Country: ca
Re: CH340 USB-UART Speed tests ?
« Reply #3 on: July 04, 2019, 09:39:25 pm »
First two screenshots are output of the adapter. Third screenshot is on the CH340 pins. So there must be some series resistors on this random TTL adapter, slowing the rise time significantly.
Won't let me go anywhere between 2 and 2.5, drops to the lower speed.

I had to set the scope to 2.75 to get it to decode properly, but it is able to read back its own data OK at any rate.

« Last Edit: July 04, 2019, 09:58:32 pm by thm_w »
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #4 on: July 04, 2019, 09:51:26 pm »
Most USB to UART converters can work at bit rates of 3,000,000 / N where N is an integer. Some have limited support for other bit rates using a fractional divider.
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #5 on: July 04, 2019, 10:26:11 pm »
Most USB to UART converters can work at bit rates of 3,000,000 / N where N is an integer. Some have limited support for other bit rates using a fractional divider.

That virtual baud starting clock varies.
eg FT2232H/FT232H/CP2102N have a virtual baud value of 24MHz, so those can give 24M/N, with some caveats on lowest values of N.
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #6 on: July 04, 2019, 10:40:13 pm »
That is because they are using a fractional divider. The 3M / N rule usually avoids having to use the fractional divider, so you get no additional jitter.
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #7 on: July 04, 2019, 10:43:41 pm »
First two screenshots are output of the adapter. Third screenshot is on the CH340 pins. So there must be some series resistors on this random TTL adapter, slowing the rise time significantly.
Won't let me go anywhere between 2 and 2.5, drops to the lower speed.

Thanks, nice plots.
What baud settings were those generated at ? eg 1500000,8,n,1 ?
observations :
Even 1.5Mbd seem to have extra stop bits, and a lot more stop bits insert at the higher speeds. The higher speeds do not seem to match the data specs ?


Do you have shots of bursts ? 64 bytes, often gaps can appear in larger data streams.
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #8 on: July 04, 2019, 10:46:01 pm »
That is because they are using a fractional divider. The 3M / N rule usually avoids having to use the fractional divider, so you get no additional jitter.

Err, no....  There is no jitter on a FT232H, even at 12Mbd.
Likewise, CP2102N starts from 48MHz sysCLK, and divides by 2, then divides by N, no fractional jitter.  EXAR parts are the only ones I've tested that have fractional-baud-jitter.
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #9 on: July 04, 2019, 10:51:44 pm »
Then they are not using typical 16x sampling at those bit rates. That can create similar problems as clock jitter.
 

Offline thm_w

  • Super Contributor
  • ***
  • Posts: 1818
  • Country: ca
Re: CH340 USB-UART Speed tests ?
« Reply #10 on: July 04, 2019, 11:21:09 pm »
Thanks, nice plots.
What baud settings were those generated at ? eg 1500000,8,n,1 ?
observations :
Even 1.5Mbd seem to have extra stop bits, and a lot more stop bits insert at the higher speeds. The higher speeds do not seem to match the data specs ?

Do you have shots of bursts ? 64 bytes, often gaps can appear in larger data streams.

Yeah 1500000,8,n,1.

The stop bit time at 2M is 2us so 4 bit times. Not sure why its so long like that. Tried a few different programs and seems to have the same result.
Sending 100 bytes I don't see any gaps.

At 2.5Mbps its actually running at 3Mbps (330ns bit time), thats why the numbers were off. So 3 is the highest available.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 1664
  • Country: dk
Re: CH340 USB-UART Speed tests ?
« Reply #11 on: July 04, 2019, 11:31:37 pm »
First two screenshots are output of the adapter. Third screenshot is on the CH340 pins. So there must be some series resistors on this random TTL adapter, slowing the rise time significantly.
Won't let me go anywhere between 2 and 2.5, drops to the lower speed.

Thanks, nice plots.
What baud settings were those generated at ? eg 1500000,8,n,1 ?
observations :
Even 1.5Mbd seem to have extra stop bits, and a lot more stop bits insert at the higher speeds. The higher speeds do not seem to match the data specs ?

stop bits and idle is the same, so it just not filling the transmitter as fast as it possible

 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #12 on: July 04, 2019, 11:52:57 pm »
Thanks, nice plots.
What baud settings were those generated at ? eg 1500000,8,n,1 ?
observations :
Even 1.5Mbd seem to have extra stop bits, and a lot more stop bits insert at the higher speeds. The higher speeds do not seem to match the data specs ?

Do you have shots of bursts ? 64 bytes, often gaps can appear in larger data streams.

Yeah 1500000,8,n,1.

At 2.5Mbps its actually running at 3Mbps (330ns bit time), thats why the numbers were off. So 3 is the highest available.
Ahh, thanks, 3MBd makes more sense from 48MHz USB clocks, than 2.82MBd :)

The stop bit time at 2M is 2us so 4 bit times. Not sure why its so long like that. Tried a few different programs and seems to have the same result.
Sending 100 bytes I don't see any gaps.
Stretched stop bits are common, when the core MCU cannot deliver the bytes fast enough, but it is less common to struggle at the byte rate, and not show any gaps at USB packet boundaries.

Even 1.5Mbd is adding extra stop bits (looks like 2 more?) , maybe the sub 1MBd can run with fewer added stop bits ?
Their claimed 921600 is harder to extract from 48MHz if we assume /16 of their MCUs, seems to imply 48M/4/13, or
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #13 on: July 05, 2019, 12:57:50 am »
My bit rates notes from evaluation of the CH340C. A few notable exceptions to the 3M/N rule are 2.0M, 1.2M and 923k (~115.2 *8). You have to ask for exactly 921,600 to get closest to it.

Code: [Select]
CH340C

Requested bps  Actual bps
---------------------------------
6,000,000      Error opening port
4,000,000      Error opening port
3,000,000      3,000,000
2,400,000      2,000,000
2,000,000      2,000,000
1,714,286      1,500,000
1,500,000      1,500,000
1,333,333      1,200,000
1,200,000      1,200,000
1,090,090      1,000,000
1,000,000      1,000,000
  923,077        860,000
  921,601        860,000
  921,600        923,077
  921,599        860,000
  857,143        860,000
  800,000        750,000
  750,000        750,000
  705,882        666,667
  666,667        666,667
  631,579        600,000
  600,000        600,000
  571,429        545,455
  545,455        545,455
  521,739        500,000
  500,000        500,000
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #14 on: July 05, 2019, 01:34:20 am »
My bit rates notes from evaluation of the CH340C. A few notable exceptions to the 3M/N rule are 2.0M, 1.2M and 923k (~115.2 *8). You have to ask for exactly 921,600 to get closest to it.


Thanks, interesting the 921,600 is such a special case test, they test for == and then do something different.
( Bemusing if you asked for 923,077, it bumps to 857143, but if you ask for 921,600, you get 923,077 ! :)  )

The formula here is (loosely based on their MCUs ) SysCLK of 96MHz and /16 from there - or a 6MHz virtual baud clock value (except for 921,600, when that is 12MHz)
Code: [Select]
N=0;;N=N+1;96M/16/N  (or 48M/8/N)
6000000
3000000
2000000
1500000
1200000
1000000
857142.857
750000
666666.666
600000
545454.545
500000
Special case : 96M/8/13 or 48M/4/13 = 923076.92 looks like their MCUs may have a not documented /8 or /4 choice.
« Last Edit: July 05, 2019, 01:37:33 am by PCB.Wiz »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 3125
  • Country: us
Re: CH340 USB-UART Speed tests ?
« Reply #15 on: July 05, 2019, 07:25:42 am »
Quote
...Even 1.5Mbd...
Buncha spoiled kids.  Like anything over 115200bps isn't "absurdly fast" for an Async UART connection..."when I was young, we were absurdly happy to use the 300bps acoustic coupler terminals instead of the 110bps ASR33s, and those 2400bps "local" CRTs were heaven!   And Get Off Of My Lawn!"-
A more interesting question is how a given adapter behaves in a ping-pong prompt/response scenario (like the Arduino STK500v1 "upload" protocol.)  As PCB.Wiz implied, packetization issues are more likely to be a bottleneck at "reasonable" speeds than raw character throughput.
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #16 on: July 05, 2019, 08:55:25 am »
I wrote some code to test throughput and reliability.

Some results for CH340G.
Runs close to full speed at 500,000 and below.
Data corruption at 1,500,000 and above.

Code: [Select]
462470 bits per second (15.4157 % of 3000000 bps)
46247 bytes per second
1048576 total written
1048576 total confirmed
1032192 total read       (98 %)
1032132 total error bytes
22319 milliseconds elapsed time

463150 bits per second (23.1575 % of 2000000 bps)
46315 bytes per second
1048576 total written
1048576 total confirmed
1032192 total read       (98 %)
1031388 total error bytes
22286 milliseconds elapsed time

461580 bits per second (30.772 % of 1500000 bps)
46158 bytes per second
1048576 total written
1048576 total confirmed
1032192 total read       (98 %)
440608 total error bytes
22362 milliseconds elapsed time

640000 bits per second (64 % of 1000000 bps)
64000 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
16384 milliseconds elapsed time

640000 bits per second (85.3 % of 750000 bps)
64000 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
16384 milliseconds elapsed time

479980 bits per second (96 % of 500000 bps)
47998 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
21846 milliseconds elapsed time

250010 bits per second (100 % of 250000 bps)
25001 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
41941 milliseconds elapsed time

230780 bits per second (100.2 % of 230400 bps)
23078 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
45436 milliseconds elapsed time

115390 bits per second (100.2 % of 115200 bps)
11539 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
90870 milliseconds elapsed time
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 1640
  • Country: pl
Re: CH340 USB-UART Speed tests ?
« Reply #17 on: July 05, 2019, 09:04:38 am »
My bit rates notes from evaluation of the CH340C. A few notable exceptions to the 3M/N rule are 2.0M, 1.2M and 923k (~115.2 *8). You have to ask for exactly 921,600 to get closest to it.
Is this from Windows?
A glance at the Linux driver suggests the chip has much higher resolution, like PL2303.
The latter supports pretty much any rate below 6M with 2% granularity or so. I have successfully used it to push data at oddball bitrates like 1.66M into an MCU running at unusual clock.

As for corruption, it's probably not corruption but simple loss of a few bytes here and there, but your program reports errors because it isn't sophisticated enough to detect loss.
For starters, use two adapters, preferably connected to different USB controllers (not just ports, usually two ports are connected to each 1.1 host controller).
If it doesn't help, enable hardware flow control. This will give you lossless transmission even in loopback, but at lower throughput.

For reliable high speed UART, flow control is a must unless you are absolutely sure that your receiver has sufficient buffering and low enough latency not to lose bytes.
« Last Edit: July 05, 2019, 09:10:10 am by magic »
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #18 on: July 05, 2019, 09:17:37 am »
Same test with FT232RL
Works very well at 1,000,000 bps and lower

Code: [Select]
1059560 bits per second (35.3187 % of 3000000 bps)
105956 bytes per second
1048576 total written
1015808 total read       (96 %)
999680 total error bytes
9587 milliseconds elapsed time

906460 bits per second (45.323 % of 2000000 bps)
90646 bytes per second
1048576 total written
1032192 total read       (98 %)
1024000 total error bytes
11387 milliseconds elapsed time

791610 bits per second (52.774 % of 1500000 bps)
79161 bytes per second
1048576 total written
1032192 total read       (98 %)
976384 total error bytes
13039 milliseconds elapsed time

998070 bits per second (99.8 % of 1000000 bps)
99807 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
10506 milliseconds elapsed time

749030 bits per second (99.9 % of 750000 bps)
74903 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
13999 milliseconds elapsed time

499580 bits per second (99.9 % of 500000 bps)
49958 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
20989 milliseconds elapsed time

249890 bits per second (100 % of 250000 bps)
24989 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
41960 milliseconds elapsed time

230670 bits per second (100 % of 230400 bps)
23067 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
45456 milliseconds elapsed time

115360 bits per second (100 % of 115200 bps)
11536 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
90891 milliseconds elapsed time
[code]
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #19 on: July 05, 2019, 09:24:39 am »
My bit rates notes from evaluation of the CH340C. A few notable exceptions to the 3M/N rule are 2.0M, 1.2M and 923k (~115.2 *8). You have to ask for exactly 921,600 to get closest to it.
Is this from Windows?
Yes
Quote
A glance at the Linux driver suggests the chip has much higher resolution, like PL2303.
The latter supports pretty much any rate below 6M with 2% granularity or so. I have successfully used it to push data at oddball bitrates like 1.66M into an MCU running at unusual clock.
Yep, I agree, probably supports more than what is available with the Windows driver.
Quote
As for corruption, it's probably not corruption but simple loss of a few bytes here and there, but your program reports errors because it isn't sophisticated enough to detect loss.
I doesn't try to determine the nature of the loss/corruption. That may be added later.
Quote
For starters, use two adapters, preferably connected to different USB controllers (not just ports, usually two ports are connected to each 1.1 host controller).
That is already on the list of things to try.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 1640
  • Country: pl
Re: CH340 USB-UART Speed tests ?
« Reply #20 on: July 05, 2019, 09:32:01 am »
Yep, I agree, probably supports more than what is available with the Windows driver.
Maybe or maybe not, just because Linux doesn't deliberately reject bitrates other than 2M or 1.5M doesn't mean the chip wouldn't do something stupid if you try to use them.
I would give it a quick test and report back but I don't have any CH340.

Another interesting thing to check is disconnect RX so that the chip isn't busy receiving and see how much data it can push into TX. IIRC, PL2303 could transmit well over 2Mb/s and bitrates above 3Mb/s made pretty much no difference to throughput.
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #21 on: July 05, 2019, 09:37:52 am »
I wrote some code to test throughput and reliability.

Some results for CH340G.
Runs close to full speed at 500,000 and below.
Data corruption at 1,500,000 and above.

Is this a loop-back test ? (TX links to RX) - that's a useful self-pacing test point.

Somewhat tougher, is to connect a FT232H/FT2232H to Rx side (ensures 8.n.1 incoming stream, no gaps), and then TX two ports at once for true full duplex...
 

Offline PCB.Wiz

  • Frequent Contributor
  • **
  • Posts: 382
  • Country: au
Re: CH340 USB-UART Speed tests ?
« Reply #22 on: July 05, 2019, 09:45:44 am »
Maybe or maybe not, just because Linux doesn't deliberately reject bitrates other than 2M or 1.5M doesn't mean the chip wouldn't do something stupid if you try to use them.
I would give it a quick test and report back but I don't have any CH340.
Yes, based on the MCU's the company makes, the granularity is as per the table I posted above. ie The hardware does not support more. (but that list is already more than the data claims)
Most of the better USB-UART parts will round to the nearest valid baud speed, when asked for any baud rate.

Another interesting thing to check is disconnect RX so that the chip isn't busy receiving and see how much data it can push into TX. IIRC, PL2303 could transmit well over 2Mb/s and bitrates above 3Mb/s made pretty much no difference to throughput.
That's shown above on the scope, the extra added stop bits mean the sustained average speed does not change 2M to 3M.

..  like PL2303. The latter supports pretty much any rate below 6M with 2% granularity or so. I have successfully used it to push data at oddball bitrates like 1.66M into an MCU running at unusual clock.
There is a PL2303GS showing, but very new. I'd like to get my hands on some of those...
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #23 on: July 05, 2019, 09:46:50 am »
FT230X is the best so far. Perfect performance at up to 3 Mbps.

Code: [Select]
2983990 bits per second (99.5 % of 3000000 bps)
298399 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
3514 milliseconds elapsed time

1992350 bits per second (99.6 % of 2000000 bps)
199235 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
5263 milliseconds elapsed time

1495400 bits per second (99.7 % of 1500000 bps)
149540 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
7012 milliseconds elapsed time

998070 bits per second (99.8 % of 1000000 bps)
99807 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
10506 milliseconds elapsed time

748920 bits per second (99.9 % of 750000 bps)
74892 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
14001 milliseconds elapsed time

499510 bits per second (99.9 % of 500000 bps)
49951 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
20992 milliseconds elapsed time

249860 bits per second (99.9 % of 250000 bps)
24986 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
41966 milliseconds elapsed time

230640 bits per second (100.1 % of 230400 bps)
23064 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
45462 milliseconds elapsed time

115340 bits per second (100.1 % of 115200 bps)
11534 bytes per second
1048576 total written
1048576 total read       (100 %)
0 total error bytes
90904 milliseconds elapsed time
 

Online oPossum

  • Frequent Contributor
  • **
  • Posts: 920
  • Country: us
  • The other white meat
Re: CH340 USB-UART Speed tests ?
« Reply #24 on: July 05, 2019, 09:49:19 am »
I wrote some code to test throughput and reliability.

Some results for CH340G.
Runs close to full speed at 500,000 and below.
Data corruption at 1,500,000 and above.

Is this a loop-back test ? (TX links to RX) - that's a useful self-pacing test point.

Somewhat tougher, is to connect a FT232H/FT2232H to Rx side (ensures 8.n.1 incoming stream, no gaps), and then TX two ports at once for true full duplex...

Yes, just a simple loop back on a single chip for now.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf