2026-01-06 9:42 AM - last edited on 2026-01-07 3:45 AM by mƎALLEm
Hello everyone,
I’m looking for some help getting an Ethernet TCP server running using LwIP with FreeRTOS on an STM32.
Current status:
Hardware: NUCLEO-H723ZG
Stack: LwIP + FreeRTOS
TCP client/monitor: Hercules v3.2.8
I can ping the board successfully every time (with Windows terminal and Hercules)
However, I cannot establish a TCP connection when FreeRTOS is enabled
What’s confusing me is that:
If I disable FreeRTOS, I can successfully establish a TCP connection using the CubeMX example LwIP_TCP_Echo_Server
Once FreeRTOS is enabled, the TCP connection attempt from Hercules fails (no connection established)
What I’ve tried so far:
Multiple CubeMX LwIP + FreeRTOS example configurations
Both Netconn and Socket-style APIs
Adjusting task priorities and stack sizes
Verifying IP address, subnet, gateway, and port settings
Confirmed Ethernet link is up and LwIP responds to ping
At this point, it feels like I’m missing something fundamental about:
LwIP threading model with FreeRTOS
Proper placement of TCP server code (tcpip thread vs user task)
FreeRTOS task priorities or blocking behavior affecting LwIP
I’m still fairly new to STM32 development and the STM32Cube/HAL/LwIP ecosystem, so any guidance or common pitfalls would be greatly appreciated.
I can provide:
CubeMX configuration screenshots
Relevant code snippets
Hercules configuration screenshots
Thanks in advance for any help or direction you can provide!
Solved! Go to Solution.
2026-01-14 2:44 AM
Hello @THommer, and thank you for your patience!
After reviewing the project and making the following modifications, I was able to get it to work:
Ping and TCP server work as expected. The modifications are added to the USER_CODE sections, so you can add other features using STM32CubeMX, generate the project, and it won't affect the Ethernet functionality.
Best regards,
2026-01-12 7:14 AM
Hello @THommer, and welcome to ST community!
Could you please provide the following information to assist with troubleshooting:
I look forward to your response.
Best regards,
2026-01-12 2:20 PM
Hello @STackPointer64,
Thank you for the response and for helping me troubleshoot this. Below is the requested information:
1. STM32CubeMX configuration
attached is the .ioc file for one of the projects I am currently using to attempt a FreeRTOS + LwIP TCP echo server on the NUCLEO-H723ZG. This project is based on a ControllersTech Ethernet tutorial that I modified for this board. I have attempted other configurations, including:
All exhibit similar behavior (ping works, TCP connection does not).
2. Hercules configuration
Below is a screenshot of my Hercules TCP client configuration and the messages shown when attempting to connect.
This same error (or similar) appears across different Free + LwIP projects I've tested. For reference, below is what I get when I use the LwIP_TCP_Echo_Server (no FreeRTOS) example from the CubeMX example selector for the NUCLEO-H723:
3. TCP server / port confirmation
Yes, the TCP server application is implemented on the STM32 side. I have confirmed that the port used by Hercules matches the server port. Example from the code:
err = netconn_bind(conn, IP_ADDR_ANY, 7);4. Hard fault behavior
I have only encountered a hard fault once, in one specific example. At the time, I believe it was related to incorrect memory allocation. I am not currently seeing a hard fault in the attached project.
5. LwIP memory allocation
I have experimented with different heap sizes for LwIP, ranging from 10KB to 64KB. Non of these changes resolved the TCP connection issue when FreeRTOS is enabled.
6. MPU / cache configuration
I have tried multiple MPU configurations based on CubeMX defaults, forum recommendations, and example projects. At this point, I am not confident that my MPU configuration is correct, especially with respect to Ethernet DMA descriptors and cacheability, as this is an area I am still learning.
Please let me know if there is any additional information or a specific configuration you would loke me to focus on. I appreciate your time and guidance.
Best regards,
2026-01-14 2:44 AM
Hello @THommer, and thank you for your patience!
After reviewing the project and making the following modifications, I was able to get it to work:
Ping and TCP server work as expected. The modifications are added to the USER_CODE sections, so you can add other features using STM32CubeMX, generate the project, and it won't affect the Ethernet functionality.
Best regards,
2026-01-14 6:50 AM
Hello @STackPointer64,
Thank you very much for taking the time to review the project and for providing a corrected version that you were able to confirm as working, I really appreciate the detailed feedback.
I tested the updated project on my end, but unfortunately I am still unable to establish a TCP connection. Below is a screenshot of my latest connection attempt from Hercules:
Reviewing the changes you made:
I have previously tested configurations with the Ethernet global interrupt enabled, though it appears I may have missed enabling it in the specific project I originally sent you.
I have also experimented with similar MPU and LwIP memory configurations, including placing descriptors and buffers in SRAM and aligning linker sections accordingly.
One difference I noticed is the heap size — I had been testing a range of values, but not the specific 16*1024-20 Byte(s) configuration used in your example.
At this point, since the same project works on your side, I’m starting to suspect there may be an environmental or hardware-related factor on my setup rather than a pure software issue.
A couple of additional observations that may or may not be relevant:
I am currently connecting from my PC using a USB 2.0 Type-A to RJ45 Ethernet adapter, as my onboard Ethernet port is occupied.
During testing, the STM32H723 MCU becomes noticeably warm to the touch, which made me wonder whether the device may be under heavy load or stuck in an unintended loop. I’m not sure whether this level of temperature rise is expected for the H7 during Ethernet operation.
Please let me know if there are any specific runtime checks, debug points, or hardware-related items you would recommend verifying next. I’m happy to provide additional screenshots, debugger information, or test results if helpful.
Thanks again for your help, this has already been very informative.
Best regards,
2026-01-14 6:55 AM
I have changed the network configuration so that it becomes discoverable on my network. You should make the corresponding changes in the lwip.c file.
2026-01-14 12:44 PM
Thank you for pointing out the network configuration change, I initially missed that. After updating the IP configuration to match my local network, I retested the project.
At first, the board stopped responding to ping when configured with 192.168.0.100, and my PC reported the address as being outside the local network range. I have previously been able to ping this address reliably, but after changing the IP to one within my current local subnet, ping started working again.
With the corrected IP:
Ping works reliably
TCP connection on port 7 still does not establish
Out of curiosity, I changed the server port to 80, and in that case I am able to establish a TCP connection successfully. However, the connection only remains open for about 1–2 minutes before it is forcefully closed.
Below are screenshots showing:
The failed connection attempt on port 7
The successful connection on port 80 (before it eventually disconnects)
At this point, it seems like:
Network configuration is now correct
The TCP server is reachable
There may be something port-related, timing-related, or task/stack-related affecting the connection stability
Please let me know what you’d recommend checking next. I’m happy to provide any additional runtime information or test other configurations if needed.
2026-01-14 1:57 PM
Just wanted to follow up and close the loop on this.
After adjusting my PC’s Network & Internet settings as you recommended and ensuring both the PC and the board were on the same subnet, I was able to get my desired static IP address working (192.168.0.100) on port 7. The TCP server now connects reliably, and ping and data exchange are working as expected.
Below is a screenshot showing the successful connection and data exchange in Hercules:
Thank you for the guidance, this ended up being a network configuration issue on the host side rather than a problem with the STM32/LwIP configuration.
2026-01-15 1:20 AM
I am glad you managed to make it work. I’m happy that I could help.