Skip to main content
Associate III
June 26, 2024
Question

USB-ECM Enumeration over USB for STM32L072

  • June 26, 2024
  • 6 replies
  • 5701 views

Using B-L072Z-LRWAN Board, I'm trying to Enumerate the USB Port as a Ethernet Adapter.(As Device not Host)

Thereby I integrated just the USB-ECM Stack provided by the STM32 itself.

I initially had issues with Driver, Post Following the Guide/Post from @tjaekel , i.e USB ECM demo - how to setup host?  I used Belcarra USBLAN Driver, Though it got installed and is shown under Network Adapter, I see a Warning Sign for it

Pavan_LohiaGroup_0-1719381415477.png

On Linux though, It gets identified as Android Tethering Device but doesn't show up on Wireshark nor Control Panel(Under Network).

 

So Below are my Issues:

  1. Is it Compulsory to Implement a Server Logic(LwIP, etc etc.) over the ECM Driver?
  2. Agenda of the Project is to USB Should be Enumerated as Ethernet Adapter on all OS Platforms, So Is ECM the Right Option?
  3. Can Someone Give me a Brief on, if I am to use ECM to achieve my agenda how and What are those Mandatory Components I need to include in the project.
  4. Keeping in mind the Board/Controller, STM32L072CZx, Wouldn't Implementing Server Logic use too much of memory? Just ECM Driver Integration alone uses 45.51% of RAM. As based on requirement we need RAM for other implementation too.

6 replies

Lead II
June 26, 2024

If you use the USB-ECM as provided as Azure demo - the USB descriptors have a small bug (something missing). The Belcarra Driver will not accept the USB-ECM because of it. You can find a fixed version on my GitHub:

GitHub - tjaekel/STM32U5xx_USB_ECM: NUCLEO-U575ZI-Q with USB ECM, without SD Card

There is a fix needed on the USB enumeration:

In file "ux_device_descriptors.c":


#define PATCH

#ifdef PATCH

 /* PATCH added */

 /* 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);

 /* end of PATCH */

#endif


#if 0

 /* Append ECM Communication 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,

 USBD_CDCECM_EPINCMD_HS_BINTERVAL,

 USBD_CDCECM_EPINCMD_FS_BINTERVAL);

#endif


 /* Append ECM Data class interface descriptor to Configuration descriptor */

#ifdef PATCH

 /* PATCH - change */

 __USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[1], 1U, 2U, 0x0AU, 0U, 0U, 0U);

#else

 __USBD_FRAMEWORK_SET_IF(pdev->tclasslist[pdev->classId].Ifs[1], 0U, 2U, 0x0AU, 0U, 0U, 0U);

#endif

 

Lead II
June 26, 2024

About your questions:
USB_ECM is great if you want to access MCU via network (e.g. using UDP sockets in a Python script or running a web server in MCU and access it from a host with web browser).

LwIP should work with USB_ECM. No idea how much RAM is needed. Why USB_ECM does use so much memory? Potentially for buffers, for USB and for network packets, Maybe possible to tweak (fewer and/or smaller buffers). Potentially, some stuff which could be const (e.g. USB enumeration) hold in SRAM (instead as const in ROM).

Yes, USB_ECM is the emulation of network traffic (Ethernet) via USB. It behaves like a network connected device and you can use the network adapter (virtual Ethernet) on host computer. If the USB_ECM host drivers will see properly the MCU with USB_ECM - there should be a virtual network adapter available (like an Ethernet interface).

At the end it depends on what you want to do: if you have just a USB FS (with USB_ECM) - a USB VCP UART might be an option. USB VCP UART does not need any driver as USB_ECM does not need one. USB_ECM via USB FS might be convenient to have it as a regular network connection, but potentially the throughput is not really fast.

BTW: without fixing the USB enumeration USB_ECM was working for me on Android and Linux systems (just Windows Belcarra needs the fix). It was also working running on Windows a Linux VM.

Lead II
June 26, 2024
Associate III
June 27, 2024

@tjaekel, Thanks for your response.

Please Correct if My understandings are wrong,

  • With no Network Stack such as LwIP, If we integrate just the USB-ECM, The Device Should get detected as Virtual Ethernet Port, Is my Understanding Correct?
  • My End Goal is, The Development Board should get Detected as a Ethernet Port on all OS Platforms so that I can read all the Data at an ISR in the format it sent over/Viewed on Wire shark.
  • USB-ECM as provided as Azure demo, Is this by any chance different from the the Middleware that STM32 Provides? i.e. stm32_mw_usb_device link.
Andrew Neil
Super User
June 27, 2024

@Pavan_LohiaGroup wrote:
  • With no Network Stack such as LwIP, If we integrate just the USB-ECM, The Device Should get detected as Virtual Ethernet Port, Is my Understanding Correct?

But the whole point of USB-ECM, surely, is to provide an IP network link - so what's the point of doing that and then not having an IP Stack ?

 


@Pavan_LohiaGroup wrote:
  • My End Goal is, The Development Board should get Detected as a Ethernet Port on all OS Platforms 

If the OS platforms see it as an Ethernet Port, they will expect to be sending IP to it - won't they?

So, again, that means your microcontroller will need to speak IP - ie, it will require an IP stack

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Super User
June 27, 2024

But the whole point of USB-ECM, surely, is to provide an IP network link - so what's the point of doing that and then not having an IP Stack ?

@Andrew Neil It is possible to use raw "ethernet" packets without IP stack. There were times before IP...

 

Andrew Neil
Super User
June 27, 2024

@Pavan_LohiaGroup wrote:

4. Keeping in mind the Board/Controller, STM32L072CZx, Wouldn't Implementing Server Logic use too much of memory? 


Yes, I would suspect that's going to be a big issue!

@tjaekel suggested using VCP instead - I think major OSs should still be able to recognise that as "dial-up" networking - with PPP, SLIP, or similar ... ?

 

Addendum:

Just received this in a mailshot from ST:

AndrewNeil_0-1719481658118.png

It's a dual-core Cortex-M4 + M0 with 256K Flash - so might be more suitable to your application:

https://www.st.com/en/microcontrollers-microprocessors/stm32wl5moc.html

It's based on the STM32WL5x:

https://www.st.com/en/microcontrollers-microprocessors/stm32wl5x.html

(Single-core, M4-only, versions are availale)

 

Addendum 2:

For a really tiny IP stack. maybe consider uIPhttps://dunkels.com/adam/software.html 

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
June 27, 2024

@Andrew Neiland @Pavel A. , Thanks for Taking time on this post.

 

To Answer a Few Points:

 > But @Pavan_LohiaGroup's objective seems to be to have this "just work" with the standard, built-in networking of "all OS Platforms" - not custom crafting raw packets ... ?

Yes, I would not fiddle or play around with the Incoming Data, I would like to Just Receive the RAW Ethernet Packets in its correct fragmentation/format.

i.e. I would like to just receive these Hex values (Captured from Wireshark),  as it is at every interrupt/packet.

Pavan_LohiaGroup_0-1719489466489.png

 

> Throughput is still going to be waaaaaaaaaaaay  faster than the LoRa radio! 

Yes, Your Understanding is right, I will just forward those packets that I receive (Raw Ethernet) to the LoRa Radio. Similarly I will Forward all the Data I receive from LoRa Radio to this Enumerated USB-ECM.

 

> @Andrew Neil It is possible to use raw "ethernet" packets without IP stack. There were times before IP...

The Pain Point I'm still facing is, Having just the Middle ware of USB-ECM isn't making my Dev. board get detected as either Virtual Ethernet nor as any Physical Ethernet Port under any OS. Or In other Words, Even if Right Drivers are installed too, They are either Disabled/Can't be used too.

 

> For a really tiny IP stack. maybe consider uIPhttps://dunkels.com/adam/software.html 

Thanks will give it a Shot soon and Update.

 

Again Thanks all for Responses and Guidance.

Andrew Neil
Super User
June 27, 2024

@Pavan_LohiaGroup wrote:

Yes, I would not fiddle or play around with the Incoming Data, I would like to Just Receive the RAW Ethernet Packets in its correct fragmentation/format..


But how will you get "all OS Platforms" to send such raw ethernet packets?

Surely, they will expect to have a TCP/IP conversation? Or UDP/IP at the least?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate III
June 27, 2024

Yes, There would be Conversation of Both TCP/IP and UDP/IP too.

So would both need a IP Stack? I understand if TCP/IP might probably need as It needs to Connect first before any Communication. But would it be needed even for UDP too, Shouldn't a Static IP assigned to Adapter be sufficient for it?

Pavel A.
Super User
June 27, 2024

 Having just the Middle ware of USB-ECM isn't making my Dev. board get detected as either Virtual Ethernet nor as any Physical Ethernet Port under any OS.

Correct, Windows for example will need a custom driver for CDC/ECM. Windows has in-box driver (usb8023.sys) only for RNDIS flavor of USB networking. But if you get a compatible driver for CDC/ECM, just answering correctly the USB descriptor requests should get the device recognized. No TCP/IP middleware is involved in this. On Linux more or less same. Install a compatible driver.

If you need more help with development or research on this project, here it can be found.

 

Associate III
June 27, 2024

As mentioned earlier, I tried using Belcarra USBLAN for ECM too. But for reasons unknown to me, it has some warnings and thereby not even shown in control panel > networking devices > adapters.

 

I indeed Tried RNDIS too, It partially works in Linux, Driver/Adapter is Disabled in windows, Details arementioned in this below post too.

usb-rndis-works-partially

Pavel A.
Super User
June 27, 2024

Looks like a bug in function descriptors. The Windows USBView isn't maintained well and cannot be trusted too much, prefer Linux tools. See the link in my reply above.

Pavel A.
Super User
June 27, 2024

So would both need a IP Stack? I understand if TCP/IP might probably need as It needs to Connect first before any Communication.

Wait a second... If your device will just passively move raw ethernet packets from host to the "LoRA radio" (translate ethernet to PPP or SLIP?) the latter will handle TCP or UDP connection, and your device does not need IP stack. If your device must do translation from TCP/UDP on behalf of the "radio", it's a different story.

Associate III
June 28, 2024

@Pavel A., Would it be possible to brief a little more on Ethernet to PPP or SLIP.

As You have understood, I just need to Passively move the raw ethernet packets from host to LoRa radio, I shall not modify interpret or do anything with raw Ethernet data.