From 0b3bc35b7dc0f3d2ffa1673ab790df8e6650fe0f Mon Sep 17 00:00:00 2001 From: datdenkikniet Date: Thu, 13 Nov 2025 23:00:58 +0100 Subject: Add new{_with_phy}, new_mii{_with_phy} --- embassy-stm32/src/eth/generic_phy.rs | 5 ++ embassy-stm32/src/eth/v1/mod.rs | 80 +++++++++++++++++++++++-- embassy-stm32/src/eth/v2/mod.rs | 78 ++++++++++++++++++++++-- examples/stm32f4/src/bin/eth.rs | 12 ++-- examples/stm32f4/src/bin/eth_compliance_test.rs | 12 ++-- examples/stm32f7/src/bin/eth.rs | 12 ++-- examples/stm32h5/src/bin/eth.rs | 12 ++-- examples/stm32h7/src/bin/eth.rs | 12 ++-- examples/stm32h7/src/bin/eth_client.rs | 12 ++-- examples/stm32h7/src/bin/eth_client_mii.rs | 12 ++-- examples/stm32h7rs/src/bin/eth.rs | 12 ++-- tests/stm32/src/bin/eth.rs | 7 +-- 12 files changed, 206 insertions(+), 60 deletions(-) diff --git a/embassy-stm32/src/eth/generic_phy.rs b/embassy-stm32/src/eth/generic_phy.rs index 4e61a83e7..0a5f41de0 100644 --- a/embassy-stm32/src/eth/generic_phy.rs +++ b/embassy-stm32/src/eth/generic_phy.rs @@ -153,4 +153,9 @@ impl GenericPhy { self.sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x4003); // set data self.sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_data); } + + /// Access the underlying station management. + pub fn station_management(&mut self) -> &mut SM { + &mut self.sm + } } diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 8b04b74c4..8de26ce9d 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -94,7 +94,15 @@ macro_rules! config_pins { }; } -impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { +impl<'d, T: Instance, SMA: sma::Instance> Ethernet<'d, T, GenericPhy>> { + /// Create a new RMII ethernet driver using 7 pins. + /// + /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the + /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. + /// + /// See [`Ethernet::new_with_phy`] for creating an RMII ethernet + /// river with a non-standard PHY. + /// /// safety: the returned instance is not leak-safe pub fn new( queue: &'d mut PacketQueue, @@ -107,8 +115,72 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { tx_d0: Peri<'d, if_afio!(impl TXD0Pin)>, tx_d1: Peri<'d, if_afio!(impl TXD1Pin)>, tx_en: Peri<'d, if_afio!(impl TXEnPin)>, - phy: P, mac_addr: [u8; 6], + sma: Peri<'d, SMA>, + mdio: Peri<'d, if_afio!(impl MDIOPin)>, + mdc: Peri<'d, if_afio!(impl MDCPin)>, + ) -> Self { + let sma = Sma::new(sma, mdio, mdc); + let phy = GenericPhy::new_auto(sma); + + Self::new_with_phy( + queue, peri, irq, ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en, mac_addr, phy, + ) + } + + /// Create a new MII ethernet driver using 14 pins. + /// + /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the + /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. + /// + /// See [`Ethernet::new_mii_with_phy`] for creating an RMII ethernet + /// river with a non-standard PHY. + pub fn new_mii( + queue: &'d mut PacketQueue, + peri: Peri<'d, T>, + irq: impl interrupt::typelevel::Binding + 'd, + rx_clk: Peri<'d, if_afio!(impl RXClkPin)>, + tx_clk: Peri<'d, if_afio!(impl TXClkPin)>, + rxdv: Peri<'d, if_afio!(impl RXDVPin)>, + rx_d0: Peri<'d, if_afio!(impl RXD0Pin)>, + rx_d1: Peri<'d, if_afio!(impl RXD1Pin)>, + rx_d2: Peri<'d, if_afio!(impl RXD2Pin)>, + rx_d3: Peri<'d, if_afio!(impl RXD3Pin)>, + tx_d0: Peri<'d, if_afio!(impl TXD0Pin)>, + tx_d1: Peri<'d, if_afio!(impl TXD1Pin)>, + tx_d2: Peri<'d, if_afio!(impl TXD2Pin)>, + tx_d3: Peri<'d, if_afio!(impl TXD3Pin)>, + tx_en: Peri<'d, if_afio!(impl TXEnPin)>, + mac_addr: [u8; 6], + sma: Peri<'d, SMA>, + mdio: Peri<'d, if_afio!(impl MDIOPin)>, + mdc: Peri<'d, if_afio!(impl MDCPin)>, + ) -> Self { + let sma = Sma::new(sma, mdio, mdc); + let phy = GenericPhy::new_auto(sma); + + Self::new_mii_with_phy( + queue, peri, irq, rx_clk, tx_clk, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en, + mac_addr, phy, + ) + } +} + +impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { + /// safety: the returned instance is not leak-safe + pub fn new_with_phy( + queue: &'d mut PacketQueue, + peri: Peri<'d, T>, + irq: impl interrupt::typelevel::Binding + 'd, + ref_clk: Peri<'d, if_afio!(impl RefClkPin)>, + crs: Peri<'d, if_afio!(impl CRSPin)>, + rx_d0: Peri<'d, if_afio!(impl RXD0Pin)>, + rx_d1: Peri<'d, if_afio!(impl RXD1Pin)>, + tx_d0: Peri<'d, if_afio!(impl TXD0Pin)>, + tx_d1: Peri<'d, if_afio!(impl TXD1Pin)>, + tx_en: Peri<'d, if_afio!(impl TXEnPin)>, + mac_addr: [u8; 6], + phy: P, ) -> Self { #[cfg(eth_v1a)] { @@ -263,7 +335,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { } /// Create a new MII ethernet driver using 12 pins. - pub fn new_mii( + pub fn new_mii_with_phy( queue: &'d mut PacketQueue, peri: Peri<'d, T>, irq: impl interrupt::typelevel::Binding + 'd, @@ -279,8 +351,8 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { tx_d2: Peri<'d, if_afio!(impl TXD2Pin)>, tx_d3: Peri<'d, if_afio!(impl TXD3Pin)>, tx_en: Peri<'d, if_afio!(impl TXEnPin)>, - phy: P, mac_addr: [u8; 6], + phy: P, ) -> Self { #[cfg(eth_v1a)] { diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 05ecee5ba..7f92e351c 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -60,8 +60,14 @@ macro_rules! config_pins { }; } -impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { +impl<'d, T: Instance, SMA: sma::Instance> Ethernet<'d, T, GenericPhy>> { /// Create a new RMII ethernet driver using 7 pins. + /// + /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the + /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. + /// + /// See [`Ethernet::new_with_phy`] for creating an RMII ethernet + /// river with a non-standard PHY. pub fn new( queue: &'d mut PacketQueue, peri: Peri<'d, T>, @@ -73,8 +79,72 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { tx_d0: Peri<'d, impl TXD0Pin>, tx_d1: Peri<'d, impl TXD1Pin>, tx_en: Peri<'d, impl TXEnPin>, - phy: P, mac_addr: [u8; 6], + sma: Peri<'d, SMA>, + mdio: Peri<'d, impl MDIOPin>, + mdc: Peri<'d, impl MDCPin>, + ) -> Self { + let sma = Sma::new(sma, mdio, mdc); + let phy = GenericPhy::new_auto(sma); + + Self::new_with_phy( + queue, peri, irq, ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en, mac_addr, phy, + ) + } + + /// Create a new MII ethernet driver using 14 pins. + /// + /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the + /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. + /// + /// See [`Ethernet::new_mii_with_phy`] for creating an RMII ethernet + /// river with a non-standard PHY. + pub fn new_mii( + queue: &'d mut PacketQueue, + peri: Peri<'d, T>, + irq: impl interrupt::typelevel::Binding + 'd, + rx_clk: Peri<'d, impl RXClkPin>, + tx_clk: Peri<'d, impl TXClkPin>, + rxdv: Peri<'d, impl RXDVPin>, + rx_d0: Peri<'d, impl RXD0Pin>, + rx_d1: Peri<'d, impl RXD1Pin>, + rx_d2: Peri<'d, impl RXD2Pin>, + rx_d3: Peri<'d, impl RXD3Pin>, + tx_d0: Peri<'d, impl TXD0Pin>, + tx_d1: Peri<'d, impl TXD1Pin>, + tx_d2: Peri<'d, impl TXD2Pin>, + tx_d3: Peri<'d, impl TXD3Pin>, + tx_en: Peri<'d, impl TXEnPin>, + mac_addr: [u8; 6], + sma: Peri<'d, SMA>, + mdio: Peri<'d, impl MDIOPin>, + mdc: Peri<'d, impl MDCPin>, + ) -> Self { + let sma = Sma::new(sma, mdio, mdc); + let phy = GenericPhy::new_auto(sma); + + Self::new_mii_with_phy( + queue, peri, irq, rx_clk, tx_clk, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en, + mac_addr, phy, + ) + } +} + +impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { + /// Create a new RMII ethernet driver using 7 pins. + pub fn new_with_phy( + queue: &'d mut PacketQueue, + peri: Peri<'d, T>, + irq: impl interrupt::typelevel::Binding + 'd, + ref_clk: Peri<'d, impl RefClkPin>, + crs: Peri<'d, impl CRSPin>, + rx_d0: Peri<'d, impl RXD0Pin>, + rx_d1: Peri<'d, impl RXD1Pin>, + tx_d0: Peri<'d, impl TXD0Pin>, + tx_d1: Peri<'d, impl TXD1Pin>, + tx_en: Peri<'d, impl TXEnPin>, + mac_addr: [u8; 6], + phy: P, ) -> Self { config_pins!(ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); @@ -92,7 +162,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { } /// Create a new MII ethernet driver using 12 pins. - pub fn new_mii( + pub fn new_mii_with_phy( queue: &'d mut PacketQueue, peri: Peri<'d, T>, irq: impl interrupt::typelevel::Binding + 'd, @@ -108,8 +178,8 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { tx_d2: Peri<'d, impl TXD2Pin>, tx_d3: Peri<'d, impl TXD3Pin>, tx_en: Peri<'d, impl TXEnPin>, - phy: P, mac_addr: [u8; 6], + phy: P, ) -> Self { config_pins!( rx_clk, tx_clk, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 2d72b6b0b..8dfa0916d 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs @@ -5,8 +5,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; @@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs { HASH_RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -67,16 +67,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PA1, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, p.PG13, p.PB13, p.PG11, - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); let config = embassy_net::Config::dhcpv4(Default::default()); diff --git a/examples/stm32f4/src/bin/eth_compliance_test.rs b/examples/stm32f4/src/bin/eth_compliance_test.rs index 734a14c2c..dc5d7dbb6 100644 --- a/examples/stm32f4/src/bin/eth_compliance_test.rs +++ b/examples/stm32f4/src/bin/eth_compliance_test.rs @@ -3,7 +3,7 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, StationManagement}; +use embassy_stm32::eth::{Ethernet, PacketQueue, StationManagement}; use embassy_stm32::time::Hertz; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; use embassy_time::Timer; @@ -43,27 +43,27 @@ async fn main(_spawner: Spawner) -> ! { let mac_addr = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF]; - const PHY_ADDR: u8 = 0; static PACKETS: StaticCell> = StaticCell::new(); let mut device = Ethernet::new( PACKETS.init(PacketQueue::<4, 4>::new()), p.ETH, Irqs, p.PA1, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, p.PG13, p.PB13, p.PG11, - GenericPhy::new(PHY_ADDR), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); - let sm = device.station_management(); + let sm = device.phy_mut().station_management(); + const PHY_ADDR: u8 = 0; // Just an example. Exact register settings depend on the specific PHY and test. sm.smi_write(PHY_ADDR, 0, 0x2100); sm.smi_write(PHY_ADDR, 11, 0xA000); diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index f8a129239..8613376b8 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -5,8 +5,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; @@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs { HASH_RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -67,16 +67,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PA1, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, p.PG13, p.PB13, p.PG11, - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); let config = embassy_net::Config::dhcpv4(Default::default()); diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs index a5c6cee26..6a3afb2d1 100644 --- a/examples/stm32h5/src/bin/eth.rs +++ b/examples/stm32h5/src/bin/eth.rs @@ -5,8 +5,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rcc::{ AHBPrescaler, APBPrescaler, Hse, HseMode, Pll, PllDiv, PllMul, PllPreDiv, PllSource, Sysclk, VoltageScale, }; @@ -23,7 +23,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -70,16 +70,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PA1, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, p.PG13, p.PB15, p.PG11, - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); let config = embassy_net::Config::dhcpv4(Default::default()); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 589f4426e..09915799b 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -5,8 +5,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::tcp::TcpSocket; use embassy_net::{Ipv4Address, StackResources}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; use embassy_time::Timer; @@ -19,7 +19,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -69,16 +69,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PA1, // ref_clk - p.PA2, // mdio - p.PC1, // eth_mdc p.PA7, // CRS_DV: Carrier Sense p.PC4, // RX_D0: Received Bit 0 p.PC5, // RX_D1: Received Bit 1 p.PG13, // TX_D0: Transmit Bit 0 p.PB13, // TX_D1: Transmit Bit 1 p.PG11, // TX_EN: Transmit Enable - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, // mdio + p.PC1, // mdc ); let config = embassy_net::Config::dhcpv4(Default::default()); diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index fed8f1a9c..189c99686 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -7,8 +7,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::StackResources; use embassy_net::tcp::client::{TcpClient, TcpClientState}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; use embassy_time::Timer; @@ -22,7 +22,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -71,16 +71,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PA1, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, p.PG13, p.PB13, p.PG11, - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); let config = embassy_net::Config::dhcpv4(Default::default()); diff --git a/examples/stm32h7/src/bin/eth_client_mii.rs b/examples/stm32h7/src/bin/eth_client_mii.rs index c3c631f0f..92c823567 100644 --- a/examples/stm32h7/src/bin/eth_client_mii.rs +++ b/examples/stm32h7/src/bin/eth_client_mii.rs @@ -7,8 +7,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::StackResources; use embassy_net::tcp::client::{TcpClient, TcpClientState}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; use embassy_time::Timer; @@ -22,7 +22,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -72,8 +72,6 @@ async fn main(spawner: Spawner) -> ! { Irqs, p.PA1, p.PC3, - p.PA2, - p.PC1, p.PA7, p.PC4, p.PC5, @@ -84,8 +82,10 @@ async fn main(spawner: Spawner) -> ! { p.PC2, p.PE2, p.PG11, - GenericPhy::new_auto(), mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); info!("Device created"); diff --git a/examples/stm32h7rs/src/bin/eth.rs b/examples/stm32h7rs/src/bin/eth.rs index 5ce1d4765..8e07d0a67 100644 --- a/examples/stm32h7rs/src/bin/eth.rs +++ b/examples/stm32h7rs/src/bin/eth.rs @@ -5,8 +5,8 @@ use defmt::*; use embassy_executor::Spawner; use embassy_net::udp::{PacketMetadata, UdpSocket}; use embassy_net::{Ipv4Address, Ipv4Cidr, StackResources}; -use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue}; -use embassy_stm32::peripherals::ETH; +use embassy_stm32::eth::{Ethernet, GenericPhy, PacketQueue, Sma}; +use embassy_stm32::peripherals::{ETH, ETH_SMA}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, bind_interrupts, eth, peripherals, rng}; use embassy_time::Timer; @@ -19,7 +19,7 @@ bind_interrupts!(struct Irqs { RNG => rng::InterruptHandler; }); -type Device = Ethernet<'static, ETH, GenericPhy>; +type Device = Ethernet<'static, ETH, GenericPhy>>; #[embassy_executor::task] async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! { @@ -69,16 +69,16 @@ async fn main(spawner: Spawner) -> ! { p.ETH, Irqs, p.PB6, - p.PA2, - p.PG6, p.PA7, p.PG4, p.PG5, p.PG13, p.PG12, p.PG11, - GenericPhy::new(0), mac_addr, + p.ETH_SMA, + p.PA2, + p.PG6, ); // Have to use UDP w/ static config to fit in internal flash diff --git a/tests/stm32/src/bin/eth.rs b/tests/stm32/src/bin/eth.rs index 95789ffc5..ffc76b96f 100644 --- a/tests/stm32/src/bin/eth.rs +++ b/tests/stm32/src/bin/eth.rs @@ -70,9 +70,6 @@ async fn main(spawner: Spawner) { static PACKETS: StaticCell> = StaticCell::new(); - let sma = Sma::new(p.ETH_SMA, p.PA2, p.PC1); - let phy = GenericPhy::new_auto(sma); - let device = Ethernet::new( PACKETS.init(PacketQueue::::new()), p.ETH, @@ -87,8 +84,10 @@ async fn main(spawner: Spawner) { #[cfg(feature = "stm32h563zi")] p.PB15, p.PG11, - phy, mac_addr, + p.ETH_SMA, + p.PA2, + p.PC1, ); let config = embassy_net::Config::dhcpv4(Default::default()); -- cgit