ETH LWIP with RTOS | bug in ethernetif.c: HAL_ETH_Start_IT
Setup
STM32CubeIde 1.10.1
STM32CubeMX 6.6.1.202207061420
Regarding
STM32F4/F7/H7 projects (maybe also exends to others) with Ethernet, LwIP and RTOS features activated.
Especially when the WITH_RTOS flag is set in LwIP>General settings.
Symptoms
Ethernet link reconnection fails, initial connection fails if disconnected at startup.
The ethernetif.c files that are created with the configuration as explained above are falsely generated with HAL_ETH_Start(&heth) non-interupt function call in ethernet_link_thread:
// Part of void ethernet_link_thread(void* argument) in ethernetif.c around line 797
if(linkchanged)
{
/* Get MAC Config MAC */
HAL_ETH_GetMACConfig(&heth, &MACConf);
MACConf.DuplexMode = duplex;
MACConf.Speed = speed;
HAL_ETH_SetMACConfig(&heth, &MACConf);
HAL_ETH_Start(&heth);
netif_set_up(netif);
netif_set_link_up(netif);
}Call must instead be HAL_ETH_Start_IT(&heth) for WITH_RTOS configuration.
Bug details
The ethernetif.c file templates (ethernetif_f4.ftl, ethernetif_f7.ftl and ethernetif_h7.ftl) in db/templates are missing an if evalution for this line for the WITH_RTOS flag.
Solution for ethernetif_f4.ftl (differerent line numbers in other .ftl files)
Replace
HAL_ETH_Start(&heth);in line 891 by
[#if with_rtos == 1]
HAL_ETH_Start_IT(&heth);
[#else]
HAL_ETH_Start(&heth);
[/#if][#-- endif with_rtos --]like done for the HAL_ETH_Stop_IT(&heth) call in line 848.
