SetCommState() fails on PC when connected to USB in CDC mode for iMX6

Thanks for engaging with this topic by the way @alex.tx
I switched back to a T20 installed in the same board and running the same firmware to double-check that it works OK with the T20 and doesn’t work with the iMX6 (It does work with the T20). I noticed a difference between the T20 and the iMX6 when I did this, I think this difference might be the root cause.

The difference is that the T20 USB connection appears on the PC as USB class 2, subclass FF, prot FF while the iMX6 USB connection appears as class 2, subclass 2, prot FF as shown below.

T20
iMX6

According to this page class 2 and subclass 2 specifies a modem, while class 2 and other values of subclass specifies a COM port. I think the problem might be that the iMX6 is advertising its USB connection as being a modem by mistake.
USB device class drivers included in Windows - Windows drivers | Microsoft Learn

This reminds me of an issue I reported a few years ago about the USB subclass not being correct for the RNDIS driver. The solution to that was that the Toradex team made a patched version of the relevant DLL which I installed on my Colibri module in order to correct the USB subclass number. That allowed for a quicker fix than waiting for the next release of the OS image and that type of fix could also work here.
RNDIS on Windows 10 to connect to CE7 running on T20 - Technical Support - Toradex Community

I also packaged my C++ code as a project for you. This simple code will prompt you for a COM port number and will then test the port and tell you if SetCommState() succeeds or not.
SetCommState.zip (33.0 KB)