cancel
Showing results for 
Search instead for 
Did you mean: 

USB-ECM Enumeration over USB for STM32L072

Pavan_LohiaGroup
Associate III

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.
26 REPLIES 26
tjaekel
Lead

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

 

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.

Pavan_LohiaGroup
Associate III

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

@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

Andrew Neil
Evangelist III

@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 

 


@tjaekel wrote:

USB_ECM via USB FS might be convenient to have it as a regular network connection, but potentially the throughput is not really fast.


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

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

 


@Pavel A. wrote:

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


👍

I guess!

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

🤔