Skip to main content
Associate
October 10, 2024
Solved

The STM32F407 lwIP does not work after the second reboot

  • October 10, 2024
  • 3 replies
  • 1338 views

After the device powers on, lwIP works properly. I reboot it once using the code below, and it continues to function correctly. However, if I reboot it a second time with the same code, it stops working. It goes through the PCB initialization, but no data reaches the callbacks. Normally, DHCP is enabled, but after the second reboot, it doesn't acquire an IP via DHCP either. What should I do to ensure the device reboots properly?

 

void Reboot_Device(void){
	close_udp();
 taskDISABLE_INTERRUPTS();
	netif_set_down(&gnetif); 
	netif_remove(&gnetif); 
	HAL_ETH_DeInit(&heth);
	NVIC_SystemReset();

}

 

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

I solved the issue. The problem was that the PHY's registers, etc., were not fully reset. I connected the NRST pin of the PHY circuit to a GPIO, and now I trigger a reset once during initialization.

HAL_GPIO_WritePin(PHY_RST_GPIO_Port, PHY_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(100);
HAL_GPIO_WritePin(PHY_RST_GPIO_Port, PHY_RST_Pin, GPIO_PIN_SET);

3 replies

ST Technical Moderator
October 10, 2024

Hello @embedtekin ,

Make sure to proper reinitialization after reboot. So, reinitialize System Clock, Ethernet Peripheral (using the HAL_ETH_Init) and reinitialize lwIP stack.

Maybe this issue is caused by one interrupt from the previous execution that remains pending in the NVIC. So, make sure to clear any pending interrupts in the NVIC to avoid spurious interrupts after reboot.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Associate
October 14, 2024

Since it returns to the main function, the things you mentioned get reinitialized. Am I thinking incorrectly? It seems like there's no deinit function for lwIP. However, I deinitialize many things related to Ethernet before the reboot. Since it returns to the main function, they get initialized again. It already works fine the first time. If I couldn't reinitialize properly, it wouldn't work the first time either, I think

embedtekinAuthorBest answer
Associate
October 14, 2024

I solved the issue. The problem was that the PHY's registers, etc., were not fully reset. I connected the NRST pin of the PHY circuit to a GPIO, and now I trigger a reset once during initialization.

HAL_GPIO_WritePin(PHY_RST_GPIO_Port, PHY_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(100);
HAL_GPIO_WritePin(PHY_RST_GPIO_Port, PHY_RST_Pin, GPIO_PIN_SET);