Page 1 of 1

Usb CDC

Posted: Wed Aug 31, 2022 12:37 pm
by DrBanana
Is there any example of USB CDC, I want to transfer data at higher rate, but found no example related to that with stm32 arduino core.

Re: Usb CDC

Posted: Wed Aug 31, 2022 2:25 pm
by ag123
use Serial.write(buffer, size);
instead of Serial.println
that could improve things.
in USB CDC serial, the polling is controlled by the host, and if you have many other peripherals e.g. mouse, keyboard, hubs etc, slots are assigned by the host, and it would reduce the polling slots to your device.
the designed bandwidth is 12 Mbps even for USB CDC, but polling, framing, and all other 'control' signals that are multiplexed means that only a small piece of 12 Mbps is available, the more devices (mouse, keyboard, etc) connected, the more slots are allocated elsewhere rather than your device.

Re: Usb CDC

Posted: Thu Sep 01, 2022 6:25 am
by DrBanana
ag123 wrote: Wed Aug 31, 2022 2:25 pm use Serial.write(buffer, size);
instead of Serial.println
that could improve things.
in USB CDC serial, the polling is controlled by the host, and if you have many other peripherals e.g. mouse, keyboard, hubs etc, slots are assigned by the host, and it would reduce the polling slots to your device.
the designed bandwidth is 12 Mbps even for USB CDC, but polling, framing, and all other 'control' signals that are multiplexed means that only a small piece of 12 Mbps is available, the more devices (mouse, keyboard, etc) connected, the more slots are allocated elsewhere rather than your device.
I do use Serial.write, Yes even 12Mbps is better than 2Mbps. Does the slots still divide if I have one device per usb port available on laptop ?

Re: Usb CDC

Posted: Thu Sep 01, 2022 6:49 am
by ag123
2 Mbps is 'normal', unless you have a usb host that connect only to the single (stm32) device.
if you have keyboards, mouse, other hubs etc, it is multiplexed and your (stm32) device only get a fraction of that 12 Mbps
there are also other overheads.
it also depends on the host polling frequency
even on a laptop, the keyboard and touchpad are probably 'hidden' usb devices, there is a 'hidden' hub in there too
and i'm not too sure if usb (host) i.e. your pc or laptop needs to poll the 'empty' slots too. lets just say that your usb host has a 'hub' (hidden) that supports up to 6 usb ports, and say it poll that round robin giving them 1 ms each per poll, then you need to take that 12 Mbps divide that by 6 or maybe even 7 (i.e. including the hub) and you get 12 / 7 ~ 1.714 Mbps.
pretty much what you see. so the bottleneck don't look like the stm32 after all

Re: Usb CDC

Posted: Sat Sep 03, 2022 1:08 pm
by DrBanana
what about USB HiSpeed 480Mbps with stm32, is it possible that we can get some fraction of it or half of it ?

I want to send 25kb of data in few milliseconds, max 5ms

Re: Usb CDC

Posted: Sat Sep 03, 2022 1:34 pm
by ag123
the main thing with that is the usb high speed ulpi transceiver that needs to be build and integrated with a supported chip
https://www.st.com/en/interfaces-and-tr ... l#overview
https://www.microchip.com/en-us/product/USB3300
this thing is needed with a supported chip, and i'm not sure what other things may be needed.
I think the speeds is 60 MB per sec 8 parallel bits on the ULPI bus - 480 Mbps
at those speeds both the stm32 and ulpi transceiver probably needs to be built on the same board, with all the accessories parts needed for the transceiver to work.
without this transceiver and the integration with a supported chip, there is only usb full speed 12 Mbps.

you can try integrating with boards like this to see if it works, a supported stm32 chip is needed
https://www.aliexpress.com/wholesale?ca ... xt=usb3300
https://www.aliexpress.com/item/32706614626.html
i've not tried them out and do not know if they'd even work