Skip to main content
Visitor II
April 2, 2024
Solved

UDP communication does not work if the cable is plugged in after initialization

  • April 2, 2024
  • 1 reply
  • 1351 views

Hi,

I have an UDP Server on a STM32H743ZI. It works very good only if 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.

FreeRTOS is used on my project and I have added LWIP_NETIF_LINK_CALLBACK 1 to lwipopts.h but I never go in callback function even if I connect/disconnect the ehernet cable.

Where's the problem?
what should I add to detect the cable connection?

Thanks a lot!

Kind regards.

    This topic has been closed for replies.
    Best answer by Bajocasse

    I solved my problem by changing the priority in the MX_LWIP_Init function

     

    I set

    /* USER CODE BEGIN H7_OS_THREAD_NEW_CMSIS_RTOS_V2 */
    memset(&attributes, 0x0, sizeof(osThreadAttr_t));
    attributes.name = "EthLink";
    attributes.stack_size = INTERFACE_THREAD_STACK_SIZE;
    attributes.priority = osPriorityNormal;
    osThreadNew(ethernet_link_thread, &gnetif, &attributes);
    /* USER CODE END H7_OS_THREAD_NEW_CMSIS_RTOS_V2 */

    rather than osPriorityBelowNormal

     

    and so The ethernet_link_thread function is then called during cable connections/disconnections

    1 reply

    ST Employee
    April 29, 2024

    Hello @Bajocasse,

    Have you called the netif_set_link_callback() function as demonstrated in the following snippet? 

    #if LWIP_NETIF_LINK_CALLBACK
    netif_set_link_callback(&netif, ethernet_link_status_updated);
    #endif
    

    By calling this function, your application will be able to dynamically respond to changes in the network link status, such as when the Ethernet cable is plugged in or unplugged.

    With Regards,

    BajocasseAuthorAnswer
    Visitor II
    May 6, 2024

    I solved my problem by changing the priority in the MX_LWIP_Init function

     

    I set

    /* USER CODE BEGIN H7_OS_THREAD_NEW_CMSIS_RTOS_V2 */
    memset(&attributes, 0x0, sizeof(osThreadAttr_t));
    attributes.name = "EthLink";
    attributes.stack_size = INTERFACE_THREAD_STACK_SIZE;
    attributes.priority = osPriorityNormal;
    osThreadNew(ethernet_link_thread, &gnetif, &attributes);
    /* USER CODE END H7_OS_THREAD_NEW_CMSIS_RTOS_V2 */

    rather than osPriorityBelowNormal

     

    and so The ethernet_link_thread function is then called during cable connections/disconnections