2025-06-06 3:11 AM
Hello colleagues,
Hope you may help me in one issue I'm facing w/.
What I have in hands:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LWIP_Init();
MX_RTC_Init();
MX_USB_DEVICE_Init();
MX_CAN1_Init();
MX_SPI2_Init();
MX_I2C1_Init();
MX_SDIO_SD_Init();
MX_USART6_UART_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
MX_DAC_Init();
MX_FATFS_Init();
/* USER CODE BEGIN 2 */
Init_System(); // from proc_system.h
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
main_whileX();
}
/* USER CODE END 3 */
}
So I build the FW and run it via discovery onboard STLINK in debug mode. Everything works fine, static IP is pinged, WEB server works. Than I disconnect USB cable of onboard STLINK (MCU as well as LAN8720 is unpowered) and than connect in back (MCU and LAN8720 are powered).
THE PROBLEM: ETH link is DOWN, IP is not pinged. However if FW is uploaded again via STLINK, once MCU is reset LINK is UP again.
Sounds like all is OK when LAN8720 is already powered (for some time?) when PHY is started to be configured on FW side via MX_LWIP_Init();
And all is BAD if MX_LWIP_Init(); is called immediately at power up (when STLINK USB cable is connected). I tried to add 1s delay before MX_LWIP_Init() but it doesn't help.
Would appreciate a lot for any clues. Thank you in advance!
2025-06-06 4:11 AM
Maybe it's a power-up timing problem. Check the LAN's datasheet.
You could start MX_LWIP_Init() later (I would do that anyway), and / or add a delay.
I would also double-check if really all important registers are equal between the 2 LAN types.
And I like having the option of a hardware reset for any external stuff, can't remember if the LANs have a reset pin, but I guess so.
2025-06-06 4:29 AM
LCE - Thanks for feedback.
I got it worked when increased delay from 1s to 2s (1s - not enough, 2s - OK!)
/* USER CODE BEGIN SysInit */
HAL_Delay(2000); // required for LAN8720 init!!!
/* USER CODE END SysInit */
When I used to work w/ Microchip PIC32 + LAN8720 I used both delay 100ms and LAN8720 chip reset.
Have no idea why 2s is needed in case of STM. Will try to reduce delay and introduce LAN8720 chip reset at startup by GPIO.