From b1245858f355e764a17eda819198f68ad83883ab Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 26 Jan 2025 22:42:13 +0100 Subject: stm32/eth: rename PHY->Phy, GenericSMI -> GenericPhy. Remove unneeded unsafes. We shouldn't use `unsafe` to mark merely "dangerous" actions, only actions that actually cause UB. --- embassy-stm32/src/eth/generic_phy.rs | 165 ++++++++++++++++++++++++ embassy-stm32/src/eth/generic_smi.rs | 165 ------------------------ embassy-stm32/src/eth/mod.rs | 38 +++--- embassy-stm32/src/eth/v1/mod.rs | 10 +- embassy-stm32/src/eth/v2/mod.rs | 8 +- examples/stm32f4/src/bin/eth.rs | 7 +- examples/stm32f4/src/bin/eth_compliance_test.rs | 7 +- examples/stm32f7/src/bin/eth.rs | 7 +- examples/stm32h5/src/bin/eth.rs | 7 +- examples/stm32h7/src/bin/eth.rs | 7 +- examples/stm32h7/src/bin/eth_client.rs | 7 +- examples/stm32h7/src/bin/eth_client_mii.rs | 7 +- tests/stm32/src/bin/eth.rs | 7 +- 13 files changed, 216 insertions(+), 226 deletions(-) create mode 100644 embassy-stm32/src/eth/generic_phy.rs delete mode 100644 embassy-stm32/src/eth/generic_smi.rs diff --git a/embassy-stm32/src/eth/generic_phy.rs b/embassy-stm32/src/eth/generic_phy.rs new file mode 100644 index 000000000..774beef80 --- /dev/null +++ b/embassy-stm32/src/eth/generic_phy.rs @@ -0,0 +1,165 @@ +//! Generic SMI Ethernet PHY + +use core::task::Context; + +#[cfg(feature = "time")] +use embassy_time::{Duration, Timer}; +#[cfg(feature = "time")] +use futures_util::FutureExt; + +use super::{Phy, StationManagement}; + +#[allow(dead_code)] +mod phy_consts { + pub const PHY_REG_BCR: u8 = 0x00; + pub const PHY_REG_BSR: u8 = 0x01; + pub const PHY_REG_ID1: u8 = 0x02; + pub const PHY_REG_ID2: u8 = 0x03; + pub const PHY_REG_ANTX: u8 = 0x04; + pub const PHY_REG_ANRX: u8 = 0x05; + pub const PHY_REG_ANEXP: u8 = 0x06; + pub const PHY_REG_ANNPTX: u8 = 0x07; + pub const PHY_REG_ANNPRX: u8 = 0x08; + pub const PHY_REG_CTL: u8 = 0x0D; // Ethernet PHY Register Control + pub const PHY_REG_ADDAR: u8 = 0x0E; // Ethernet PHY Address or Data + + pub const PHY_REG_WUCSR: u16 = 0x8010; + + pub const PHY_REG_BCR_COLTEST: u16 = 1 << 7; + pub const PHY_REG_BCR_FD: u16 = 1 << 8; + pub const PHY_REG_BCR_ANRST: u16 = 1 << 9; + pub const PHY_REG_BCR_ISOLATE: u16 = 1 << 10; + pub const PHY_REG_BCR_POWERDN: u16 = 1 << 11; + pub const PHY_REG_BCR_AN: u16 = 1 << 12; + pub const PHY_REG_BCR_100M: u16 = 1 << 13; + pub const PHY_REG_BCR_LOOPBACK: u16 = 1 << 14; + pub const PHY_REG_BCR_RESET: u16 = 1 << 15; + + pub const PHY_REG_BSR_JABBER: u16 = 1 << 1; + pub const PHY_REG_BSR_UP: u16 = 1 << 2; + pub const PHY_REG_BSR_FAULT: u16 = 1 << 4; + pub const PHY_REG_BSR_ANDONE: u16 = 1 << 5; +} +use self::phy_consts::*; + +/// Generic SMI Ethernet PHY implementation +pub struct GenericPhy { + phy_addr: u8, + #[cfg(feature = "time")] + poll_interval: Duration, +} + +impl GenericPhy { + /// Construct the PHY. It assumes the address `phy_addr` in the SMI communication + /// + /// # Panics + /// `phy_addr` must be in range `0..32` + pub fn new(phy_addr: u8) -> Self { + assert!(phy_addr < 32); + Self { + phy_addr, + #[cfg(feature = "time")] + poll_interval: Duration::from_millis(500), + } + } + + /// Construct the PHY. Try to probe all addresses from 0 to 31 during initialization + /// + /// # Panics + /// Initialization panics if PHY didn't respond on any address + pub fn new_auto() -> Self { + Self { + phy_addr: 0xFF, + #[cfg(feature = "time")] + poll_interval: Duration::from_millis(500), + } + } +} + +// TODO: Factor out to shared functionality +fn blocking_delay_us(us: u32) { + #[cfg(feature = "time")] + embassy_time::block_for(Duration::from_micros(us as u64)); + #[cfg(not(feature = "time"))] + { + let freq = unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 as u64; + let us = us as u64; + let cycles = freq * us / 1_000_000; + cortex_m::asm::delay(cycles as u32); + } +} + +impl Phy for GenericPhy { + fn phy_reset(&mut self, sm: &mut S) { + // Detect SMI address + if self.phy_addr == 0xFF { + for addr in 0..32 { + sm.smi_write(addr, PHY_REG_BCR, PHY_REG_BCR_RESET); + for _ in 0..10 { + if sm.smi_read(addr, PHY_REG_BCR) & PHY_REG_BCR_RESET != PHY_REG_BCR_RESET { + trace!("Found ETH PHY on address {}", addr); + self.phy_addr = addr; + return; + } + // Give PHY a total of 100ms to respond + blocking_delay_us(10000); + } + } + panic!("PHY did not respond"); + } + + sm.smi_write(self.phy_addr, PHY_REG_BCR, PHY_REG_BCR_RESET); + while sm.smi_read(self.phy_addr, PHY_REG_BCR) & PHY_REG_BCR_RESET == PHY_REG_BCR_RESET {} + } + + fn phy_init(&mut self, sm: &mut S) { + // Clear WU CSR + self.smi_write_ext(sm, PHY_REG_WUCSR, 0); + + // Enable auto-negotiation + sm.smi_write( + self.phy_addr, + PHY_REG_BCR, + PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M, + ); + } + + fn poll_link(&mut self, sm: &mut S, cx: &mut Context) -> bool { + #[cfg(not(feature = "time"))] + cx.waker().wake_by_ref(); + + #[cfg(feature = "time")] + let _ = Timer::after(self.poll_interval).poll_unpin(cx); + + let bsr = sm.smi_read(self.phy_addr, PHY_REG_BSR); + + // No link without autonegotiate + if bsr & PHY_REG_BSR_ANDONE == 0 { + return false; + } + // No link if link is down + if bsr & PHY_REG_BSR_UP == 0 { + return false; + } + + // Got link + true + } +} + +/// Public functions for the PHY +impl GenericPhy { + /// Set the SMI polling interval. + #[cfg(feature = "time")] + pub fn set_poll_interval(&mut self, poll_interval: Duration) { + self.poll_interval = poll_interval + } + + // Writes a value to an extended PHY register in MMD address space + fn smi_write_ext(&mut self, sm: &mut S, reg_addr: u16, reg_data: u16) { + sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x0003); // set address + sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_addr); + sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x4003); // set data + sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_data); + } +} diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs deleted file mode 100644 index 239c52634..000000000 --- a/embassy-stm32/src/eth/generic_smi.rs +++ /dev/null @@ -1,165 +0,0 @@ -//! Generic SMI Ethernet PHY - -use core::task::Context; - -#[cfg(feature = "time")] -use embassy_time::{Duration, Timer}; -#[cfg(feature = "time")] -use futures_util::FutureExt; - -use super::{StationManagement, PHY}; - -#[allow(dead_code)] -mod phy_consts { - pub const PHY_REG_BCR: u8 = 0x00; - pub const PHY_REG_BSR: u8 = 0x01; - pub const PHY_REG_ID1: u8 = 0x02; - pub const PHY_REG_ID2: u8 = 0x03; - pub const PHY_REG_ANTX: u8 = 0x04; - pub const PHY_REG_ANRX: u8 = 0x05; - pub const PHY_REG_ANEXP: u8 = 0x06; - pub const PHY_REG_ANNPTX: u8 = 0x07; - pub const PHY_REG_ANNPRX: u8 = 0x08; - pub const PHY_REG_CTL: u8 = 0x0D; // Ethernet PHY Register Control - pub const PHY_REG_ADDAR: u8 = 0x0E; // Ethernet PHY Address or Data - - pub const PHY_REG_WUCSR: u16 = 0x8010; - - pub const PHY_REG_BCR_COLTEST: u16 = 1 << 7; - pub const PHY_REG_BCR_FD: u16 = 1 << 8; - pub const PHY_REG_BCR_ANRST: u16 = 1 << 9; - pub const PHY_REG_BCR_ISOLATE: u16 = 1 << 10; - pub const PHY_REG_BCR_POWERDN: u16 = 1 << 11; - pub const PHY_REG_BCR_AN: u16 = 1 << 12; - pub const PHY_REG_BCR_100M: u16 = 1 << 13; - pub const PHY_REG_BCR_LOOPBACK: u16 = 1 << 14; - pub const PHY_REG_BCR_RESET: u16 = 1 << 15; - - pub const PHY_REG_BSR_JABBER: u16 = 1 << 1; - pub const PHY_REG_BSR_UP: u16 = 1 << 2; - pub const PHY_REG_BSR_FAULT: u16 = 1 << 4; - pub const PHY_REG_BSR_ANDONE: u16 = 1 << 5; -} -use self::phy_consts::*; - -/// Generic SMI Ethernet PHY implementation -pub struct GenericSMI { - phy_addr: u8, - #[cfg(feature = "time")] - poll_interval: Duration, -} - -impl GenericSMI { - /// Construct the PHY. It assumes the address `phy_addr` in the SMI communication - /// - /// # Panics - /// `phy_addr` must be in range `0..32` - pub fn new(phy_addr: u8) -> Self { - assert!(phy_addr < 32); - Self { - phy_addr, - #[cfg(feature = "time")] - poll_interval: Duration::from_millis(500), - } - } - - /// Construct the PHY. Try to probe all addresses from 0 to 31 during initialization - /// - /// # Panics - /// Initialization panics if PHY didn't respond on any address - pub fn new_auto() -> Self { - Self { - phy_addr: 0xFF, - #[cfg(feature = "time")] - poll_interval: Duration::from_millis(500), - } - } -} - -// TODO: Factor out to shared functionality -fn blocking_delay_us(us: u32) { - #[cfg(feature = "time")] - embassy_time::block_for(Duration::from_micros(us as u64)); - #[cfg(not(feature = "time"))] - { - let freq = unsafe { crate::rcc::get_freqs() }.sys.to_hertz().unwrap().0 as u64; - let us = us as u64; - let cycles = freq * us / 1_000_000; - cortex_m::asm::delay(cycles as u32); - } -} - -unsafe impl PHY for GenericSMI { - fn phy_reset(&mut self, sm: &mut S) { - // Detect SMI address - if self.phy_addr == 0xFF { - for addr in 0..32 { - sm.smi_write(addr, PHY_REG_BCR, PHY_REG_BCR_RESET); - for _ in 0..10 { - if sm.smi_read(addr, PHY_REG_BCR) & PHY_REG_BCR_RESET != PHY_REG_BCR_RESET { - trace!("Found ETH PHY on address {}", addr); - self.phy_addr = addr; - return; - } - // Give PHY a total of 100ms to respond - blocking_delay_us(10000); - } - } - panic!("PHY did not respond"); - } - - sm.smi_write(self.phy_addr, PHY_REG_BCR, PHY_REG_BCR_RESET); - while sm.smi_read(self.phy_addr, PHY_REG_BCR) & PHY_REG_BCR_RESET == PHY_REG_BCR_RESET {} - } - - fn phy_init(&mut self, sm: &mut S) { - // Clear WU CSR - self.smi_write_ext(sm, PHY_REG_WUCSR, 0); - - // Enable auto-negotiation - sm.smi_write( - self.phy_addr, - PHY_REG_BCR, - PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M, - ); - } - - fn poll_link(&mut self, sm: &mut S, cx: &mut Context) -> bool { - #[cfg(not(feature = "time"))] - cx.waker().wake_by_ref(); - - #[cfg(feature = "time")] - let _ = Timer::after(self.poll_interval).poll_unpin(cx); - - let bsr = sm.smi_read(self.phy_addr, PHY_REG_BSR); - - // No link without autonegotiate - if bsr & PHY_REG_BSR_ANDONE == 0 { - return false; - } - // No link if link is down - if bsr & PHY_REG_BSR_UP == 0 { - return false; - } - - // Got link - true - } -} - -/// Public functions for the PHY -impl GenericSMI { - /// Set the SMI polling interval. - #[cfg(feature = "time")] - pub fn set_poll_interval(&mut self, poll_interval: Duration) { - self.poll_interval = poll_interval - } - - // Writes a value to an extended PHY register in MMD address space - fn smi_write_ext(&mut self, sm: &mut S, reg_addr: u16, reg_data: u16) { - sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x0003); // set address - sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_addr); - sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x4003); // set data - sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_data); - } -} diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs index 773452bf2..109ceeeb3 100644 --- a/embassy-stm32/src/eth/mod.rs +++ b/embassy-stm32/src/eth/mod.rs @@ -4,7 +4,7 @@ #[cfg_attr(any(eth_v1a, eth_v1b, eth_v1c), path = "v1/mod.rs")] #[cfg_attr(eth_v2, path = "v2/mod.rs")] mod _version; -pub mod generic_smi; +mod generic_phy; use core::mem::MaybeUninit; use core::task::Context; @@ -13,6 +13,7 @@ use embassy_net_driver::{Capabilities, HardwareAddress, LinkState}; use embassy_sync::waitqueue::AtomicWaker; pub use self::_version::{InterruptHandler, *}; +pub use self::generic_phy::*; use crate::rcc::RccPeripheral; #[allow(unused)] @@ -71,7 +72,7 @@ impl PacketQueue { static WAKER: AtomicWaker = AtomicWaker::new(); -impl<'d, T: Instance, P: PHY> embassy_net_driver::Driver for Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> embassy_net_driver::Driver for Ethernet<'d, T, P> { type RxToken<'a> = RxToken<'a, 'd> where @@ -156,23 +157,15 @@ impl<'a, 'd> embassy_net_driver::TxToken for TxToken<'a, 'd> { } /// Station Management Interface (SMI) on an ethernet PHY -/// -/// # Safety -/// -/// The methods cannot move out of self -pub unsafe trait StationManagement { +pub trait StationManagement { /// Read a register over SMI. fn smi_read(&mut self, phy_addr: u8, reg: u8) -> u16; /// Write a register over SMI. fn smi_write(&mut self, phy_addr: u8, reg: u8, val: u16); } -/// Traits for an Ethernet PHY -/// -/// # Safety -/// -/// The methods cannot move S -pub unsafe trait PHY { +/// Trait for an Ethernet PHY +pub trait Phy { /// Reset PHY and wait for it to come out of reset. fn phy_reset(&mut self, sm: &mut S); /// PHY initialisation. @@ -181,18 +174,23 @@ pub unsafe trait PHY { fn poll_link(&mut self, sm: &mut S, cx: &mut Context) -> bool; } -impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { /// Directly expose the SMI interface used by the Ethernet driver. /// /// This can be used to for example configure special PHY registers for compliance testing. - /// - /// # Safety - /// - /// Revert any temporary PHY register changes such as to enable test modes before handing - /// the Ethernet device over to the networking stack otherwise things likely won't work. - pub unsafe fn station_management(&mut self) -> &mut impl StationManagement { + pub fn station_management(&mut self) -> &mut impl StationManagement { &mut self.station_management } + + /// Access the user-supplied `Phy`. + pub fn phy(&self) -> &P { + &self.phy + } + + /// Mutably access the user-supplied `Phy`. + pub fn phy_mut(&mut self) -> &mut P { + &mut self.phy + } } trait SealedInstance { diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 438b28020..e12ac2fef 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -46,7 +46,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } /// Ethernet driver. -pub struct Ethernet<'d, T: Instance, P: PHY> { +pub struct Ethernet<'d, T: Instance, P: Phy> { _peri: PeripheralRef<'d, T>, pub(crate) tx: TDesRing<'d>, pub(crate) rx: RDesRing<'d>, @@ -91,7 +91,7 @@ macro_rules! config_pins { }; } -impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { /// safety: the returned instance is not leak-safe pub fn new( queue: &'d mut PacketQueue, @@ -272,12 +272,12 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { } /// Ethernet station management interface. -pub struct EthernetStationManagement { +pub(crate) struct EthernetStationManagement { peri: PhantomData, clock_range: Cr, } -unsafe impl StationManagement for EthernetStationManagement { +impl StationManagement for EthernetStationManagement { fn smi_read(&mut self, phy_addr: u8, reg: u8) -> u16 { let mac = T::regs().ethernet_mac(); @@ -307,7 +307,7 @@ unsafe impl StationManagement for EthernetStationManagement { } } -impl<'d, T: Instance, P: PHY> Drop for Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> Drop for Ethernet<'d, T, P> { fn drop(&mut self) { let dma = T::regs().ethernet_dma(); let mac = T::regs().ethernet_mac(); diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 9dd7f7d95..26e4eeb63 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -36,7 +36,7 @@ impl interrupt::typelevel::Handler for InterruptHandl } /// Ethernet driver. -pub struct Ethernet<'d, T: Instance, P: PHY> { +pub struct Ethernet<'d, T: Instance, P: Phy> { _peri: PeripheralRef<'d, T>, pub(crate) tx: TDesRing<'d>, pub(crate) rx: RDesRing<'d>, @@ -63,7 +63,7 @@ macro_rules! config_pins { }; } -impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { /// Create a new RMII ethernet driver using 9 pins. pub fn new( queue: &'d mut PacketQueue, @@ -304,7 +304,7 @@ pub struct EthernetStationManagement { clock_range: u8, } -unsafe impl StationManagement for EthernetStationManagement { +impl StationManagement for EthernetStationManagement { fn smi_read(&mut self, phy_addr: u8, reg: u8) -> u16 { let mac = T::regs().ethernet_mac(); @@ -334,7 +334,7 @@ unsafe impl StationManagement for EthernetStationManagement { } } -impl<'d, T: Instance, P: PHY> Drop for Ethernet<'d, T, P> { +impl<'d, T: Instance, P: Phy> Drop for Ethernet<'d, T, P> { fn drop(&mut self) { let dma = T::regs().ethernet_dma(); let mac = T::regs().ethernet_mac(); diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index a3af8f75c..634d8e2c6 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -5,8 +5,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; @@ -21,7 +20,7 @@ bind_interrupts!(struct Irqs { HASH_RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -76,7 +75,7 @@ async fn main(spawner: Spawner) -> ! { p.PG13, p.PB13, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); diff --git a/examples/stm32f4/src/bin/eth_compliance_test.rs b/examples/stm32f4/src/bin/eth_compliance_test.rs index 5946fed79..52f9d57f6 100644 --- a/examples/stm32f4/src/bin/eth_compliance_test.rs +++ b/examples/stm32f4/src/bin/eth_compliance_test.rs @@ -3,8 +3,7 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue, StationManagement}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, StationManagement}; use embassy_stm32::time::Hertz; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; use embassy_time::Timer; @@ -59,11 +58,11 @@ async fn main(_spawner: Spawner) -> ! { p.PG13, p.PB13, p.PG11, - GenericSMI::new(PHY_ADDR), + GenericPhy::new(PHY_ADDR), mac_addr, ); - let sm = unsafe { device.station_management() }; + let sm = device.station_management(); // Just an example. Exact register settings depend on the specific PHY and test. sm.smi_write(PHY_ADDR, 0, 0x2100); diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index f353af674..17ab7fc00 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -5,8 +5,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; @@ -22,7 +21,7 @@ bind_interrupts!(struct Irqs { HASH_RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -77,7 +76,7 @@ async fn main(spawner: Spawner) -> ! { p.PG13, p.PB13, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index ead346741..4034b552c 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs @@ -5,8 +5,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rcc::{ AHBPrescaler, APBPrescaler, Hse, HseMode, Pll, PllDiv, PllMul, PllPreDiv, PllSource, Sysclk, VoltageScale, @@ -25,7 +24,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -80,7 +79,7 @@ async fn main(spawner: Spawner) -> ! { p.PG13, p.PB15, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 6665cd1d0..da7aa4af5 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -5,8 +5,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; @@ -21,7 +20,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -79,7 +78,7 @@ async fn main(spawner: Spawner) -> ! { p.PG13, // TX_D0: Transmit Bit 0 p.PB13, // TX_D1: Transmit Bit 1 p.PG11, // TX_EN: Transmit Enable - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 4fbe10f31..10485109a 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -7,8 +7,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::client::{TcpClient, TcpClientState}; use embassy_net::StackResources; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; @@ -24,7 +23,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -81,7 +80,7 @@ async fn main(spawner: Spawner) -> ! { p.PG13, p.PB13, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); diff --git a/examples/stm32h7/src/bin/eth_client_mii.rs b/examples/stm32h7/src/bin/eth_client_mii.rs index 53f86ac80..849173615 100644 --- a/examples/stm32h7/src/bin/eth_client_mii.rs +++ b/examples/stm32h7/src/bin/eth_client_mii.rs @@ -7,8 +7,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::client::{TcpClient, TcpClientState}; use embassy_net::StackResources; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; @@ -24,7 +23,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -86,7 +85,7 @@ async fn main(spawner: Spawner) -> ! { p.PC2, p.PE2, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); info!("Device created"); diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs index 4ab6e234f..a7e76fd8e 100644 --- a/tests/stm32/src/bin/eth.rs +++ b/tests/stm32/src/bin/eth.rs @@ -7,8 +7,7 @@ mod common; use common::*; use embassy_executor::Spawner; use embassy_net::StackResources; -use embassy_stm32::eth::generic_smi::GenericSMI; -use embassy_stm32::eth::{Ethernet, PacketQueue}; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::{bind_interrupts, eth, peripherals, rng}; @@ -29,7 +28,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericSMI>; +type Device = Ethernet<'static, ETH, GenericPhy>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -87,7 +86,7 @@ async fn main(spawner: Spawner) { #[cfg(feature = "stm32h563zi")] p.PB15, p.PG11, - GenericSMI::new_auto(), + GenericPhy::new_auto(), mac_addr, ); -- cgit