cancel
Showing results for 
Search instead for 
Did you mean: 

UDP Server not receiving when connecting cable after power-on

JCOrtiz
Associate II

Hi,

I have an UDP Server on a STM32F407Disc1. It works very good, but when the ethernet cable is already connected when I power on the board.

However, if I connect the cable after powering on the board, UDP Server does not receive any message.

My UDP Server is initiated before the while(1) loop, and I have MX_LWIP_Process() inside this while.

I have also added LWIP_NETIF_LINK_CALLBACK 1 to lwipopts.h and ethernetif_set_link(&gnetif) inside my MX_LWIP_Process function.

Where's the problem? The link status (if connected or not) is detected.

Thanks a lot!

Kind regards.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello

Define this function that is already weak..

if DHCP is used add also     dhcp_start(netif); and dhcp_release_and_stop(netif); accordingly

void ethernetif_notify_conn_changed(struct netif *netif)

{

 if(netif_is_link_up(netif))

  netif_set_up(netif);

 else

   netif_set_down(netif);

}

View solution in original post

5 REPLIES 5

Hello

Define this function that is already weak..

if DHCP is used add also     dhcp_start(netif); and dhcp_release_and_stop(netif); accordingly

void ethernetif_notify_conn_changed(struct netif *netif)

{

 if(netif_is_link_up(netif))

  netif_set_up(netif);

 else

   netif_set_down(netif);

}

I don't use DHCP. I have fixed IP.

However, that function is the solution. Thanks!

For a link status only the functions netif_set_link_up()/netif_set_link_down() must be used.

And for DHCP a single dhcp_start() at initialization is enough. It doesn't have to be stopped and started on link up/down events - lwIP already does the necessary steps internally.

Do not look at ST's broken bloatware examples, but read the documentation and actual lwIP code instead! All of that is explained there:

https://community.st.com/s/question/0D50X0000BOtfhnSQB/how-to-make-ethernet-and-lwip-working-on-stm32

Hello

@Piranha​, i read your articles .

i use lwip 2.1.2 , no RTOS

netif_set_link_up/ down functions, calls(not directly) the ethernetif_notify_conn_changed()

So netif_set_link_up()-down(), have been called already inside the ethernetif_set_link(..) that initiates a PHY "status report" callback system to every allocated netif and propagated up to ethernetif_notify_conn_changed(...) function.

i suggested use netif_set_up()/down() because if phy cable is disconnected before start the net stack, then netif is allready disabled and can't start if connect the cable. (For users of st version of lwip)

I suggested dhcp_release_and_stop() because gives netif status callback that needed(i use it), if enabled (when disconnect the cable) (netif_set_status_callback(...), ..

OK, understood that it's a workaround to not change ST's broken code. In that case I suggest replacing your code with this one:

if (!netif_is_up(netif)) {
	netif_set_up(netif);
}

Even better would be to place it not in the ethernetif_notify_conn_changed() function but right after ST's lwIP initialization. The status of netif itself is only administrative and has nothing to do with physical link status. Generally it must be enabled at the initialization and never be disabled. ST's developers just cannot grasp that simple truth.