From 6309492ec5daff70289da513cd184d2e52a96bbf Mon Sep 17 00:00:00 2001 From: SummerGift Date: Wed, 15 May 2019 15:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91PHY=20?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E7=9B=B8=E5=85=B3=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/stm32/libraries/HAL_Drivers/drv_eth.c | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c index 1c9055be89..148a03f45b 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_eth.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_eth.c @@ -91,10 +91,10 @@ static rt_err_t rt_stm32_eth_init(rt_device_t dev) EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE; #ifdef RT_LWIP_USING_HW_CHECKSUM EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE; -#else +#else EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_SOFTWARE; #endif - + HAL_ETH_DeInit(&EthHandle); /* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */ @@ -431,31 +431,34 @@ static void phy_monitor_thread_entry(void *parameter) uint8_t phy_addr = 0xFF; uint8_t phy_speed_new = 0; rt_uint32_t status = 0; + uint8_t detected_count = 0; - /* phy search */ - rt_uint32_t i, temp; - for (i = 0; i <= 0x1F; i++) + while(phy_addr == 0xFF) { - EthHandle.Init.PhyAddress = i; - - HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp); - - if (temp != 0xFFFF && temp != 0x00) + /* phy search */ + rt_uint32_t i, temp; + for (i = 0; i <= 0x1F; i++) { - phy_addr = i; - break; + EthHandle.Init.PhyAddress = i; + HAL_ETH_ReadPHYRegister(&EthHandle, PHY_ID1_REG, (uint32_t *)&temp); + + if (temp != 0xFFFF && temp != 0x00) + { + phy_addr = i; + break; + } + } + + detected_count++; + rt_thread_mdelay(1000); + + if (detected_count > 10) + { + LOG_E("No PHY device was detected, please check hardware!"); } } - if (phy_addr == 0xFF) - { - LOG_E("phy not probe!"); - return; - } - else - { - LOG_D("found a phy, address:0x%02X", phy_addr); - } + LOG_D("Found a phy, address:0x%02X", phy_addr); /* RESET PHY */ LOG_D("RESET PHY!");