Virtual COM with USB performance - Page 1
Forum section: electronics / general

author: bogdant
author_rank: Regular Contributor
timestamp: November 15, 2020, 12:47:29 pm
content: I am designing a CAN->USB convertor around STM32H750 and I stuck on transmitting CAN frames to USB, the CAN frames are generated by CAN1 and loopback on CAN1 RX and send to USB. I could not get more speed then 2500bytes/25ms(100kB/s). Sometimes after a while the transmit USB handler(CDC_Transmit_HS) in STM32 takes from usually 10us to more 45ms. I also realized that the internal is only FS not HS.Is there still room for improvement in current hardware setup ?https://github.com/bogdan-tirzioru/BusAnalizer/blob/master/factory/sampleA/schematic.PDFhttps://github.com/bogdan-tirzioru/BusAnalizer/tree/master/FirmwareAny idea what configuration shall I try to improve this?

author: voltsandjolts
author_rank: Unknown
timestamp: November 15, 2020, 02:23:39 pm
content: Max data rate for CDC on USB FS is around 1MByte/sec.So, certainly 500kBytes/sec should be achievable with that MCU.Are you using ping-pong buffers?Direct to port connection, i.e. no hubs?

author: rounin
author_rank: Regular Contributor
timestamp: November 16, 2020, 04:29:57 am
content: I had a bunch of issues with ST's USB driver. It isn't really interrupt or multi-thread safe, and it would lock up on me with bidirectional traffic - that is, no transaction completion interrupts would fire after a few packets going both directions at the same time.I wrote a small new usb stack here with a H750 driver:https://github.com/jacobschloss/libusb_dev_cpp,https://github.com/jacobschloss/libusb_dev_cpp/blob/master/src/driver/stm32/stm32_h7xx_otghs2.cpp. It actually was also for a USB CAN adapter, coincidentally -https://github.com/suburbanembedded/hadoucan-fw. I have it working in HS mode (external PHY), haven't bench marked but its pretty fast, keeping up with 12Mbps CAN FD.So, it could be ST's driver.

author: bogdant
author_rank: Regular Contributor
timestamp: November 16, 2020, 07:36:18 am
content: Quote from: voltsandjolts on November 15, 2020, 02:23:39 pmSo far I have not implemented any buffering, I know that I need too, so far the consistency was not in the focus.There is no hubs in the involved.

author: bogdant
author_rank: Regular Contributor
timestamp: November 16, 2020, 07:44:23 am
content: Quote from: rounin on November 16, 2020, 04:29:57 amThe change to HS PHY will be in the next hardware version, I am hopping to have a STM32H7xx version with included HS PHY, it is not a joy to route high speed signals on a custom board. In the stm32F735 there is included but it is not CANFD included. I will have a look on the project you are working. I my design initial plan was to include 2 CANFD, but limitation is clear now, I will be lucky if one CANFD will work OK.Did you use more then 3 endpoints or dma ?

author: fchk
author_rank: Frequent Contributor
timestamp: November 16, 2020, 11:29:10 am
content: This Controllerhttps://www.microchip.com/wwwproducts/en/ATSAMV70N19has got built-in HS-USB including PHY and two CAN-FD interfaces. Might be more suitable for you.fchk

author: hans
author_rank: Super Contributor
timestamp: November 16, 2020, 12:47:59 pm
content: If you want to stay inside the STM32 ecosystem, the STM32F730 also has integrated HS.Not sure if they have CAN-FD (maybe the F733?)edit:, ah if the 735 doesn't have CAN-FD.. then probably the 733 won't neitherHS has the advantage of being able to transfer 512 bytes from an bulk endpoint rather than 64 bytes.The Usbd_cdc descriptoris now set up for512 bytes. I'm not sure how the stack performs if you still attempt so transmit 512 or 2K at a time.

author: bogdant
author_rank: Regular Contributor
timestamp: November 16, 2020, 02:53:45 pm
content: Quote from: hans on November 16, 2020, 12:47:59 pmI would expect to send 4 packets of 512 for each transmit trigger(CDC_Transmit_HS).

author: rounin
author_rank: Regular Contributor
timestamp: November 16, 2020, 10:30:29 pm
content: Quote from: bogdant on November 16, 2020, 07:44:23 amOnly 3 endpoints, no dma (just loading FIFO up to 512B at a time). My stack recently got support for composite devices so I might be adding another virtual com port for diagnostics (patches not public yet).Our board was very small, I don't think we were /that/ precise laying out the ULPI bus. but the tracks were also only like 1-2 cm long so ymmv.

author: voltsandjolts
author_rank: Unknown
timestamp: November 17, 2020, 01:05:05 pm
content: Another interesting example for USB connection is the TeensyUSB stack for STM32 inc. H7.It has an example for a WinUSB WCID device, which means seamless (no user interaction) driver install for your device (WinUSB.sys/WinUSB.dll).Your app can then use either WinUSB.dll directly or via libusb (cross-platform).Thus it allows bulk transfer while avoiding both the clumsy driver install and COM ports.I haven't tried it myself but its on my todo list.https://github.com/xtoolbox/TeenyUSB/blob/master/sample/custom_bulk/teeny_usb_desc.c

author: bogdant
author_rank: Regular Contributor
timestamp: November 17, 2020, 07:30:01 pm
content: Quote from: hans on November 16, 2020, 12:47:59 pmI have change to 2K in the define (usbd_cdc.h)#define CDC_DATA_HS_MAX_PACKET_SIZE 2048U /* Endpoint IN & OUT Packet size */I also succeeded to reduce to 5ms/2048 by tuning the windows application. Setting to 2ms the worker threed does not release anymore and lead to main tread not to update anymore.What is the maxim packet endpoint size?

author: Jeroen3
author_rank: Super Contributor
timestamp: November 17, 2020, 09:13:14 pm
content: What are you using to receive the Virtual COM with?

author: bogdant
author_rank: Regular Contributor
timestamp: November 18, 2020, 05:25:26 am
content: Quote from: Jeroen3 on November 17, 2020, 09:13:14 pmI have a MFC application based on PJ Naughter driver:https://github.com/bogdan-tirzioru/BusAnalizer/tree/master/BusWinAppl/BusWinApplI also compare it with Putty application.http://www.naughter.com/serialport.html

author: bogdant
author_rank: Regular Contributor
timestamp: November 18, 2020, 12:17:35 pm
content: STM32 USB training:https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/STM32-USB-training.htmlhttps://www.youtube.com/playlist?list=PLnMKNibPkDnFFRBVD206EfnnHhQZI4Hxa

author: bogdant
author_rank: Regular Contributor
timestamp: November 20, 2020, 05:52:37 am
content: Quote from: rounin on November 16, 2020, 04:29:57 amI could not find the schematic in the repository. The project you have is written in C++, most interesting

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 21, 2020, 05:08:43 am
content: Quote from: voltsandjolts on November 17, 2020, 01:05:05 pmTeeny, as in TeenyUSB; not Teensy. (TeenyUSB has nothing to do with Teensy microcontrollers.)