2025-06-02 9:58 PM - edited 2025-06-02 10:00 PM
Hi everyone,
I faced a frustrating issue with lwip_connect() hanging forever when trying to use an STM32 as a TCP client (FreeRTOS V1 + LWIP stack).
Calling lwip_connect() inside my STM32 TCP client code caused the system to hang indefinitely.
It was getting stuck at this internal LWIP line:
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
This only happens when the TCP/IP stack is waiting for the connection to complete, and never gets a response.
- I could ping the server (PC) from STM32 successfully.
- My STM32 TCP server mode worked perfectly.
- But when STM32 tried to connect to Hercules TCP server on port 503 — it hung forever.
- LWIP debug logs showed that:
- tcp_connect() was called
- But the TCP state machine never moved forward
- The stack kept calling tcp_slowtmr: polling application
lwip_socket(PF_INET, SOCK_STREAM, 0) = 0
lwip_connect(0, addr=192.168.1.1 port=503)
tcp_connect to port 503
tcp_slowtmr: processing active pcb
tcp_slowtmr: polling application
(repeats forever)
Thanks in advance for your guidance and suggestions!
Solved! Go to Solution.
2025-06-15 11:57 PM
Hii Guys!
Im happy to inform you, that my issue got resoved by just turning off the my PC's firewall.
Ping worked because ICMP was allowed.
But Windows Firewall was silently dropping the TCP SYN from your STM32.
As a result, lwip_connect() hung waiting for a SYN-ACK that never came.
Turning off Windows Public Firewall allowed Hercules to receive the SYN and reply — connection succeeds!
2025-06-02 10:23 PM
This is one of the many known bugs of FreeRTOS + LwIP, and more bugs you can find browsing old messages.
STM recently published a slide showing support for various OS vs processors: H7 is still indicated as a TreadX+NetX , FreeRTOS+ (new ) is for some newer processors, that means that no bug fixing (or porting to FreeRTOS+) will be done for H7 on FreeRTOS in short period - at least is waht I can understand after receiving contradictory info in meeting with STM officials.
Browsing old post, you can find also workaround, but this solution remain basically flawed and unsupported.
2025-06-02 10:54 PM
@mbarg.1 Thanks for the quick response!
Do you suggest I stop using FreeRTOS? I've become quite comfortable with it, and switching to a different OS would be a bit challenging at this point.
By the way, I recently came across an ST post mentioning that ST plans to start providing official support for FreeRTOS (or something along those lines).
Anyway, I also tested the same configuration on the STM32F746 Nucleo Board — both the server and client setups are working seamlessly there
2025-06-15 11:57 PM
Hii Guys!
Im happy to inform you, that my issue got resoved by just turning off the my PC's firewall.
Ping worked because ICMP was allowed.
But Windows Firewall was silently dropping the TCP SYN from your STM32.
As a result, lwip_connect() hung waiting for a SYN-ACK that never came.
Turning off Windows Public Firewall allowed Hercules to receive the SYN and reply — connection succeeds!