2026-04-09 5:29 AM - last edited on 2026-04-09 10:01 AM by mƎALLEm
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 */
}
}
Solved! Go to Solution.
2026-04-09 7:40 AM
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.
2026-04-09 6:08 AM
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.
2026-04-09 6:10 AM
My only requirement at the moment is to check if the cable is connected.
2026-04-09 6:38 AM
Hello @NicRoberts,
Have you tried setting a breakpoint on the `if` condition to check whether it is triggered?
Best regards,
2026-04-09 7:23 AM
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()
2026-04-09 7:40 AM
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.
2026-04-09 7:42 AM
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.
2026-04-09 7:47 AM
2026-04-09 7:47 AM
@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
2026-04-09 8:06 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.