Skip to main content
April 1, 2021
Solved

STM32f429IGT6+STM32cubemx+lwip+httpd+freertos sometimes not working

  • April 1, 2021
  • 3 replies
  • 1014 views

Hello,

Here I have a nearly advanced problem in my view, maybe as easy as ABC on your side. I have been able to work with STM32f429IGT6+STM32cubemx+lwip+httpd+freertos.

But there is a problem. Unlike the USB-CDC module which can enumerate and identify the connection in the middle of runtime, the LWIP framework with the default configuration of stm32cube code generator can't enumerates and identify if the cable is connected in the middle of runtime. But it can detect and work completely if it has been connected before reset.

How should I change my code to achieve this goal? So far I had read that someone had the same problem and solved it, but couldn't find that question again on the web.

This topic has been closed for replies.
Best answer by Vangelis Fortounas

hello.

>> Should I only define it in the main file so that a weak definition becomes strong =) which means it is a recursively called function that remained to be defined by the user?

Yes !

just define it (copy from here). is already declared and (defined as weak

it will be called from ethernetif_set_link (the link thread "LinkThr" ) if ethernet link is changed (cable status).

3 replies

Vangelis Fortounas
Associate II
April 2, 2021

Hello

The below code is an approach to solve the mentioned issue. Try to understand how it works and use it if fits to your needs.

ethernetif_notify_conn_changed is already defined as weak so just link the code.

//##############################################################################
void ethernetif_notify_conn_changed(struct netif *netif)// called from netif_set_link_up/down
{
//	netif->flags;
#ifndef LWIP_DHCP	
 extern ip_addr_t ipaddr;// static, ip address already set if static address used
 extern ip_addr_t netmask;// netmask, already set if static address used
 extern ip_addr_t gw;// geteway, already set if static address used
#endif //LWIP_DHCP
 if(netif_is_link_up(netif))//
 {
		LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_notify_conn_changed: Network cable connected \n"));
		netif_set_up(netif);// set NETIF_FLAG_UP and call the relative callbacks about netif status.
#ifdef LWIP_DHCP
		ip_addr_set_zero_ip4(&netif->ip_addr);//zeroize brfore start dhcp. cable can connect to a different network than was before
		ip_addr_set_zero_ip4(&netif->netmask);//zeroize brfore start dhcp
		ip_addr_set_zero_ip4(&netif->gw);//zeroize brfore start dhcp
		dhcp_start(netif);// start or restart dhcp
#else
		netif_set_addr(netif, &ipaddr , &netmask, &gw);/set static ip address
#endif //LWIP_DHCP
 }
 else
 {
#ifdef LWIP_DHCP
		dhcp_release_and_stop(netif);//stop dhcp and relative timeouts if cable disconnected
#endif //LWIP_DHCP 
		netif_set_down(netif);//clear NETIF_FLAG_UP and call the relative callbacks about netif status
		LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("ethernetif_notify_conn_changed: Network cable disconnected \n")); 
 }
}
//##############################################################################

April 2, 2021

Dear @Vangelis Fortounas​ 

Thank you for your reply.

The code is somehow clear. The only matter that remains is where I should use the code.

Should I use this part in a parallel task as an independent function in the os (I use Freertos) so that it is checked continuously? or

Should I only define it in the main file so that a weak definition becomes strong :) which means it is a recursively called function that remained to be defined by the user?

Vangelis Fortounas
Associate II
April 2, 2021

hello.

>> Should I only define it in the main file so that a weak definition becomes strong =) which means it is a recursively called function that remained to be defined by the user?

Yes !

just define it (copy from here). is already declared and (defined as weak

it will be called from ethernetif_set_link (the link thread "LinkThr" ) if ethernet link is changed (cable status).