Some time ago, our project initially used a 100 Mbps network communication setup with LWIP. At the beginning, we tried to port it based on the atomic routine. However, since the atomic routine was using LAN8720, we had to switch to DP83848. This required changing the register addresses and definitions. We also modified the speed calculation formula, but after several days of trying, it still didn’t work. Eventually, I followed some online advice and decided to modify the official ST routine instead. After a few more days of work, everything finally worked. Now, I’d like to share the steps I took so that others can benefit from my experience.
In my actual project, we ended up using DP83848, which turned out to be the most suitable option. This article isn’t about porting LWIP itself, but rather about adapting the official ST routines to fit our specific needs. This approach is especially helpful for those who are new to LWIP and want to quickly get their projects up and running without needing to understand the inner workings of LWIP in detail.
My project configuration: STM32F407VET6 + DP83848C
1. Download the official STSW-STM32070 package from the ST website at http://www.st.com. It includes the English document DM00036052.pdf and the demo code package stsw-stm32070.zip. The package is for the LwIP TCP/IP protocol stack on STM32F4x7 microcontrollers. Instead of transplanting LWIP from scratch, modifying this demo code is much easier and faster.
2. Extract the stsw-stm32070.zip file to get the folder STM32F4x7_ETH_LwIP_V1.1.0. Here’s the folder structure:
[Image: STM32F407-DP83848-Lwip transplantation method]
3. Delete the _htmresc folder, as it contains logos from ST and CMSIS, which are not needed for our project.
4. Open the project folder. Inside, there are two folders: FreeRTOS and Standalone. The FreeRTOS folder contains examples based on LWIP with FreeRTOS, which we don’t need to delete. In the Standalone folder, there are examples without an operating system. Since we only need basic data transfer (UDP), we keep only the udp_echo_client folder and remove all other folders. Within udp_echo_client, there are folders for different IDEs like EWARM and MDK-ARM. We choose the MDK-ARM project, while the IAR project can be kept or deleted. The RIDE folder is for another compiler and can be safely removed.
5. In the Utilities > Third_Party folder, there are three subfolders: FatFs_vR0, FreeRTOSV7.3, and lwip-1.4.1. FatFs_vR0 is for FAT file systems, and FreeRTOSV7.3 is for an embedded OS kernel. These are not needed here, so we delete them. The lwip-1.4.1 folder contains the LWIP source code, which is exactly what we need.
6. Open the MDK project in the MDK-ARM folder. Compile it first; you should see zero errors and three warnings. Two of the warnings are about unused variables, which we can ignore. The third warning is related to the file ethernetif.c in the lwip-1.4.1 folder. The warning says: “last line of file ends without a newline.†To fix this, add a newline at the end of the file.
7. Open main.h. Since we are using the RMII interface on the board, comment out `#define MII_MODE` and uncomment `#define RMII_MODE`. Also, note that the RMII clock should be 50MHz, and a 50MHz active crystal oscillator can be directly soldered onto the board.
[Image: RMII Mode Configuration]
Additionally, if you’re using a static IP address, make sure to disable DHCP by commenting out `// #define USE_DHCP`, as dynamic IP assignment may fail otherwise.
[Image: DHCP Configuration]
Since we have deleted the SERIAL_DEBUG feature, we can also remove the serial_debug.c file from the project.
[Image: Deleting serial_debug.c]
In the stm324x7i_eval.c and stm324x7i_eval_lcd.c files, delete the references to STM324xG_EVAL. Also, remove the startup_stm32f427x.s file from the MDK_ARM project. Delete the project target named STM324x7I_EVAL. After these changes, the compiler might throw errors. To fix this, remove any header files related to LCD functions from the stm32f4x7_eth_bsp.h file.
[Image: Removing LCD-related headers]
Once these adjustments are made, your project should compile successfully and be ready for further development.
Mianyang Ouxun Information Industry Co., Ltd , https://www.ouxunantenna.com