-
Notifications
You must be signed in to change notification settings - Fork 1k
[USB] Generic implementation providing HID composite (Mouse and Keyboard) and CDC in FS/HS #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Good work. But sadly I can't test the branch right now, since my only working STM32 prototype with USB support is right now at a beta testers place. Could you maybe provide an example in the example project on how to use the features provided in thid PR? |
There is no special example. |
Ah okay, I got confused them by your comment about the |
oh no. My concerns was about the |
Compiling with;
. |
So use the build_opt.h and |
How is CDC enabled within a sketch? Tried a few things but still get an unrecognized USB device in Windows. |
You enable it thanks the USB interface menu. Then it depends of your board. HS or FS. |
Ha, OK so I need to hack boards.txt for the BLACK407VET, thanks. |
So compiled with USB CDC FS option I can see the board as CDC FS & a Serial USB COM port in USBDeview but it is 'purple' and I cannot select the COM port in the IDE Serial monitor, is there some internal glue that needs to happen to get Serial talking via USB? (I noticed the re-enumerate comments above). |
If you get the full PR, the menu should be available.
Nice it is recognized, anyway you should be able to select it. Note: purple on USBDeview means : The device is connected. You must disconnect the device from USBDeview or from Windows "Safely Remove Hardware" option before you physically unplug it |
Host OS is Windows 10. I have applied the full PR, there are no USB options for GenF4 in the included boards.txt, I just copied the appropriate lines. Is there anyway to overload Serial to SerialUSB as in Roger's core? |
Windows 10 Still cannot use the COM port, simple sketch of: void setup() {
Tried also on WIndows 8.1 - OS fails to install drivers for the devices. |
Have also tried Ubuntu 16.04 LTS, I can See the CDC FS device but not the Serial device via 'sudo lsusb -v' |
@BennehBoy Set PID in Then VCP works fine. I've made the benchmark:
So this seems to be a good results for USB FS. |
Made this change but I still cannot open the COM port :( I will try on another Win10 machine and report back |
Here's what device manager says: CDC in FS Mode
USB Serial Device
Same issue on 2 machines |
In this case it seems to be a driver issue. |
OK, it must be driver related. The only driver packages I can see in programs & features are related to ST-Link, removing them does not help. I can now see the COM port on a Windows 8.1 system which has never been used for Dev. I'll try again on a clean Win 10 machine tomorrow. |
I replaced the driver using Zadig and can now use the comport, however two devices are shown 1 of which is still inoperable. Getting there 👍 |
Fine. |
It's actually 3, a composite, a Communication Device, and a CDC Data device. Don't get this on a Windows 8.1 machine. I'll try on a couple of Windows 10 machines later in case I've goosed this one. Ubuntu 116.04 LTS Server I see a USB device (interface 0), but no tty gets mapped. I have a spare machine that I'll boot from Another distro later to see how that copes. |
@fpistm Just tried the PR and it works just fine in FS mode on the STM32F407 based Armed 3d printer board. Shows up as a "STMicroelectronics Virtual COM port" device in Windows 10, as expected. |
Added fixes as advised by @ktand * If the USB packet to be sent is equal to the USB buffer size (64 bytes), a Zero Length Packet must be sent. Otherwise the USB CDC connection will fail. * Add check for linestate in CDC_Flush and in CDC_TIM_PeriodElapsedCallback to ignore transmission if the device is disconnected.
Add USB menu for Generic F4 Change PID to 0x0483 Signed-off-by: Frederic.Pillon <[email protected]>
Signed-off-by: Frederic.Pillon <[email protected]>
See https://www.usb.org/defined-class-codes Well documented for Win10: https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-driver-installation-based-on-compatible-ids * If you want to load Usbser.sys automatically, set the class code to 02 and subclass code to 02 in the Device Descriptor. For more information, see USB communications device class (or USB CDC) Specification found on the USB DWG website. With this approach, you are not required to distribute INF files for your device because the system uses Usbser.inf. * If your device specifies class code 02 but a subclass code value other than 02, Usbser.sys does not load automatically. Pnp Manager tries to find a driver. If a suitable driver is not found, the device might not have a driver loaded. In this case, you might have to load your own driver or write an INF that references another in-box driver. * If your device specifies class and subclass codes to 02, and you want to load another driver instead of Usbser.sys, you have to write an INF that specifies the hardware ID of the device and the driver to install. For examples, look through the INF files included with sample drivers and find devices similar to your device. For information about INF sections, see Overview of INF Files. Signed-off-by: Frederic.Pillon <[email protected]>
Issue raised by @makarenya (see stm32duino#388) USB Specification EP0 should never STALL. Issue reproduced when using USB 3.0 port. Device is not recognized if STALL present. Signed-off-by: Frederic.Pillon <[email protected]>
Not sure if this is an issue/optimisation opportunity for future PR's but compiling with CDC enabled results in ~10K more SRAM usage than without. That's a big hit for smaller boards... |
Right, this is mainly due to the buffer, hereafter .map extraction.
This could probably optimized |
Ok I'll do a quick compare with Roger's core later to see what buffer size
it uses.
…On Wed, Jan 16, 2019 at 8:14 AM Frederic Pillon ***@***.***> wrote:
Right, this is mainly due to the buffer, hereafter .map extraction.
Source code Name Size dec Size hex Section Address
core.a(usbd_cdc_if.c.o) StackTxBuffer 2048 0x800 .bss 0x20000464
core.a(usbd_cdc_if.c.o) UserTxBuffer 2048 0x800 .bss 0x20000c64
core.a(usbd_cdc_if.c.o) UserRxBuffer 2048 0x800 .bss 0x20001464
core.a(usbd_conf.c.o) g_hpcd 1008 0x3f0 .bss 0x20001ca4
core.a(usbd_interface.c.o) hUSBD_Device_CDC 668 0x29c .bss 0x20002194
core.a(usbd_desc.c.o) USBD_StrDesc 256 0x100 .bss 0x20002094
This could probably optimized
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX0eXlLZSWLBUb5IytlGz-C57xQo-TpNks5vDt9WgaJpZM4ZPxzT>
.
|
Not sure if I'm barking up the wrong tree and these are sub buffers, but Serial TX & RX buffers for CDC are 256 bytes in rogers core (on F1 at least): |
Pardon, but what about my PR (into this PR). I use smaller buffers (only 64b for transmitting and 128b for sending, when this PR uses 2048b buffer for receiving and TWO 2048b buffers for sending). My PR not used timers to determine the moment, when it can continue sending data. Instead, it uses a USB interrupt to detect this moment (which is somewhat more effective) |
I think your PR has conflicts - perhaps rebase now that this one is merged, and just include the changes - would be v welcome from me, or split into two? One for timer removal, one for buffer size reduction... |
Buffer sizes can be reduced in the current PR. They are simply chosen thoughtlessly large. Maximum size of USB packet in full speed mode can't be greater when 64b. So 128b is enough. For the high speed devices, maximum size of the buffer is 512b. so you need only 1k, not 2k. Just write this define:
And you will have extra small and compact buffers for small devices and two time smaller buffers in devices with HS support (but they have more RAM, and it's not will a problem for it) Timer reduction and extreme memory optimization PR i make in few days. |
I think you just need to rebase your existing PR against master - 388 has been merged already. |
Yes, give me few days, please! |
I'm not pressuring you 😃 |
@makarenya don't worry I always planned to remove Timer as you suggested (and also @edogaldo) |
@fpistm It is not working when add Keyboard and Mouse in one sketch, but it work well when using Keyboard or Mouse standard-alone. They can't work together?? I test this with version 1.5.0, the testing code:
|
@roc2 normally yes. I've tested with both on the same sketch. |
@fpistm My board is Black STM32F407VE, on win10 OS. |
Tested with 1.5.0 on Win10 it works. |
Issue raised by @makarenya (see stm32duino#388) USB Specification EP0 should never STALL. Issue reproduced when using USB 3.0 port. Device is not recognized if STALL present. Signed-off-by: Frederic.Pillon <[email protected]>
[USB] Generic implementation providing HID composite (Mouse and Keyboard) and CDC in FS/HS
This PR includes HID composite (Keyboard and Mouse) and CDC and will replace #91 and #344.
This new PR will be more generic, no more needs to have
usb/
directory in the variant.USB pins are in
PeripheralPins.c
,usbd_desc
andusbd_conf
are common and handle USB base and USB OTG FS/HS (also FS in HS).This means all MCU with USB capabilities could be handled.
PR include your remarks and improvements (I hope).
Several define can be redefined in
variant.h
or thanks thebuild_opt.h
including timer which by default is set toTIM6
as well theTIMx_IRQn
(CDC_TIM
andCDC_TIM_IRQn
)LPM is currently not managed as well the BOS descriptor.
Several tests will be required and also some other optimisation (ex: @edogaldo comments #344 (comment) )
USBSerial::write(const uint8_t *buf, size_t len)
has been added but this have to be rewrote properly.readBytes()
could probably be added.Anyway first tests are promising, see below.
First CDC tests performed (using pjrc USB benchmark):
Before Speed improvement from @hasenbanck and @ktand:
After Speed improvement from @hasenbanck and @ktand:
Note: Compare to previous PR, USB is not provided as a built-in library.
So, I did not add the
reenumerate()
as the usbd init is not the same. Any comments are welcome.Updated implementation of
reenumerate()
could be something like that (don't know how manage for USB HS):