Skip to content

Commit 361754e

Browse files
authored
Merge pull request #2692 from SummerGGift/phy_check
[bsp][stm32][driver] fix phy detection driver
2 parents 8b312c2 + 6309492 commit 361754e

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_eth.c

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ static rt_err_t rt_stm32_eth_init(rt_device_t dev)
9191
EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
9292
#ifdef RT_LWIP_USING_HW_CHECKSUM
9393
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
94-
#else
94+
#else
9595
EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_SOFTWARE;
9696
#endif
97-
97+
9898
HAL_ETH_DeInit(&EthHandle);
9999

100100
/* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */
@@ -431,31 +431,34 @@ static void phy_monitor_thread_entry(void *parameter)
431431
uint8_t phy_addr = 0xFF;
432432
uint8_t phy_speed_new = 0;
433433
rt_uint32_t status = 0;
434+
uint8_t detected_count = 0;
434435

435-
/* phy search */
436-
rt_uint32_t i, temp;
437-
for (i = 0; i <= 0x1F; i++)
436+
while(phy_addr == 0xFF)
438437
{
439-
EthHandle.Init.PhyAddress = i;
438+
/* phy search */
439+
rt_uint32_t i, temp;
440+
for (i = 0; i <= 0x1F; i++)
441+
{
442+
EthHandle.Init.PhyAddress = i;
443+
HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp);
444+
445+
if (temp != 0xFFFF && temp != 0x00)
446+
{
447+
phy_addr = i;
448+
break;
449+
}
450+
}
440451

441-
HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp);
452+
detected_count++;
453+
rt_thread_mdelay(1000);
442454

443-
if (temp != 0xFFFF && temp != 0x00)
455+
if (detected_count > 10)
444456
{
445-
phy_addr = i;
446-
break;
457+
LOG_E("No PHY device was detected, please check hardware!");
447458
}
448459
}
449460

450-
if (phy_addr == 0xFF)
451-
{
452-
LOG_E("phy not probe!");
453-
return;
454-
}
455-
else
456-
{
457-
LOG_D("found a phy, address:0x%02X", phy_addr);
458-
}
461+
LOG_D("Found a phy, address:0x%02X", phy_addr);
459462

460463
/* RESET PHY */
461464
LOG_D("RESET PHY!");

0 commit comments

Comments
 (0)