diff options
| author | datdenkikniet <[email protected]> | 2025-11-13 23:00:58 +0100 |
|---|---|---|
| committer | Johannes Cornelis Draaijer <[email protected]> | 2025-11-14 14:08:06 +0100 |
| commit | 0b3bc35b7dc0f3d2ffa1673ab790df8e6650fe0f (patch) | |
| tree | 71b02b007385bcca6b96d8eb13169bf27551ebe1 /embassy-stm32/src/eth | |
| parent | 694249487cd592a0f806aab61b28534e33c1c5f0 (diff) | |
Add new{_with_phy}, new_mii{_with_phy}
Diffstat (limited to 'embassy-stm32/src/eth')
| -rw-r--r-- | embassy-stm32/src/eth/generic_phy.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/eth/v1/mod.rs | 80 | ||||
| -rw-r--r-- | embassy-stm32/src/eth/v2/mod.rs | 78 |
3 files changed, 155 insertions, 8 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<SM: StationManagement> GenericPhy<SM> { | |||
| 153 | self.sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x4003); // set data | 153 | self.sm.smi_write(self.phy_addr, PHY_REG_CTL, 0x4003); // set data |
| 154 | self.sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_data); | 154 | self.sm.smi_write(self.phy_addr, PHY_REG_ADDAR, reg_data); |
| 155 | } | 155 | } |
| 156 | |||
| 157 | /// Access the underlying station management. | ||
| 158 | pub fn station_management(&mut self) -> &mut SM { | ||
| 159 | &mut self.sm | ||
| 160 | } | ||
| 156 | } | 161 | } |
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 { | |||
| 94 | }; | 94 | }; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | 97 | impl<'d, T: Instance, SMA: sma::Instance> Ethernet<'d, T, GenericPhy<Sma<'d, SMA>>> { |
| 98 | /// Create a new RMII ethernet driver using 7 pins. | ||
| 99 | /// | ||
| 100 | /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the | ||
| 101 | /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. | ||
| 102 | /// | ||
| 103 | /// See [`Ethernet::new_with_phy`] for creating an RMII ethernet | ||
| 104 | /// river with a non-standard PHY. | ||
| 105 | /// | ||
| 98 | /// safety: the returned instance is not leak-safe | 106 | /// safety: the returned instance is not leak-safe |
| 99 | pub fn new<const TX: usize, const RX: usize, #[cfg(afio)] A>( | 107 | pub fn new<const TX: usize, const RX: usize, #[cfg(afio)] A>( |
| 100 | queue: &'d mut PacketQueue<TX, RX>, | 108 | queue: &'d mut PacketQueue<TX, RX>, |
| @@ -107,8 +115,72 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 107 | tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>, | 115 | tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>, |
| 108 | tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>, | 116 | tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>, |
| 109 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, | 117 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, |
| 110 | phy: P, | ||
| 111 | mac_addr: [u8; 6], | 118 | mac_addr: [u8; 6], |
| 119 | sma: Peri<'d, SMA>, | ||
| 120 | mdio: Peri<'d, if_afio!(impl MDIOPin<SMA, A>)>, | ||
| 121 | mdc: Peri<'d, if_afio!(impl MDCPin<SMA, A>)>, | ||
| 122 | ) -> Self { | ||
| 123 | let sma = Sma::new(sma, mdio, mdc); | ||
| 124 | let phy = GenericPhy::new_auto(sma); | ||
| 125 | |||
| 126 | Self::new_with_phy( | ||
| 127 | queue, peri, irq, ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en, mac_addr, phy, | ||
| 128 | ) | ||
| 129 | } | ||
| 130 | |||
| 131 | /// Create a new MII ethernet driver using 14 pins. | ||
| 132 | /// | ||
| 133 | /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the | ||
| 134 | /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. | ||
| 135 | /// | ||
| 136 | /// See [`Ethernet::new_mii_with_phy`] for creating an RMII ethernet | ||
| 137 | /// river with a non-standard PHY. | ||
| 138 | pub fn new_mii<const TX: usize, const RX: usize, #[cfg(afio)] A>( | ||
| 139 | queue: &'d mut PacketQueue<TX, RX>, | ||
| 140 | peri: Peri<'d, T>, | ||
| 141 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | ||
| 142 | rx_clk: Peri<'d, if_afio!(impl RXClkPin<T, A>)>, | ||
| 143 | tx_clk: Peri<'d, if_afio!(impl TXClkPin<T, A>)>, | ||
| 144 | rxdv: Peri<'d, if_afio!(impl RXDVPin<T, A>)>, | ||
| 145 | rx_d0: Peri<'d, if_afio!(impl RXD0Pin<T, A>)>, | ||
| 146 | rx_d1: Peri<'d, if_afio!(impl RXD1Pin<T, A>)>, | ||
| 147 | rx_d2: Peri<'d, if_afio!(impl RXD2Pin<T, A>)>, | ||
| 148 | rx_d3: Peri<'d, if_afio!(impl RXD3Pin<T, A>)>, | ||
| 149 | tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>, | ||
| 150 | tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>, | ||
| 151 | tx_d2: Peri<'d, if_afio!(impl TXD2Pin<T, A>)>, | ||
| 152 | tx_d3: Peri<'d, if_afio!(impl TXD3Pin<T, A>)>, | ||
| 153 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, | ||
| 154 | mac_addr: [u8; 6], | ||
| 155 | sma: Peri<'d, SMA>, | ||
| 156 | mdio: Peri<'d, if_afio!(impl MDIOPin<SMA, A>)>, | ||
| 157 | mdc: Peri<'d, if_afio!(impl MDCPin<SMA, A>)>, | ||
| 158 | ) -> Self { | ||
| 159 | let sma = Sma::new(sma, mdio, mdc); | ||
| 160 | let phy = GenericPhy::new_auto(sma); | ||
| 161 | |||
| 162 | Self::new_mii_with_phy( | ||
| 163 | 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, | ||
| 164 | mac_addr, phy, | ||
| 165 | ) | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | ||
| 170 | /// safety: the returned instance is not leak-safe | ||
| 171 | pub fn new_with_phy<const TX: usize, const RX: usize, #[cfg(afio)] A>( | ||
| 172 | queue: &'d mut PacketQueue<TX, RX>, | ||
| 173 | peri: Peri<'d, T>, | ||
| 174 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | ||
| 175 | ref_clk: Peri<'d, if_afio!(impl RefClkPin<T, A>)>, | ||
| 176 | crs: Peri<'d, if_afio!(impl CRSPin<T, A>)>, | ||
| 177 | rx_d0: Peri<'d, if_afio!(impl RXD0Pin<T, A>)>, | ||
| 178 | rx_d1: Peri<'d, if_afio!(impl RXD1Pin<T, A>)>, | ||
| 179 | tx_d0: Peri<'d, if_afio!(impl TXD0Pin<T, A>)>, | ||
| 180 | tx_d1: Peri<'d, if_afio!(impl TXD1Pin<T, A>)>, | ||
| 181 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, | ||
| 182 | mac_addr: [u8; 6], | ||
| 183 | phy: P, | ||
| 112 | ) -> Self { | 184 | ) -> Self { |
| 113 | #[cfg(eth_v1a)] | 185 | #[cfg(eth_v1a)] |
| 114 | { | 186 | { |
| @@ -263,7 +335,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 263 | } | 335 | } |
| 264 | 336 | ||
| 265 | /// Create a new MII ethernet driver using 12 pins. | 337 | /// Create a new MII ethernet driver using 12 pins. |
| 266 | pub fn new_mii<const TX: usize, const RX: usize, #[cfg(afio)] A>( | 338 | pub fn new_mii_with_phy<const TX: usize, const RX: usize, #[cfg(afio)] A>( |
| 267 | queue: &'d mut PacketQueue<TX, RX>, | 339 | queue: &'d mut PacketQueue<TX, RX>, |
| 268 | peri: Peri<'d, T>, | 340 | peri: Peri<'d, T>, |
| 269 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 341 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| @@ -279,8 +351,8 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 279 | tx_d2: Peri<'d, if_afio!(impl TXD2Pin<T, A>)>, | 351 | tx_d2: Peri<'d, if_afio!(impl TXD2Pin<T, A>)>, |
| 280 | tx_d3: Peri<'d, if_afio!(impl TXD3Pin<T, A>)>, | 352 | tx_d3: Peri<'d, if_afio!(impl TXD3Pin<T, A>)>, |
| 281 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, | 353 | tx_en: Peri<'d, if_afio!(impl TXEnPin<T, A>)>, |
| 282 | phy: P, | ||
| 283 | mac_addr: [u8; 6], | 354 | mac_addr: [u8; 6], |
| 355 | phy: P, | ||
| 284 | ) -> Self { | 356 | ) -> Self { |
| 285 | #[cfg(eth_v1a)] | 357 | #[cfg(eth_v1a)] |
| 286 | { | 358 | { |
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 { | |||
| 60 | }; | 60 | }; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | 63 | impl<'d, T: Instance, SMA: sma::Instance> Ethernet<'d, T, GenericPhy<Sma<'d, SMA>>> { |
| 64 | /// Create a new RMII ethernet driver using 7 pins. | 64 | /// Create a new RMII ethernet driver using 7 pins. |
| 65 | /// | ||
| 66 | /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the | ||
| 67 | /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. | ||
| 68 | /// | ||
| 69 | /// See [`Ethernet::new_with_phy`] for creating an RMII ethernet | ||
| 70 | /// river with a non-standard PHY. | ||
| 65 | pub fn new<const TX: usize, const RX: usize>( | 71 | pub fn new<const TX: usize, const RX: usize>( |
| 66 | queue: &'d mut PacketQueue<TX, RX>, | 72 | queue: &'d mut PacketQueue<TX, RX>, |
| 67 | peri: Peri<'d, T>, | 73 | peri: Peri<'d, T>, |
| @@ -73,8 +79,72 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 73 | tx_d0: Peri<'d, impl TXD0Pin<T>>, | 79 | tx_d0: Peri<'d, impl TXD0Pin<T>>, |
| 74 | tx_d1: Peri<'d, impl TXD1Pin<T>>, | 80 | tx_d1: Peri<'d, impl TXD1Pin<T>>, |
| 75 | tx_en: Peri<'d, impl TXEnPin<T>>, | 81 | tx_en: Peri<'d, impl TXEnPin<T>>, |
| 76 | phy: P, | ||
| 77 | mac_addr: [u8; 6], | 82 | mac_addr: [u8; 6], |
| 83 | sma: Peri<'d, SMA>, | ||
| 84 | mdio: Peri<'d, impl MDIOPin<SMA>>, | ||
| 85 | mdc: Peri<'d, impl MDCPin<SMA>>, | ||
| 86 | ) -> Self { | ||
| 87 | let sma = Sma::new(sma, mdio, mdc); | ||
| 88 | let phy = GenericPhy::new_auto(sma); | ||
| 89 | |||
| 90 | Self::new_with_phy( | ||
| 91 | queue, peri, irq, ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en, mac_addr, phy, | ||
| 92 | ) | ||
| 93 | } | ||
| 94 | |||
| 95 | /// Create a new MII ethernet driver using 14 pins. | ||
| 96 | /// | ||
| 97 | /// This function uses a [`GenericPhy::new_auto`] as PHY, created using the | ||
| 98 | /// provided [`SMA`](sma::Instance), and MDIO and MDC pins. | ||
| 99 | /// | ||
| 100 | /// See [`Ethernet::new_mii_with_phy`] for creating an RMII ethernet | ||
| 101 | /// river with a non-standard PHY. | ||
| 102 | pub fn new_mii<const TX: usize, const RX: usize>( | ||
| 103 | queue: &'d mut PacketQueue<TX, RX>, | ||
| 104 | peri: Peri<'d, T>, | ||
| 105 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | ||
| 106 | rx_clk: Peri<'d, impl RXClkPin<T>>, | ||
| 107 | tx_clk: Peri<'d, impl TXClkPin<T>>, | ||
| 108 | rxdv: Peri<'d, impl RXDVPin<T>>, | ||
| 109 | rx_d0: Peri<'d, impl RXD0Pin<T>>, | ||
| 110 | rx_d1: Peri<'d, impl RXD1Pin<T>>, | ||
| 111 | rx_d2: Peri<'d, impl RXD2Pin<T>>, | ||
| 112 | rx_d3: Peri<'d, impl RXD3Pin<T>>, | ||
| 113 | tx_d0: Peri<'d, impl TXD0Pin<T>>, | ||
| 114 | tx_d1: Peri<'d, impl TXD1Pin<T>>, | ||
| 115 | tx_d2: Peri<'d, impl TXD2Pin<T>>, | ||
| 116 | tx_d3: Peri<'d, impl TXD3Pin<T>>, | ||
| 117 | tx_en: Peri<'d, impl TXEnPin<T>>, | ||
| 118 | mac_addr: [u8; 6], | ||
| 119 | sma: Peri<'d, SMA>, | ||
| 120 | mdio: Peri<'d, impl MDIOPin<SMA>>, | ||
| 121 | mdc: Peri<'d, impl MDCPin<SMA>>, | ||
| 122 | ) -> Self { | ||
| 123 | let sma = Sma::new(sma, mdio, mdc); | ||
| 124 | let phy = GenericPhy::new_auto(sma); | ||
| 125 | |||
| 126 | Self::new_mii_with_phy( | ||
| 127 | 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, | ||
| 128 | mac_addr, phy, | ||
| 129 | ) | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | ||
| 134 | /// Create a new RMII ethernet driver using 7 pins. | ||
| 135 | pub fn new_with_phy<const TX: usize, const RX: usize>( | ||
| 136 | queue: &'d mut PacketQueue<TX, RX>, | ||
| 137 | peri: Peri<'d, T>, | ||
| 138 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | ||
| 139 | ref_clk: Peri<'d, impl RefClkPin<T>>, | ||
| 140 | crs: Peri<'d, impl CRSPin<T>>, | ||
| 141 | rx_d0: Peri<'d, impl RXD0Pin<T>>, | ||
| 142 | rx_d1: Peri<'d, impl RXD1Pin<T>>, | ||
| 143 | tx_d0: Peri<'d, impl TXD0Pin<T>>, | ||
| 144 | tx_d1: Peri<'d, impl TXD1Pin<T>>, | ||
| 145 | tx_en: Peri<'d, impl TXEnPin<T>>, | ||
| 146 | mac_addr: [u8; 6], | ||
| 147 | phy: P, | ||
| 78 | ) -> Self { | 148 | ) -> Self { |
| 79 | config_pins!(ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | 149 | config_pins!(ref_clk, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); |
| 80 | 150 | ||
| @@ -92,7 +162,7 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 92 | } | 162 | } |
| 93 | 163 | ||
| 94 | /// Create a new MII ethernet driver using 12 pins. | 164 | /// Create a new MII ethernet driver using 12 pins. |
| 95 | pub fn new_mii<const TX: usize, const RX: usize>( | 165 | pub fn new_mii_with_phy<const TX: usize, const RX: usize>( |
| 96 | queue: &'d mut PacketQueue<TX, RX>, | 166 | queue: &'d mut PacketQueue<TX, RX>, |
| 97 | peri: Peri<'d, T>, | 167 | peri: Peri<'d, T>, |
| 98 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, | 168 | irq: impl interrupt::typelevel::Binding<interrupt::typelevel::ETH, InterruptHandler> + 'd, |
| @@ -108,8 +178,8 @@ impl<'d, T: Instance, P: Phy> Ethernet<'d, T, P> { | |||
| 108 | tx_d2: Peri<'d, impl TXD2Pin<T>>, | 178 | tx_d2: Peri<'d, impl TXD2Pin<T>>, |
| 109 | tx_d3: Peri<'d, impl TXD3Pin<T>>, | 179 | tx_d3: Peri<'d, impl TXD3Pin<T>>, |
| 110 | tx_en: Peri<'d, impl TXEnPin<T>>, | 180 | tx_en: Peri<'d, impl TXEnPin<T>>, |
| 111 | phy: P, | ||
| 112 | mac_addr: [u8; 6], | 181 | mac_addr: [u8; 6], |
| 182 | phy: P, | ||
| 113 | ) -> Self { | 183 | ) -> Self { |
| 114 | config_pins!( | 184 | config_pins!( |
| 115 | rx_clk, tx_clk, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en | 185 | rx_clk, tx_clk, rxdv, rx_d0, rx_d1, rx_d2, rx_d3, tx_d0, tx_d1, tx_d2, tx_d3, tx_en |
