From 6fc800e56232fca3a13e7b444424c0383c3ff61b Mon Sep 17 00:00:00 2001 From: linuswck Date: Wed, 28 Feb 2024 12:58:57 +0800 Subject: [PATCH] net: Set stm32 link speed with the Phy Speed read --- src/net/net.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/net/net.rs b/src/net/net.rs index 2fdc2cf..07357cd 100644 --- a/src/net/net.rs +++ b/src/net/net.rs @@ -12,6 +12,7 @@ use smoltcp::{ }; use stm32_eth::{ Parts, EthPins, PartsIn, + mac::Speed, dma::{ TxRingEntry, RxRingEntry, EthernetDMA }}; @@ -148,6 +149,20 @@ impl ServerHandle { ); phy.phy_init(); + while !phy.phy_link_up() {} + + if let Some(speed) = phy.speed().map(|s| match s { + PhySpeed::HalfDuplexBase10T => Speed::HalfDuplexBase10T, + PhySpeed::FullDuplexBase10T => Speed::FullDuplexBase10T, + PhySpeed::HalfDuplexBase100Tx => Speed::HalfDuplexBase100Tx, + PhySpeed::FullDuplexBase100Tx => Speed::FullDuplexBase100Tx, + }) { + phy.get_miim().set_speed(speed); + info!("Detected link speed: {:?}", speed); + } else { + debug!("Failed to detect link speed."); + } + } else { info!("Not resetting unsupported PHY."); } @@ -218,6 +233,7 @@ use ieee802_3_miim::{ phy::{ lan87xxa::{LAN8720A, LAN8742A}, BarePhy, KSZ8081R, + PhySpeed }, Miim, Pause, Phy, };