2024-01-22 10:33 PM - last edited on 2024-01-30 03:44 AM by SofLit
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:
No idea what to install on a Windows OS to make the device driver happy.
What works:
The MCU FW is not happy:
If I try on a MacOS:
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?
Solved! Go to Solution.
2024-02-15 12:09 AM
BTW: you have to do this "Ethernet tethering" all the time again on Android phone, after USB was disconnected, or the MCU board reset.
2024-02-15 01:01 PM - edited 2024-02-15 01:03 PM
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
However, the ping is still not working.
2024-02-15 04:29 PM
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).
2024-02-16 02:18 PM
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.
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?
2024-02-16 02:39 PM
The code basically stays in Error_handler loop blinking RED LED.
2024-02-16 04:20 PM
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).
2024-02-16 11:22 PM
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.
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.
2024-02-19 11:05 PM
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.
2024-06-26 10:16 AM - edited 2024-06-26 10:26 AM
@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.
2024-06-26 12:39 PM
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).