Networking issues for LwIP/FreeRTOS code generated via STM32CubeMX [NUCLEO-F746ZG]
- January 9, 2019
- 4 replies
- 3631 views
After a few somewhat fruitless attempts to run Ethernet error-free on the H7 development board, I have decided to switch back to the somewhat more established F7 series (which I am a bit more familiar with). Nonetheless, I am still experiencing some weird Ethernet connectivity behavior from the code generated via STM32CubeMX. The LwIP_HTTP_Server_Netconn_RTOS example from STM32Cube_FW_F7_V1.14.0 works just fine. The operation of LwIP_HTTP_Server_Netconn_RTOS is stable and I can send HTTP GET commands to the development board at a rapid pace. Essentially, I can send them every few milliseconds, and the devboard transmits a proper response without any unnecessary lag.
If I try to recreate the same conditions using STM32CubeMX I begin to experience periodic lag. The continuous stream of HTTP GET commands is actually sent as a burst after which the devboard seemingly crashes and I am kept waiting for a timeout. After a small halt, this communication is reestablished once again and I can send another burst of messages. If I inspect the Ethernet traffic, I can see that each crash is followed by a bunch of TCP Retransmission, TCP Previous segment not captured or TCP Dup ACK errors:
As I've mentioned before, the LwIP_HTTP_Server_Netconn_RTOS example does not behave in this kind of segmented fashion - I can continuously send and receive TCP packets to/from the board.
The code in STMCubeMX was generated in the following way:
- In the RCC tab HSE was set to Crystal/Ceramic Resonator (8 MHz) and the HCLK was set to 216 MHz in the Clock Configuration window.
- SYS timebase source was set to TIM6.
- Ethernet (RMII) was enabled in Connectivity->ETH.
- PHY address was set to 0.
- Pins PG13 and PG11 were set to, accordingly, ETH_TXD0 and ETH_TX_EN.
- FreeRTOS was enabled with all the default settings.
- LwIP was enable with all the default settings.
- Code was generated for SW4STM32.
To get some response out of the device, I’ve copied the httpserver-netconn.h and httpserver-netconn.c files and added them to my project. Since I’m only interested in very basic connectivity, I’ve commented out most of the code there (see the attached files), leaving the http server responsive only to the “GET /STM32F7xx_files/logo.jpg�? command. The http_server_netconn_init(); function was added to the StartDefaultTask thread.
A couple of things to note:
- I think that a similar issue has been reported earlier: https://community.st.com/s/question/0D50X00009XkYKOSA3/problem-with-slow-response-from-lwip-to-incoming-data-on-stm32f7 but this particular solution did not improve the behavior of my code.
- The LwIP_HTTP_Server_Netconn_RTOS example enables ICache, DCache, and MPU (also it uses a dedicated linker script for RAM reallocation). The above-described code doesn’t. I’ve tried to implement these features into the CubeMX-generated code, albeit they did not seem to fix the issue.
- The LwIP/FreeRTOS parameters in the LwIP_HTTP_Server_Netconn_RTOS example are (most likely) fine-tuned. I’ve looked through the lwiopts.h and FreeRTOSConfig.h files to determine the discrepancies between the CubeMX-generated code and the properly working example. I tried to set a good portion of them to match (the attached project does not implement these changes), but this did not improve the Ethernet behavior. The lwiopts.h and FreeRTOSConfig.h in the LwIP_HTTP_Server_Netconn_RTOS example are somewhat messy – they seem to be generated manually (since their structure is much different from the code generated via CubeMX), therefore it can be rather hard to track all the differences.
Now I realize that it is possible just to write my own code using the LwIP_HTTP_Server_Netconn_RTOS example as a basis. Nonetheless, this kind of approach lacks the functionality provided by CubeMX. So my questions are:
- Why is the LwIP_HTTP_Server_Netconn_RTOS example running properly, whereas an equivalent code generated via CubeMX is buggy?
- What LwIP/FreeRTOS/system parameters need to be changed to run Ethernet properly (i.e., without the windows of lag and/or TCP errors)?
I guess my end goal is to be able to generate a networking example using CubeMX that works just as well as the LwIP_HTTP_Server_Netconn_RTOS example.
