Some time ago, the project originally used a 100 Mbps network communication with LWIP. At the beginning, we tried to transplant it based on the atomic routine. Since the atomic routine used LAN8720, we had to switch to DP83848, which required changing the register addresses and definitions. We also adjusted the speed calculation formula, but after several days of effort, it still didn’t work. Finally, following advice from online forums, I decided to modify the official ST routine instead. After a few more days of work, everything finally worked. Now I want to share the steps I took so that others can benefit from my experience.
I believe that in actual projects, using DP83848 is still the most common choice. This article isn't about transplanting LWIP itself, but rather modifying the official ST routines to suit our own project needs. This approach is especially suitable for those who are new to LWIP and want to start working on their own projects without needing to deeply understand the internal workings of LWIP. It's all about using what’s already there and adapting it to your requirements.
My project configuration includes STM32F407VET6 + DP83848C.
Here are the steps I followed:
1. Download the official STSW-STM32070 package from the website: http://www.st.com. This includes the English document DM00036052.pdf and the demo code zip file stsw-stm32070.zip. The demo code is for the LwIP TCP/IP protocol stack on the STM32F4x7 microcontroller. Instead of trying to transplant LWIP from scratch, it's much easier to modify this existing demo code for our purposes. The PDF provides detailed documentation for the demo code.
2. Extract the contents of stsw-stm32070.zip to get the STM32F4x7_ETH_LwIP_V1.1.0 folder. This folder contains the structure of the demo project.
3. Delete the _htmresc folder, as it contains ST and CMSIS logos that aren’t needed for our project.
4. Open the project folder, which contains two subfolders: FreeRTOS and Standalone. The FreeRTOS folder contains examples based on the LWIP port for FreeRTOS, which we don’t need. In the Standalone folder, there are several examples for LWIP without an OS. Since we only need normal data transfer, we keep the udp_echo_client folder and delete the rest. Inside the udp_echo_client folder, you’ll find projects for IAR EWARM (EWARM) and Keil MDK (MDK-ARM). We use the MDK version, 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 folder, there are three subfolders: FatFs_vR0, FreeRTOSV7.3, and lwip-1.4.1. FatFs_vR0 is a file system module, and FreeRTOSV7.3 is a small RTOS 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 and compile it. 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 that the last line of the file doesn’t end with a newline. To fix this, add a new line at the end of the file, and the warning will disappear.
7. Open main.h. Since we’re using the RMII interface on the board, comment out `#define MII_MOD` and uncomment `#define RMII_MODE`. Also, note that the RMII clock should be 50MHz, and a 50MHz crystal oscillator can be directly soldered onto the board.
8. Remove the `// #define USE_DHCP` comment if you want to enable dynamic IP address allocation. If you're using a static IP, make sure the configuration is correct.
9. Since we’ve disabled serial debugging, remove the `serial_debug.c` file from the project. Click the red cross to delete it and confirm with OK.
10. In the files stm324x7i_eval.c and stm324x7i_eval_lcd.c, remove references to STM324xG_EVAL. Also, delete the startup_stm32f427x.s file from the MDK project. In the Project Targets section, remove the STM324x7I_EVAL entry. Additionally, delete any LCD-related functions in the header file stm32f4x7_eth_bsp.h to avoid compilation errors.
This process helped me successfully adapt the official ST example to work with DP83848, making it easier to proceed with my own project. I hope this guide helps others who are facing similar challenges with LWIP and Ethernet drivers on STM32.
Gy06 Military Green Ultra Wave Cleaner,Military Green Receiving Antenna,Military Green Terminal Antenna Plastic Antenna
Mianyang Ouxun Information Industry Co., Ltd , https://www.ouxunantenna.com