cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP not entering callback when ethernet cable (dis)connected

NicRoberts
Senior II

NUCLEO-F767ZI

I'm trying to use the LwIP middleware which I have enabled in MX.

First I'm trying to check if an ethernet cable is attached or not. I have setup UART3 to use printf (which works as expected)

I've set the callback in lwip.c to print when the cable is removed or plugged in or so I thought but I get no message when I connect or disconnect the cable. The LEDs on the socket light up when the cable is connected, so the board at some level does see the cable. What am I missing here?

EDIT:: LWIP_NETIF_LINK_CALLBACK was enabled in MX

// In main.c
MX_LWIP_Init();

/* USER CODE BEGIN WHILE */
while (1)
{
  MX_LWIP_Process();
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */



// In lwip.c the callback function that is registered in MX_LWIP_Init()
static void ethernet_link_status_updated(struct netif *netif)
{
  if (netif_is_up(netif))
  {
/* USER CODE BEGIN 5 */
	  printf("Cable connected\r\n");
/* USER CODE END 5 */
  }
  else /* netif is down */
  {
/* USER CODE BEGIN 6 */
	  printf("Cable NOT connected\r\n");
/* USER CODE END 6 */
  }
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
STackPointer64
ST Employee

Have you configured the Ethernet DMA descriptors, LwIP, and the MPU correctly? If you attach your project, I can analyze it and look for misconfigurations. I also suggest that you review this knowledge base article; it will guide you through the necessary configurations. You could skip FreeRTOS and using a dedicated timer as a time base, because from the snippet you attached above, your goal is to run LwIP in polling mode.

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

View solution in original post

13 REPLIES 13
mbarg.1
Lead

You do not have a connection manager - demo does not (most cases) it - there are many other cases, choices, features requiring sw management that are not handled in demo.

I usually suggest to draw a set of requirements you want in your system and compare with actual demo code to get double sure that minimum system is hat your customers can accept.

My only requirement at the moment is to check if the cable is connected.

STackPointer64
ST Employee

Hello @NicRoberts,

Have you tried setting a breakpoint on the `if` condition to check whether it is triggered?

Best regards,

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

Going through the debug it doesn't get anywhere near, doesn't get past the memory initialisation, 

 

MX_LWIP_Init()

____lwip_init()

________mem_init()

__________mem->prev = 0;

HardFault_Handler()

STackPointer64
ST Employee

Have you configured the Ethernet DMA descriptors, LwIP, and the MPU correctly? If you attach your project, I can analyze it and look for misconfigurations. I also suggest that you review this knowledge base article; it will guide you through the necessary configurations. You could skip FreeRTOS and using a dedicated timer as a time base, because from the snippet you attached above, your goal is to run LwIP in polling mode.

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.
STackPointer64
ST Employee

Once we ensure that LwIP is working flawlessly, we can move on and debug why the LWIP_NETIF_LINK_CALLBACK function is not being triggered and does not print any message.

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.

I'll go through the link you posted. Thanks for taking a look, find attached. 


@NicRoberts wrote:

doesn't get past the memory initialisation, 


So the code is not completing initialisation at all ?

Hardly surprising, then, that none of the features work!

 

Debugging Cortex-M Hard Faults

 

LwIP Debug / Diagnostics

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
STackPointer64
ST Employee

As suspected, you are missing crucial memory and cache configurations that will allow your application to work. I suggest that, after reading the article, you apply the configurations illustrated in sections 2.2, 2.4, 2.5, and 3.1. I’m pretty sure they will resolve the issue you are currently facing.

To improve visibility of answered topics, please click 'Accept as Solution' on the reply that resolved your issue or answered your question.