cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 + LWIP + FreeRTOS: lwip_connect() Hangs Forever – TCP Client Issue

jumman_JHINGA
Senior III

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).

 

🧠 Problem Summary

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.

🧪 Observations

- 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 Debug Logs

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!

1 ACCEPTED SOLUTION

Accepted Solutions
jumman_JHINGA
Senior III

Hii Guys!

Im happy to inform you, that my issue got resoved by just turning off the my PC's firewall. 

My Final Diagnosis:

  • 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!

View solution in original post

3 REPLIES 3
mbarg.1
Senior III

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.

jumman_JHINGA
Senior III

@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

jumman_JHINGA
Senior III

Hii Guys!

Im happy to inform you, that my issue got resoved by just turning off the my PC's firewall. 

My Final Diagnosis:

  • 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!