Enabling Network Connectivity on a Development Board: Detailed Analysis of RT-Thread CherryUSB RNDIS Driver | Technical Gathering
This document describes the process of enabling network connectivity on a development board by utilizing the CherryUSB package as the USB Host stack in RT-Thread, to drive the AIR780E 4G Cat.1 module’s RNDIS functionality, and integrating it with the lwIP network stack. The implementation uses the STM32F429 as a reference platform.
1. Creating a New Project
2. Configuring CubeMX
The standard peripheral configuration is here.
Enable USB HOST
Enable USB HOST Interrupt
After completing the above, generate the project and close CubeMX.
3. Configuring CherryUSB
Compile the project initially.
An error will occur.Solution: remove RT_WEAK and recompile. The error will no longer appear.
Next, open RT-Thread Settings, add the CherryUSB package, and configure it.
In fact, only enabling RNDIS (without enabling CDC ACM) is sufficient to drive AIR780 to achieve lwIP networking, but the terminal will show a large number of red prompts saying CDC ACM is not supported. For neatness, enable it as well.
At this point, save and compile. Many errors will appear, but do not panic. Solve them one by one:
(1) usb_config.h Error
Solution: create a file usb_config.h under the applications folder with the following content:
#ifndef CHERRYUSB_CONFIG_H #define CHERRYUSB_CONFIG_H … #endif
Recompile. The number of errors will be significantly reduced.
(2) RT_TIMER_THREAD_STACK_SIZE Issue
Solution: increase the stack size.
It is also necessary to enlarge the idle thread stack.
(3) lwIP Version Incompatibility
Solution: use lwIP version 2.1.2.
(4) lwIP Receive Thread Issue
Solution: disable the lwIP receive thread.
(5) lwIP Thread Stack Size
Solution: increase the lwIP thread stack size.
(6) Linker Script Issue
Solution: add the following code to the linker script:
/* section information for USB Host class (CherryUSB) */ . = ALIGN(4); __usbh_class_info_start__ = .; KEEP(*(.usbh_class_info)) __usbh_class_info_end__ = .;
Recompile. No further errors should occur.
4. Modifying main.c
Insert the following code:
#include <rtthread.h>#define DBG_TAG “main”#define DBG_LVL DBG_LOG #include <rtdbg.h>#include <stm32f429xx.h>#include “usbh_core.h”#include “lwip/tcpip.h”int main(void) { usbh_initialize(0, USB_OTG_HS_PERIPH_BASE); return RT_EOK; }
5. Verification
Flash the firmware to the development board.
Upon startup, terminal output will indicate successful initialization.By issuing the ping command, the board will respond, confirming that network connectivity over the 4G module has been successfully established.
