Skip to main content
Visitor II
January 23, 2024
Solved

STM32U5x: USB ECM demo - how to setup host?

  • January 23, 2024
  • 4 replies
  • 9571 views

I am progressing on porting the CubeU5 project for STM32U575I-EV as Ux_Device_CDC_ECM to a NUCLEO-U575ZI-Q board:

The USB enumeration seems to work: I hear the sound and I see also an USB "STM32 CDC ECM" device.
BTW: very important to go with the right BSP files: the NUCLEO-U575ZI-Q has a different USPD chip! (I have changed to the right BSP files for NUCLEO, the EVAL board BSP cannot work).

What I get:

  • an "Other devices" in device manager (the driver is not found):

USB_ECM_1.png

No idea what to install on a Windows OS to make the device driver happy.
What works:

  • if I select manually and select "USB devices", "STMicroelectronics" and "STLink Bridge" - the driver is happy
  • but it cannot be right (it does not look like a network interface is added to the system)
  • trying some NDIS and RNDIS drivers fail (Windows complains about issues to install)

USB_ECM_2.png

The MCU FW is not happy:

  • it does not progress on DHCP server: the MCU does not get any IP address (and the event for IP address changed is not coming)

If I try on a MacOS:

  • it looks like I see a new ETH network interface: an "en4" is there when I have connected the MCU board (via USB and FW running as USB ECM, without MCU it is not there)
  • but the FW does not progress here in the same way: it does not get an IP address via DHCP
  • I tried to ping the reported IP address on "en4" - it does not work

There are some threads in Internet related to USB ECM: nothing mentioned for Windows OS, many application notes reference to use Linux (but no idea how to enable DHCP on such an USB EMC device, even it seems to be available (via ifconfig).

Does anybody have a clue how to install and use USB EMC?
(on Windows or MacOS)

What is missing so that MCU FW gets an IP address (via DHCP, as enabled in FW)?

How to install a driver on Windows?
And to make it working on Windows?

    This topic has been closed for replies.
    Best answer by tjaekel

    Now all works!

    Dear STM team: please, could you develop/provide a Windows USB EMC driver?
    (or cooperate with other companies: Seeger, MCCI, NVidia seem to have such one).

    Issue with SD Card solved:
    The flying wires were causing the issue to open the web files. With a carrier board where SD Card adapter is connected - all works fine. BTW: I tried to lower SDMMC speed, clock dividers - nothing helped really, except to make the connection "directly" for SD Card adapter (I got CRC errors on SDMMC transactions).

    STM32U575_USB_ECM_Android.jpg

    So, all works fine (on my Android phone). Just Windows OS "sucks" (missing driver).

    What could "we" do with it?:

    1. A host (Linux, Android, MacOS) could connect and control MCU board via TCP/IP (network) - even the MCU board is just connected via USB (and does not have ETH connection).
    2. Running my (Android) phone as "Mobile Hotspot" - the MCU would get access to Internet, or I can access the MCU via WiFi - even the MCU board does not have a WiFi chip,
    3. I can reuse my host scripts, e.g. Python, talking via network (TCP/IP, UDP sockets) like to my other MCU boards.

    How to solve the issue with missing USB ECM driver on Windows?:

    • STM could think about to provide a Windows driver - would be very kind. Thank you.
    • Install a Virtual Machine (VM) on Windows, running Linux (e.g. Ubuntu) and try if USB in VM would see it as USB ECM.

    So far, all accomplished what I had in mind.
    Well done, STM team, to have such a USB ECM (with the new AZURE RTOS and USB stack),
    which works now on NUCLEO-U575ZI-Q board as well.

    I will cleanup my project and publish on (my) GitHub...

    4 replies

    tjaekelAuthor
    Visitor II
    January 24, 2024

    Another progress: I can see my NUCLEO-U575ZI-Q board on an Android phone! Cool.

    What I have figured out on Internet:

    • USB EMC is NOT supported by Microsoft OS: you would need a special vendor driver (and I could not find any USB EMC driver, STM does not provide any...)
    • (only) RNDIS is supported by Windows (very old), but it is not the same as USB EMC:
      all the RNDIS drivers I tried to install - FAIL (on my Windows 11 PC, "driver cannot be started")
    • I do not want to go with RNDIS (too old, hard to find STM32 examples, all new Middleware with AZURE does not seem to have RNDIS): it would need anyway a different USB stack on MCU board (and hard to find one, just very old stuff, not for my MCU...)

    But USB EMC works fine on Linux, e.g. MacOS, Ubuntu Linux (not tried) but for sure on Android!

    So, I could enable "Ethernet tethering" on my Android phone:

    • I can enable - a very good indication: it means: the USB EMC is recognized (provided by my MCU)
      (if MCU is not providing an USB EMC or it is not connected/not running - not possible to enable - great to see it works)
    • I can also "ping" the IP address (reported on ST-LINK UART) - works

    Just: my SD Card interface or the SD Card seems to have a problem: the file system, to initialize and to open the request files (e.g. "index.html") does not work.
    But the USB EMC is working! Cool

    USB_EMC_log.png

    When I connect via USB-C to Android phone, enable "Ethernet tethering" - the MCU progresses, gets an IP address (via DHCP server) - cool.

    20240123_213101.jpg

    I can also "ping" the MCU, via the IP address on UART log (ping tool on Android phone, I cannot reach MCU from PC: a different network, potentially a "route" setting needed, with a gateway to reach the other network)

    So,

    USB EMC works (just on Linux systems, I saw it popping up also on MacOS), just to fix my SD Card:

    It looks like the NetX file system cannot be initialized successfully: no idea in which format the SD Card has to be (exFAT, FAT32, FAT16, NTFS, ...). MCU cannot open files. (but so far good to see USB EMC working).
    (but looks now more like a minor issue).

    Why do I "like" Windows so much? Because it is a live-long challenge to fix issues...  LOL

     

    tjaekelAuthorAnswer
    Visitor II
    January 24, 2024

    Now all works!

    Dear STM team: please, could you develop/provide a Windows USB EMC driver?
    (or cooperate with other companies: Seeger, MCCI, NVidia seem to have such one).

    Issue with SD Card solved:
    The flying wires were causing the issue to open the web files. With a carrier board where SD Card adapter is connected - all works fine. BTW: I tried to lower SDMMC speed, clock dividers - nothing helped really, except to make the connection "directly" for SD Card adapter (I got CRC errors on SDMMC transactions).

    STM32U575_USB_ECM_Android.jpg

    So, all works fine (on my Android phone). Just Windows OS "sucks" (missing driver).

    What could "we" do with it?:

    1. A host (Linux, Android, MacOS) could connect and control MCU board via TCP/IP (network) - even the MCU board is just connected via USB (and does not have ETH connection).
    2. Running my (Android) phone as "Mobile Hotspot" - the MCU would get access to Internet, or I can access the MCU via WiFi - even the MCU board does not have a WiFi chip,
    3. I can reuse my host scripts, e.g. Python, talking via network (TCP/IP, UDP sockets) like to my other MCU boards.

    How to solve the issue with missing USB ECM driver on Windows?:

    • STM could think about to provide a Windows driver - would be very kind. Thank you.
    • Install a Virtual Machine (VM) on Windows, running Linux (e.g. Ubuntu) and try if USB in VM would see it as USB ECM.

    So far, all accomplished what I had in mind.
    Well done, STM team, to have such a USB ECM (with the new AZURE RTOS and USB stack),
    which works now on NUCLEO-U575ZI-Q board as well.

    I will cleanup my project and publish on (my) GitHub...

    tjaekelAuthor
    Visitor II
    January 25, 2024

    Sorry,

    Dear STM team: please provide an USB ECM driver for Windows OS.
    Or ask Microsoft: why their AZURE RTOS does support USB ECM - but not their host (Windows)?

    Thank you.

    Graduate II
    February 16, 2024

    The code basically stays in Error_handler loop blinking RED LED.

    tjaekelAuthor
    Visitor II
    February 17, 2024

    When you have fetched the code from GitHub?
    There was a version which has crashed. But the latest version on GitHub should have the correct version.
    Try to get it from GitHub again.

    How does your file "ux_device_descriptors.c" looks like? (see below)

    I have placed the BIN files into the GitHub folder "bin": watch carefully which board do you have and the name of file (U5A5 vs U575). The U575 - I have not tested again recently (go with U5A5 and board - which works for me and would be USB HS anyway (but ECM runs just with FS)).

    https://github.com/tjaekel/STM32U5xx_USB_ECM 

    The fix for this crash, in file "ux_device_descriptors.c", function "USBD_FrameWork_CDCECMDesc()":

     /* Append ECM Union functional descriptor to Configuration descriptor */
     pUnionDesc = ((USBD_CDCUnionFuncDescTypedef *)((uint32_t)pConf + *Sze));
     pUnionDesc->bLength = (uint8_t)sizeof(USBD_CDCUnionFuncDescTypedef);
     pUnionDesc->bDescriptorType = 0x24U;
     pUnionDesc->bDescriptorSubtype = 0x06U;
     pUnionDesc->bMasterInterface = pdev->tclasslist[pdev->classId].Ifs[0];
     pUnionDesc->bSlaveInterface = pdev->tclasslist[pdev->classId].Ifs[1];
     *Sze += (uint32_t)sizeof(USBD_CDCUnionFuncDescTypedef);
    
     /* Append ECM Interrupt IN Endpoint Descriptor to Configuration descriptor */
     __USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[2].add),
     (USBD_EP_TYPE_INTR),
     (uint16_t)(pdev->tclasslist[pdev->classId].Eps[2].size),
     (0x00U), (0x00U));
    
     /* Append ECM Data class interface descriptor to Configuration descriptor */
     __USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[1], 0U, 0U, 0x0AU, 0U, 0U, 0U);
    
     /* Append ECM Data class interface descriptor to Configuration descriptor */
     __USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[1], 1U, 2U, 0x0AU, 0U, 0U, 0U);
    
     /* Append ECM OUT Endpoint Descriptor to Configuration descriptor */
     __USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[0].add),
     (USBD_EP_TYPE_BULK),
     (uint16_t)(pdev->tclasslist[pdev->classId].Eps[0].size),
     (0x00U), (0x00U));
    
     /* Append ECM IN Endpoint Descriptor to Configuration descriptor */
     __USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[1].add),
     (USBD_EP_TYPE_BULK),
     (uint16_t)(pdev->tclasslist[pdev->classId].Eps[1].size),
     (0x00U), (0x00U));
    
     /* Update Config Descriptor and IAD descriptor */
     ((USBD_ConfigDescTypedef*)pConf)->bNumInterfaces += 2U;
     ((USBD_ConfigDescTypedef*)pConf)->wDescriptorLength = *Sze;

    There were a descriptor missing and on interim version was a bug. This is the working one - compare with your code (or update this file from GitHub).

     

     

    Graduate II
    February 17, 2024

    I was using this repo as I've only U575ZI-Q Nucleo board right now.
    https://github.com/tjaekel/NUCLEO-U575ZI-Q_USB_ECM

    Tried this repo for board without SD card and everything works fine. Can control the LED on the board.
    https://github.com/tjaekel/NUCLEO-U575ZI-Q_USB_ECM_noSDCard

    Had tried the CDC-ECM project on STM32H735G-DK board earlier so was familiar with it.

    https://github.com/STMicroelectronics/x-cube-azrtos-h7/tree/main/Projects/STM32H735G-DK/Applications/USBX/Ux_Device_CDC_ECM\

    The USB-C OTG type cable works reliably. I used this adapter.
    https://www.amazon.com/gp/product/B07BS8SRWH?th=1

    With regular USB-C cable, the phone sometimes gets confused and thinks a charger is connected. 

    With STM32H735G-DK, I had modified the example project to use static IP instead and just used Ethernet setting on phone in static IP mode. No need to look for IP address on console. 

    Great that you found a CDC-ECM driver too for Windows. Very useful.

    Graduate II
    June 26, 2024

    @tjaekel , thanks for sharing in so much detail - very interesting. Would you mind replacing the references to "EMC" in your first few posts with "ECM"? just to avoid confusion by any newcomers who would otherwise benefit from all the detailed information you generously provided.

    tjaekelAuthor
    Visitor II
    June 26, 2024

    I am sorry for the type: yes, ECM
    (how to edit old posts?)

    Graduate II
    June 26, 2024

    (how to edit old posts?)

    @tjaekel, click the little drop-down arrow located above the post's date/time and choose "edit reply".

     

    BarryWhit_0-1723754650534.png

    Graduate II
    August 15, 2024

     

    For anyone coming here due to interest in ethernet/IP over USB, I'll note that TinyUSB has support for ECM, RNDIS, and recently added an NCM impl as well. Their maturity varies,  but at least there's active development around it.

    Windows 11 ships with a microsoft driver for usb NCM devices.