1. Introduction
The previous article “Unlocking the Potential of LwIP: Easily Implementing Multi-NIC for MCU” mainly introduced how to utilize the high-speed USB 2.0 480Mbps interface of the Xianji Semiconductor high-performance MCU as a USB Host to connect USB 4G modules or USB network cards, and combined with the Ethernet PHY interface to achieve multi-NIC functionality.
This article further expands on that foundation, primarily introducing how to configure the high-speed USB interface of the Xianji MCU as a USB Device mode to implement RNDIS (Remote NDIS) device functionality. Through this functionality, the MCU can simulate a standard Ethernet card via the USB interface, establishing an efficient network communication channel with the host.
Of course, the source code for hpm’s usbnic_eth_multi_net_lwip will also be open-sourced, and the repository address is:
https://github.com/RCSN/hpm_sdk_extra
The path is demos/usb_device_rndis_eth_multi
Using the HPM6E00evk, connect the USB0 port to the PC with a data cable, and the effect is as follows:
The RNDIS device appears in the PC’s device manager


For Xianji MCUs equipped with a physical Ethernet interface (such as HPM6800, HPM6P00, HPM6300, etc.), the RNDIS functionality provides a flexible network expansion method. When the physical network port is already used to connect to routers or switches, direct communication with the PC can be achieved through the USB RNDIS interface, providing a convenient channel for data transmission.
For Xianji MCUs without a physical network port (such as HPM6200, HPM5300, etc.), using USB to implement RNDIS is an ideal solution to obtain complete network communication capabilities without additional hardware. This not only simplifies hardware design but also significantly enhances system integration and product design flexibility.
In summary, whether the Xianji MCU has a network port or not, implementing RNDIS functionality via USB can effectively expand its network connectivity options, greatly enhancing the adaptability of product application scenarios and providing high practical value.
For Xianji MCUs without a physical network port (such as HPM6200, HPM5300, etc.), you can directly refer to the rndis example in the hpm sdk under samples/cherryusb/device.
2. Porting Process
The CherryUSB section is discussed extensively in this article; those interested can refer to the article “Not Enough USB Endpoints? Not a Problem! Full-Blooded USB Endpoints MCU to Assist You!” which will not be elaborated here.
In the Xianji HPM SDK, there are rich examples for the USB device RNDIS, including bare metal and RTOS, as well as examples for HTTP, TCP, UDP, etc. This article references the http_server_freertos sample.

(1) Implementation of USB Device RNDIS Driver
In the CherryUSB protocol stack, there is already a RNDIS class driver under the device section, mainly implementing:
1. RNDIS Message Protocol Interface.
The message protocol is roughly divided into control messages and data messages. Control messages are mainly used for the host to send relevant controls to the NDIS device, such as initializing the network connection REMOTE_NDIS_INITIALIZE_MSG; data messages are mainly used for sending and receiving TCP/IP protocols. As follows:

For the API implementation: you can see some control messages that CherryUSB has basically implemented.

2. Network Data Encapsulation and Transmission via CDC RNDIS Class
Users can directly use these encapsulation APIs for network send and receive operations, mainly the usbd_rndis_eth_rx and usbd_rndis_eth_tx APIs. For example, how the receive function passes USB data to the network stack, and how the send function retrieves data from the network stack and sends it via USB.
For the usbd_rndis_eth_rx API, it is used to receive data from USB and encapsulate it into the LWIP pbuf structure. At the beginning of the function, it checks if there is data to read; if not, it returns NULL.

For the usbd_rndis_eth_tx API, it is responsible for sending LWIP pbuf data. It first checks the connection status and busy status; if disconnected or busy, it returns an error.

3. USB Interface Initialization
Mainly implements USB interface parameter initialization, facilitating user initialization of the USB device to add an interface. The API is: usbd_rndis_init_intf.
The RNDIS device uses CDC and requires the configuration of three endpoints: bulk in, bulk out, and init. Additionally, it configures the interface handling function, mainly to handle the aforementioned RNDIS message protocol.

(2) Implementation of RNDIS Descriptor
Refer to previous articles and the descriptor section of the device RNDIS example in the HPM SDK, mainly implementing:
Device Descriptor, Configuration Descriptor (including Interface Descriptor and Endpoint Descriptor), String Descriptor, etc.
(3) RNDIS Device Initialization
Mainly implements the registration of RNDIS descriptors and interfaces, as well as the initialization of the CherryUSB protocol stack’s hardware layer and protocol stack.

(4) LwIP Integration
It is necessary to implement the netif network interface integration for the device RNDIS device, requiring the definition of a netif network interface variable to store the network device. The HPM SDK’s RNDIS device conveniently includes a DHCP server, allowing for automatic dynamic IP allocation. This part can refer to the source code, and will not be elaborated here.



Create a thread mainly for USB device initialization and DHCP server initialization (the LwIP initialization part has already been initialized in main). In the thread loop, when the USB interface is detected, the data packets are passed to LwIP’s input processing.

(5) Multi-NIC Integration
In conjunction with the previous article, initialize and distinguish multiple network cards. Enable DHCP, and you can see the IPs of the two network cards.


3. Conclusion
This article further explores the network expansion capabilities of the Xianji high-performance MCU based on the previous article “Unlocking the Potential of LwIP: Easily Implementing Multi-NIC for MCU”, focusing on how to configure its high-speed USB 2.0 interface (480Mbps) as USB Device mode and implement RNDIS network device functionality based on the CherryUSB protocol stack.