STM32F767 LwIP TCP Client
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-28 5:47 PM
Hello,
I'm facing some weird problem that I can't solve myself. I'm trying to get to work a TCP client using LwIP.
Now the weird part:
Everything works just fine in debug mode when I run the program. Connection is being established, and communication works as intended. But when I run the program without debug mode, I get ERR_RTE error.
I searched the internet and couldn't find an answer to my problem.
I suppose the code is fine due to the fact it works in debug mode.
Program generates error in tcp_connect function at netif = ip_route part.
Here is the code:
uint8_t TCP_ClientInit()
{
struct tcp_pcb *tpcb = {0};
err_t res = 0;
tpcb = tcp_new();
if(tpcb != 0) {
ip_addr_t sourceIPAddr;
IP_ADDR4(&sourceIPAddr, 192, 168, 0, 111);
res = tcp_bind(tpcb, &sourceIPAddr, 1500);
ip_addr_t destIPADDR;
IP_ADDR4(&destIPADDR, 192, 168, 0, 15);
res = tcp_connect(tpcb, &destIPADDR, 1400, tcp_client_connected); // this returns error ERR_RTE
}
else {
return HAL_ERROR;
}
if(res == ERR_OK) {
return HAL_OK;
}
return HAL_ERROR;
}
err_t tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
tcp_connected_fn connected)
{
struct netif *netif = NULL;
err_t ret;
u32_t iss;
u16_t old_local_port;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("tcp_connect: invalid pcb", pcb != NULL, return ERR_ARG);
LWIP_ERROR("tcp_connect: invalid ipaddr", ipaddr != NULL, return ERR_ARG);
LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
ip_addr_set(&pcb->remote_ip, ipaddr);
pcb->remote_port = port;
if (pcb->netif_idx != NETIF_NO_INDEX) {
netif = netif_get_by_index(pcb->netif_idx);
} else {
/* check if we have a route to the remote host */
netif = ip_route(&pcb->local_ip, &pcb->remote_ip); // ### this returns NULL
}
if (netif == NULL) {
/* Don't even try to send a SYN packet if we have no route since that will fail. */
return ERR_RTE;
}
Solved! Go to Solution.
- Labels:
-
LwIP
-
STM32F7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-02 11:57 PM
Hello @DziadGarbaty ,
Please take a look at this post: Solved: Basic UDP Echo server works in debug, but not run ... - STMicroelectronics Community. You might be experiencing a similar issue.
With Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-01 2:12 AM
@DziadGarbaty wrote:Everything works just fine in debug mode when I run the program. Connection is being established, and communication works as intended. But when I run the program without debug mode, I get ERR_RTE error.
Instrument your code so that you can see what's happening with & without the debugger.
Are you using a standard ST example?
For LwIP diagnostic messages, see:
More on STM32H7 and LwIP:
Have you looked-up what this "ERR_RTE error" actually means? Where, exactly, does it occur?
@DziadGarbaty wrote:Here is the code:
Your code has lost all indentation - please see How to insert source code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-02 11:57 PM
Hello @DziadGarbaty ,
Please take a look at this post: Solved: Basic UDP Echo server works in debug, but not run ... - STMicroelectronics Community. You might be experiencing a similar issue.
With Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-03 2:59 PM
Thank you, @ASEHST
Indeed adding HAL_Delay after clock initialisation solved the problem. Program starts most of the time so perhaps I need to adjust the delay value.
Interesting problem, I never would have thought the solution would be so simple!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-04 12:20 AM
@DziadGarbaty wrote:perhaps I need to adjust the delay value.
Better, look at what it is that is needing time to "stabilise" and, instead of an arbitrary delay, test for that condition...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-03-26 5:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-01 7:28 AM
"ERR_RTE" means "routing error". There's no interface for the IP packet you want to send.
But in that case I think it is because there's no interface at all.
This may be caused by the time taken by autonegotiation between the board's PHY and the ethernet switch.
Normally, the examples provided by ST do a polling on the PHY registers to wait until the PHY says it is connected. No need for delay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-01 7:43 AM
@Guillaume K wrote:Normally, the examples provided by ST do a polling on the PHY registers to wait until the PHY says it is connected. No need for delay.
But @DziadGarbaty (this thread), and @Hey0256 and @KMill (the older threads) did all find a delay to be necessary
