aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/eth
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src/eth
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (diff)
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/eth')
-rw-r--r--embassy-stm32/src/eth/mod.rs3
-rw-r--r--embassy-stm32/src/eth/v1/mod.rs48
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs112
3 files changed, 80 insertions, 83 deletions
diff --git a/embassy-stm32/src/eth/mod.rs b/embassy-stm32/src/eth/mod.rs
index 109ceeeb3..97d7b4347 100644
--- a/embassy-stm32/src/eth/mod.rs
+++ b/embassy-stm32/src/eth/mod.rs
@@ -9,6 +9,7 @@ mod generic_phy;
9use core::mem::MaybeUninit; 9use core::mem::MaybeUninit;
10use core::task::Context; 10use core::task::Context;
11 11
12use embassy_hal_internal::PeripheralType;
12use embassy_net_driver::{Capabilities, HardwareAddress, LinkState}; 13use embassy_net_driver::{Capabilities, HardwareAddress, LinkState};
13use embassy_sync::waitqueue::AtomicWaker; 14use embassy_sync::waitqueue::AtomicWaker;
14 15
@@ -199,7 +200,7 @@ trait SealedInstance {
199 200
200/// Ethernet instance. 201/// Ethernet instance.
201#[allow(private_bounds)] 202#[allow(private_bounds)]
202pub trait Instance: SealedInstance + RccPeripheral + Send + 'static {} 203pub trait Instance: SealedInstance + PeripheralType + RccPeripheral + Send + 'static {}
203 204
204impl SealedInstance for crate::peripherals::ETH { 205impl SealedInstance for crate::peripherals::ETH {
205 fn regs() -> crate::pac::eth::Eth { 206 fn regs() -> crate::pac::eth::Eth {
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs
index e12ac2fef..640191d69 100644
--- a/embassy-stm32/src/eth/v1/mod.rs
+++ b/embassy-stm32/src/eth/v1/mod.rs
@@ -6,7 +6,7 @@ mod tx_desc;
6use core::marker::PhantomData; 6use core::marker::PhantomData;
7use core::sync::atomic::{fence, Ordering}; 7use core::sync::atomic::{fence, Ordering};
8 8
9use embassy_hal_internal::{into_ref, PeripheralRef}; 9use embassy_hal_internal::Peri;
10use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; 10use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf};
11 11
12pub(crate) use self::rx_desc::{RDes, RDesRing}; 12pub(crate) use self::rx_desc::{RDes, RDesRing};
@@ -15,6 +15,7 @@ use super::*;
15#[cfg(eth_v1a)] 15#[cfg(eth_v1a)]
16use crate::gpio::Pull; 16use crate::gpio::Pull;
17use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed}; 17use crate::gpio::{AfType, AnyPin, OutputType, SealedPin, Speed};
18use crate::interrupt;
18use crate::interrupt::InterruptExt; 19use crate::interrupt::InterruptExt;
19#[cfg(eth_v1a)] 20#[cfg(eth_v1a)]
20use crate::pac::AFIO; 21use crate::pac::AFIO;
@@ -22,7 +23,6 @@ use crate::pac::AFIO;
22use crate::pac::SYSCFG; 23use crate::pac::SYSCFG;
23use crate::pac::{ETH, RCC}; 24use crate::pac::{ETH, RCC};
24use crate::rcc::SealedRccPeripheral; 25use crate::rcc::SealedRccPeripheral;
25use crate::{interrupt, Peripheral};
26 26
27/// Interrupt handler. 27/// Interrupt handler.
28pub struct InterruptHandler {} 28pub struct InterruptHandler {}
@@ -47,11 +47,11 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ETH> for InterruptHandl
47 47
48/// Ethernet driver. 48/// Ethernet driver.
49pub struct Ethernet<'d, T: Instance, P: Phy> { 49pub struct Ethernet<'d, T: Instance, P: Phy> {
50 _peri: PeripheralRef<'d, T>, 50 _peri: Peri<'d, T>,
51 pub(crate) tx: TDesRing<'d>, 51 pub(crate) tx: TDesRing<'d>,
52 pub(crate) rx: RDesRing<'d>, 52 pub(crate) rx: RDesRing<'d>,
53 53
54 pins: [PeripheralRef<'d, AnyPin>; 9], 54 pins: [Peri<'d, AnyPin>; 9],
55 pub(crate) phy: P, 55 pub(crate) phy: P,
56 pub(crate) station_management: EthernetStationManagement<T>, 56 pub(crate) station_management: EthernetStationManagement<T>,
57 pub(crate) mac_addr: [u8; 6], 57 pub(crate) mac_addr: [u8; 6],
@@ -95,22 +95,20 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
95 /// safety: the returned instance is not leak-safe 95 /// safety: the returned instance is not leak-safe
96 pub fn new<const TX: usize, const RX: usize>( 96 pub fn new<const TX: usize, const RX: usize>(
97 queue: &'d mut PacketQueue<TX, RX>, 97 queue: &'d mut PacketQueue<TX, RX>,
98 peri: impl Peripheral<P = T> + 'd, 98 peri: Peri<'d, T>,
99 _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 99 _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
100 ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, 100 ref_clk: Peri<'d, impl RefClkPin<T>>,
101 mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, 101 mdio: Peri<'d, impl MDIOPin<T>>,
102 mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, 102 mdc: Peri<'d, impl MDCPin<T>>,
103 crs: impl Peripheral<P = impl CRSPin<T>> + 'd, 103 crs: Peri<'d, impl CRSPin<T>>,
104 rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, 104 rx_d0: Peri<'d, impl RXD0Pin<T>>,
105 rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, 105 rx_d1: Peri<'d, impl RXD1Pin<T>>,
106 tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, 106 tx_d0: Peri<'d, impl TXD0Pin<T>>,
107 tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, 107 tx_d1: Peri<'d, impl TXD1Pin<T>>,
108 tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, 108 tx_en: Peri<'d, impl TXEnPin<T>>,
109 phy: P, 109 phy: P,
110 mac_addr: [u8; 6], 110 mac_addr: [u8; 6],
111 ) -> Self { 111 ) -> Self {
112 into_ref!(peri, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
113
114 // Enable the necessary Clocks 112 // Enable the necessary Clocks
115 #[cfg(eth_v1a)] 113 #[cfg(eth_v1a)]
116 critical_section::with(|_| { 114 critical_section::with(|_| {
@@ -213,15 +211,15 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
213 }; 211 };
214 212
215 let pins = [ 213 let pins = [
216 ref_clk.map_into(), 214 ref_clk.into(),
217 mdio.map_into(), 215 mdio.into(),
218 mdc.map_into(), 216 mdc.into(),
219 crs.map_into(), 217 crs.into(),
220 rx_d0.map_into(), 218 rx_d0.into(),
221 rx_d1.map_into(), 219 rx_d1.into(),
222 tx_d0.map_into(), 220 tx_d0.into(),
223 tx_d1.map_into(), 221 tx_d1.into(),
224 tx_en.map_into(), 222 tx_en.into(),
225 ]; 223 ];
226 224
227 let mut this = Self { 225 let mut this = Self {
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index 26e4eeb63..034c5dd88 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -3,16 +3,16 @@ mod descriptors;
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4use core::sync::atomic::{fence, Ordering}; 4use core::sync::atomic::{fence, Ordering};
5 5
6use embassy_hal_internal::{into_ref, PeripheralRef}; 6use embassy_hal_internal::Peri;
7use stm32_metapac::syscfg::vals::EthSelPhy; 7use stm32_metapac::syscfg::vals::EthSelPhy;
8 8
9pub(crate) use self::descriptors::{RDes, RDesRing, TDes, TDesRing}; 9pub(crate) use self::descriptors::{RDes, RDesRing, TDes, TDesRing};
10use super::*; 10use super::*;
11use crate::gpio::{AfType, AnyPin, OutputType, SealedPin as _, Speed}; 11use crate::gpio::{AfType, AnyPin, OutputType, SealedPin as _, Speed};
12use crate::interrupt;
12use crate::interrupt::InterruptExt; 13use crate::interrupt::InterruptExt;
13use crate::pac::ETH; 14use crate::pac::ETH;
14use crate::rcc::SealedRccPeripheral; 15use crate::rcc::SealedRccPeripheral;
15use crate::{interrupt, Peripheral};
16 16
17/// Interrupt handler. 17/// Interrupt handler.
18pub struct InterruptHandler {} 18pub struct InterruptHandler {}
@@ -37,7 +37,7 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ETH> for InterruptHandl
37 37
38/// Ethernet driver. 38/// Ethernet driver.
39pub struct Ethernet<'d, T: Instance, P: Phy> { 39pub struct Ethernet<'d, T: Instance, P: Phy> {
40 _peri: PeripheralRef<'d, T>, 40 _peri: Peri<'d, T>,
41 pub(crate) tx: TDesRing<'d>, 41 pub(crate) tx: TDesRing<'d>,
42 pub(crate) rx: RDesRing<'d>, 42 pub(crate) rx: RDesRing<'d>,
43 pins: Pins<'d>, 43 pins: Pins<'d>,
@@ -48,8 +48,8 @@ pub struct Ethernet<'d, T: Instance, P: Phy> {
48 48
49/// Pins of ethernet driver. 49/// Pins of ethernet driver.
50enum Pins<'d> { 50enum Pins<'d> {
51 Rmii([PeripheralRef<'d, AnyPin>; 9]), 51 Rmii([Peri<'d, AnyPin>; 9]),
52 Mii([PeripheralRef<'d, AnyPin>; 14]), 52 Mii([Peri<'d, AnyPin>; 14]),
53} 53}
54 54
55macro_rules! config_pins { 55macro_rules! config_pins {
@@ -67,17 +67,17 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
67 /// Create a new RMII ethernet driver using 9 pins. 67 /// Create a new RMII ethernet driver using 9 pins.
68 pub fn new<const TX: usize, const RX: usize>( 68 pub fn new<const TX: usize, const RX: usize>(
69 queue: &'d mut PacketQueue<TX, RX>, 69 queue: &'d mut PacketQueue<TX, RX>,
70 peri: impl Peripheral<P = T> + 'd, 70 peri: Peri<'d, T>,
71 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 71 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
72 ref_clk: impl Peripheral<P = impl RefClkPin<T>> + 'd, 72 ref_clk: Peri<'d, impl RefClkPin<T>>,
73 mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, 73 mdio: Peri<'d, impl MDIOPin<T>>,
74 mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, 74 mdc: Peri<'d, impl MDCPin<T>>,
75 crs: impl Peripheral<P = impl CRSPin<T>> + 'd, 75 crs: Peri<'d, impl CRSPin<T>>,
76 rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, 76 rx_d0: Peri<'d, impl RXD0Pin<T>>,
77 rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, 77 rx_d1: Peri<'d, impl RXD1Pin<T>>,
78 tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, 78 tx_d0: Peri<'d, impl TXD0Pin<T>>,
79 tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, 79 tx_d1: Peri<'d, impl TXD1Pin<T>>,
80 tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, 80 tx_en: Peri<'d, impl TXEnPin<T>>,
81 phy: P, 81 phy: P,
82 mac_addr: [u8; 6], 82 mac_addr: [u8; 6],
83 ) -> Self { 83 ) -> Self {
@@ -92,19 +92,18 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
92 crate::pac::SYSCFG.pmcr().modify(|w| w.set_eth_sel_phy(EthSelPhy::RMII)); 92 crate::pac::SYSCFG.pmcr().modify(|w| w.set_eth_sel_phy(EthSelPhy::RMII));
93 }); 93 });
94 94
95 into_ref!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
96 config_pins!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); 95 config_pins!(ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en);
97 96
98 let pins = Pins::Rmii([ 97 let pins = Pins::Rmii([
99 ref_clk.map_into(), 98 ref_clk.into(),
100 mdio.map_into(), 99 mdio.into(),
101 mdc.map_into(), 100 mdc.into(),
102 crs.map_into(), 101 crs.into(),
103 rx_d0.map_into(), 102 rx_d0.into(),
104 rx_d1.map_into(), 103 rx_d1.into(),
105 tx_d0.map_into(), 104 tx_d0.into(),
106 tx_d1.map_into(), 105 tx_d1.into(),
107 tx_en.map_into(), 106 tx_en.into(),
108 ]); 107 ]);
109 108
110 Self::new_inner(queue, peri, irq, pins, phy, mac_addr) 109 Self::new_inner(queue, peri, irq, pins, phy, mac_addr)
@@ -113,22 +112,22 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
113 /// Create a new MII ethernet driver using 14 pins. 112 /// Create a new MII ethernet driver using 14 pins.
114 pub fn new_mii<const TX: usize, const RX: usize>( 113 pub fn new_mii<const TX: usize, const RX: usize>(
115 queue: &'d mut PacketQueue<TX, RX>, 114 queue: &'d mut PacketQueue<TX, RX>,
116 peri: impl Peripheral<P = T> + 'd, 115 peri: Peri<'d, T>,
117 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 116 irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
118 rx_clk: impl Peripheral<P = impl RXClkPin<T>> + 'd, 117 rx_clk: Peri<'d, impl RXClkPin<T>>,
119 tx_clk: impl Peripheral<P = impl TXClkPin<T>> + 'd, 118 tx_clk: Peri<'d, impl TXClkPin<T>>,
120 mdio: impl Peripheral<P = impl MDIOPin<T>> + 'd, 119 mdio: Peri<'d, impl MDIOPin<T>>,
121 mdc: impl Peripheral<P = impl MDCPin<T>> + 'd, 120 mdc: Peri<'d, impl MDCPin<T>>,
122 rxdv: impl Peripheral<P = impl RXDVPin<T>> + 'd, 121 rxdv: Peri<'d, impl RXDVPin<T>>,
123 rx_d0: impl Peripheral<P = impl RXD0Pin<T>> + 'd, 122 rx_d0: Peri<'d, impl RXD0Pin<T>>,
124 rx_d1: impl Peripheral<P = impl RXD1Pin<T>> + 'd, 123 rx_d1: Peri<'d, impl RXD1Pin<T>>,
125 rx_d2: impl Peripheral<P = impl RXD2Pin<T>> + 'd, 124 rx_d2: Peri<'d, impl RXD2Pin<T>>,
126 rx_d3: impl Peripheral<P = impl RXD3Pin<T>> + 'd, 125 rx_d3: Peri<'d, impl RXD3Pin<T>>,
127 tx_d0: impl Peripheral<P = impl TXD0Pin<T>> + 'd, 126 tx_d0: Peri<'d, impl TXD0Pin<T>>,
128 tx_d1: impl Peripheral<P = impl TXD1Pin<T>> + 'd, 127 tx_d1: Peri<'d, impl TXD1Pin<T>>,
129 tx_d2: impl Peripheral<P = impl TXD2Pin<T>> + 'd, 128 tx_d2: Peri<'d, impl TXD2Pin<T>>,
130 tx_d3: impl Peripheral<P = impl TXD3Pin<T>> + 'd, 129 tx_d3: Peri<'d, impl TXD3Pin<T>>,
131 tx_en: impl Peripheral<P = impl TXEnPin<T>> + 'd, 130 tx_en: Peri<'d, impl TXEnPin<T>>,
132 phy: P, 131 phy: P,
133 mac_addr: [u8; 6], 132 mac_addr: [u8; 6],
134 ) -> Self { 133 ) -> Self {
@@ -145,24 +144,23 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
145 .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII)); 144 .modify(|w| w.set_eth_sel_phy(EthSelPhy::MII_GMII));
146 }); 145 });
147 146
148 into_ref!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en);
149 config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en); 147 config_pins!(rx_clk, tx_clk, mdio, mdc, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en);
150 148
151 let pins = Pins::Mii([ 149 let pins = Pins::Mii([
152 rx_clk.map_into(), 150 rx_clk.into(),
153 tx_clk.map_into(), 151 tx_clk.into(),
154 mdio.map_into(), 152 mdio.into(),
155 mdc.map_into(), 153 mdc.into(),
156 rxdv.map_into(), 154 rxdv.into(),
157 rx_d0.map_into(), 155 rx_d0.into(),
158 rx_d1.map_into(), 156 rx_d1.into(),
159 rx_d2.map_into(), 157 rx_d2.into(),
160 rx_d3.map_into(), 158 rx_d3.into(),
161 tx_d0.map_into(), 159 tx_d0.into(),
162 tx_d1.map_into(), 160 tx_d1.into(),
163 tx_d2.map_into(), 161 tx_d2.into(),
164 tx_d3.map_into(), 162 tx_d3.into(),
165 tx_en.map_into(), 163 tx_en.into(),
166 ]); 164 ]);
167 165
168 Self::new_inner(queue, peri, irq, pins, phy, mac_addr) 166 Self::new_inner(queue, peri, irq, pins, phy, mac_addr)
@@ -170,7 +168,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
170 168
171 fn new_inner<const TX: usize, const RX: usize>( 169 fn new_inner<const TX: usize, const RX: usize>(
172 queue: &'d mut PacketQueue<TX, RX>, 170 queue: &'d mut PacketQueue<TX, RX>,
173 peri: impl Peripheral<P = T> + 'd, 171 peri: Peri<'d, T>,
174 _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, 172 _irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd,
175 pins: Pins<'d>, 173 pins: Pins<'d>,
176 phy: P, 174 phy: P,
@@ -254,7 +252,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> {
254 }; 252 };
255 253
256 let mut this = Self { 254 let mut this = Self {
257 _peri: peri.into_ref(), 255 _peri: peri,
258 tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf), 256 tx: TDesRing::new(&mut queue.tx_desc, &mut queue.tx_buf),
259 rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf), 257 rx: RDesRing::new(&mut queue.rx_desc, &mut queue.rx_buf),
260 pins, 258 pins,