Strange breakpoint issue

Hello there! I am using a Cortex M4, the XMC4500 and I am experiencing a strange problem that I don’t understand. I have LWIP 1.4.0 working and when I activate the netif callback I create a FreeRTOS timer to check the PHY link each second. When the link is out, I bring the interface down. When the link comes back, I brin the interface up. uint32_t previousLinkState = 0;
void CheckUnplug( xTimerHandle xTimer )
{
extern synopGMACdevice GMACdevice;
synopGMAC_cable_unplug_function(&GMACdevice);
if(GMACdevice.LinkState == 0 && previousLinkState == 1)
{
netif_set_link_down(pxNetIfInUse);
previousLinkState = 0;
}
else if(GMACdevice.LinkState != 0 && previousLinkState == 0)
{
netif_set_link_up(pxNetIfInUse);
previousLinkState = 1;
}
} The strange thing: imagine I was sending via socket something and I disconnect the cable. It obviously stops. Then I reconnect the cable. The connection doesn’t resume, even though it should. If in this moment I put a breakpoint (I use a Segger JLink, GDB server, ARM GCC toolchain) in the netif_set_link_up call it actually stops, does it and the connection gets resumed. Long story short, is like if the timer code was not executing if I don’t put a breakpoint, which is really confusing. Anyone knows anything about this? Thank you

Strange breakpoint issue

That is strange. Can you establish exactly where the failure happens. Maybe add a link_down_processing++ after each previousLinkState = 0 statement and link_up_processing++ after each previousLinkState = 1 statement to see if you go through the if statement at all. If the counters values show that the netif_set_link_x functions are being called, but the network is still not coming up, then it is more likely to be in the implementation of those functions rather than the timer not being called. Are the netif_set_link_x() functions thread safe?

Strange breakpoint issue

Hello there! Thanks for the suggestion! I didin’t even think about that, but that’s it, one must ensure everything is done from the tcp_ip thread. So I changed it like this: xTimerHandle unplug_timer;
uint32_t previousLinkState = 0;
uint32_t downCounter = 0, upCounter = 0; void _check_unplug(void* param)
{
extern synopGMACdevice GMACdevice;
synopGMAC_cable_unplug_function(&GMACdevice);
if(GMACdevice.LinkState == 0 && previousLinkState == 1)
{
netif_set_link_down(pxNetIfInUse);
previousLinkState = 0;
downCounter++;
}
else if(GMACdevice.LinkState != 0 && previousLinkState == 0)
{
netif_set_link_up(pxNetIfInUse);
GMACdevice.LinkState = 1;
previousLinkState = 1;
upCounter++;
}
} void CheckUnplug( xTimerHandle xTimer )
{
tcpip_callback_with_block(_check_unplug,NULL,0);
} The tcpip_callback_with_block is included in LWIP and now it works perfect. Thank you for your help :-)