Problem in ethernet starts while LAN cable disconnected

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem in ethernet starts while LAN cable disconnected

2,224 Views
biafra
Senior Contributor I

Hi everyone,

 

I'm using a custom board based on RT1064, with MCUXpresso 11.8.0 and SDK 2.12.0.

The board uses a LAN8720A ethernet tranceiver that is working fine.

I have a trouble when the system starts with then LAN cable disconnected: if I connect the cable after the init is completed, a ping packet from another device is not answered.

Here is a summary of my code:

 

 

tcpip_init( NULL, NULL );
...
netif_add( &NetIfLAN, &IPAddress, &NetMask, &DGAddress, &EthConfig, ethernetif0_init, tcpip_input );
netif_set_default( &NetIfLAN );
StartNetworkSupervisor();
void NetWorkSupervisor( void )
{
	bool link, oldlink = false;

	while( 1 )
	{
		if( PHY_GetLinkStatus( EthConfig.phyHandle, &link ) != kStatus_Success )
			link = false;
		if( link != oldlink )
		{
			if( link != false )
			{
				PRINTF( "LINK UP\n" );
				sys_lock_tcpip_core();
				//netif_set_link_up( &NetIfLAN );
				netif_set_up( &NetIfLAN );
				sys_unlock_tcpip_core();
			}
			else
			{
				PRINTF( "LINK DOWN\n" );
				sys_lock_tcpip_core();
				//netif_set_down( &NetIfLAN );
				netif_set_link_down( &NetIfLAN );
				sys_unlock_tcpip_core();
			}
			oldlink = link;
		}
		...
	}
}

 

 

 

In the terminal I can see the "LINK UP" and "LINK DOWN" strings, so the connection and disconnection events are handled. I tried both with and without the netif_set_link_up() and netif_set_link_down() calls, but the behaviour is the same.

 

Does anyone have some suggestion?

 

Many thanks

Biafra

7 Replies

2,196 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, my name is Pavel, and I will be supporting your case, I reviewed your comments, and I suggest reviewing the example on the SDK because there are some states in the protocol that need to wait. Maybe you could do a porting.

Pavel_Hernandez_0-1697584609430.png

Best regards,
Pavel

2,182 Views
biafra
Senior Contributor I

Hi Pavel,

 

Many thanks for your answer.

I reviewed some example in SDK about LwIP, and I noticed that in freertos examples netifapi_netif_xxx functions are used.

So in my code I replaced the netif_xxx functions with the corresponding netifapi_netif_xxx functions, but the behaviour is the same.

In such examples I couldn't find the states to wait you mentioned: can you give me some details about them?

 

Many thanks

Biafra

1,959 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, sorry for the late response I apologize for the last response I was not clear; I recommend reviewing how the examples work they have a blocking mode of wait state until connecting the LAN cable.

Pavel_Hernandez_0-1698785290261.png

Best regards,
Pavel

1,924 Views
biafra
Senior Contributor I

Hi @Pavel_Hernandez,

 

Many thanks for your answer.

Sorry for my my lack of clarity, I'll try to explain myself better.

The blocking mode have a configurable max numer of attempts (ENET_ATONEGOTIATION_TIMEOUT) to wait until connecting the LAN cable. If I connect the LAN cable before the number of attempts reaches ENET_ATONEGOTIATION_TIMEOUT the system works fine.

The system doesn't work if I connect the LAN cable after the max numer of attempts is reached.

The NetWorkSupervisor task is intended to recognize the cable connection/disconnection and to do the needed operartions to make the system work in all situations.

 

Many thanks

Biafra

1,751 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, sorry for the late response what is the example where you find that functions NetWorkSupervisor, I reviewed the httpsrv_freertos but I can't find this.

Best regards,
Pavel

1,708 Views
biafra
Senior Contributor I

Hi @Pavel_Hernandez,

 

Many thanks for your answer.

There isn't the NetWorkSupervisor() function in the examples, it's a function I've written thinking that it's needed to make the network work if it starts with the cable disconnected.

 

Many thanks

Biafra

 

1,653 Views
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello, sorry but I´m afraid there is no nothing like this, I suggest creating a task supervisor to avoid using the counter.

Best regards,
Pavel