Okay, I've been looking into this a bit more and I've come to the conclusion that I don't need CDC and COM ports anymore, woo-hoo!
Firstly, I looked at using USB HID which is a nice solution because there is no driver install.
usbhid.sys/usbhid.dll are used as kernel/userspace drivers and hidapi.dll[1] provides an easy to use cross-platform API.
The maximum data rate of 64,000 bytes/sec full-duplex is ample for many applications.
..but what I've recently discovered (many of you probably knew years ago) is that you can use any USB transport type without a driver install and get FS/HS/SS data rates. Just as easy as HID.
With Windows 8.1 onwards, your USB device can respond with certain string descriptors which cause it to be assigned winusb.sys/winusb.dll as the kernel/userspace drivers, with no user interaction.
Plug and play. Your host software can then use winusb.dll directly, or via libusb for easier API and cross-platform ability.
This system is often referred to as Windows Compatability ID (WCID). There are some links below [2] to get you started if you want more background info.
There is an open source embedded USB stack called 'M-Stack' [3].
It's for all PICs which have the Microchip Full Speed USB peripheral, and that includes PIC16/18/24/32, not PIC32MZ (which has HS USB).
IMHO it's well written and much easier to understand than any of Microchip's USB code, which has so much abstraction and pointer shenanigans it makes me dizzy.
Useful to look over even if you are going to use Microchips code in your device.
Anyway, M-Stack includes this WCID feature and I'm attaching a ready configured project here.
FYI M-Stack needed one tiny fix, the last byte of this struct was zero but it actually must be 0x01:
struct microsoft_os_descriptor os_descriptor =
{
0x12, /* bLength */
0x3, /* bDescriptorType */
{'M','S','F','T','1','0','0'}, /* qwSignature */
MICROSOFT_OS_DESC_VENDOR_CODE, /* bMS_VendorCode */
0x01, /* bPad MUST BE 0x01 */
};
This project has been tested on PIC32MX but should work for other PIC families.
Change MPLABX project settings and hardware.c for your device as appropriate.
Build the project (no massive external dependencies like Microchip USB stuff, all self contained) and program your device.
Plug it into a USB socket and it appears in Win10 Device Manager under 'Universal Serial Bus Devices' as 'USB Stack Test Device'
It is setup with VID=0x1209 PID=0x000E which is assigned for test devices by pidcodes [4].
USB Tree View[5] shows all the details for the device, with the four endpoints established (pipes), in addition to endpoint 0.
---------------- Connection Information ---------------
Connection Index : 0x06 (Port 6)
Connection Status : 0x01 (DeviceConnected)
Current Config Value : 0x01 (Configuration 1)
Device Address : 0x0E (14)
Is Hub : 0x00 (no)
Device Bus Speed : 0x01 (Full-Speed)
Number Of Open Pipes : 0x04 (4 pipes to data endpoints)
Pipe[0] : EndpointID=1 Direction=IN ScheduleOffset=0 Type=Bulk
Pipe[1] : EndpointID=1 Direction=OUT ScheduleOffset=0 Type=Bulk
Pipe[2] : EndpointID=2 Direction=IN ScheduleOffset=0 Type=Bulk
Pipe[3] : EndpointID=2 Direction=OUT ScheduleOffset=0 Type=Bulk
The firmware just has a loopback on endpoint 1 and same for endpoint 2 (see main.c).
I have attached a very simple Python script which puts some data through the loopback - read it for install instructions.
Goodbye COM ports!
[1]
HIDAPI library was originally developed by Alan Ott.
It is now part of the libusb project.
https://github.com/libusb/hidapi[2]
Keywords are WinUSB, WCID, Microsoft OS Descriptors/Extended Descriptors. Some links:
https://stackoverflow.com/questions/38906880/how-to-work-with-winusbhttps://github.com/pbatard/libwdi/wiki/WCID-Deviceshttps://www.silabs.com/community/mcu/32-bit/forum.topic.html/using_microsoft_osd-lMCDhttps://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb[3]
Guess what, also developed by Alan Ott!
https://github.com/signal11/m-stack[4]
https://pid.codes/1209/[5]
USB Tree View
https://www.uwe-sieber.de/english.html