cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5x: USB ECM demo - how to setup host?

tjaekel
Lead

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?

21 REPLIES 21

BTW: you have to do this "Ethernet tethering" all the time again on Android phone, after USB was disconnected, or the MCU board reset.

I'm using S22 Ultra.

It was bit tricky to get IP address on the board.

Ethernet Tethering worked after some work around.

I've to go to Ethernet setting, disable it, change the setting to DHCP, then enable Ethernet.

Then come back to Ethernet Tethering and enable it.

Then I see IP address on console

RajeshTripathi_0-1708030683037.png

However, the ping is still not working.

 

RajeshTripathi_2-1708030887722.png

 

 

Do you see a red LED close to the debugger USB port?
Do you see a crash in IDE?
Compile with debug flags (-g3, -Og) and check if MCU FW ends up in a Hardfault_Handler.
If MCU FW crashes - therefore ping fails (?)

On my Android system nothing to do. But, actually, your phone has a different IP address (e.g. via WiFi), 
it is on a different network. In order to reach the MCU via USB ECM - there must be a gateway and route inside
Android (but now idea how to set such one, not needed for me).

The LD3, RED LED starts blinking as soon as I click on "Ethernet tethering" button on phone.

Tried another galaxy S23 phone and same behavior.

Tried to run under debugger and it's waiting in HAL_delay when I suspend the debugger. There is no HW fault apparently.

Maybe, you can share your executable binary that I can load on the board to check if something else is causing problem and it's not the code itself.

RajeshTripathi_0-1708120716274.png

When I suspend the code execution under the debugger, the "Ethernet tethering" stays connected and LED stops blinking. LED resumes blinking on running again.  So USB sub system is still working.

After setting the break point, I see that it got stuck trying to init SD card which is not present on the Nucleo board.
Have you put the correct project on github?

 

Rajesh Tripathi
Associate III

The code basically stays in Error_handler loop blinking RED LED.

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).

 

 

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.

Tried building the project
https://github.com/tjaekel/STM32U5xx_USB_ECM 

Default build completes without errors. Since I don't have U5A5 board yet, I tried building for U575 and undefined STM32U5A5xx from environment but that is not enough. Have not debugged further what else to change.

The README.md file should have details about how to build for U575 board without SD card.

BarryWhit
Senior

@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.

- If you feel a post has answered your question, please click "Accept as Solution".
- Once you've solved your issue, please consider posting a summary with any additional details you've learned. Your new knowledge may help others in the future.

FYI, you have to "toggle" these two defines:

STM32U575xx
XXX_STM32U5A5xx

One or the other active: add and remove the "XXX_".

It should work also on a STM32U575xx, just: this is just USB FS, the U5A has an USB HS (integrated PHY).