diff options
| author | Thales Fragoso <[email protected]> | 2021-06-14 17:20:04 -0300 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-06-16 16:48:35 +0200 |
| commit | 6cecc6d4b54acf84cc9b22996b178cba97970374 (patch) | |
| tree | 34f2856e9bbef82b8f1faa3a3f0c856d73a5f293 | |
| parent | f7e1f262af5ca886e3780d92048c5dc167bef6d9 (diff) | |
eth-v2: Get hclk frequency from clock singleton
| -rw-r--r-- | embassy-stm32/src/eth/v2/mod.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index b9acbf404..a8a361dfe 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -14,7 +14,6 @@ use crate::gpio::Pin as GpioPin; | |||
| 14 | use crate::pac::gpio::vals::Ospeedr; | 14 | use crate::pac::gpio::vals::Ospeedr; |
| 15 | use crate::pac::{ETH, RCC, SYSCFG}; | 15 | use crate::pac::{ETH, RCC, SYSCFG}; |
| 16 | use crate::peripherals; | 16 | use crate::peripherals; |
| 17 | use crate::time::Hertz; | ||
| 18 | 17 | ||
| 19 | mod descriptors; | 18 | mod descriptors; |
| 20 | use super::{StationManagement, PHY}; | 19 | use super::{StationManagement, PHY}; |
| @@ -44,7 +43,6 @@ impl<'d, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, P, TX, RX> { | |||
| 44 | tx_en: impl Unborrow<Target = impl TXEnPin> + 'd, | 43 | tx_en: impl Unborrow<Target = impl TXEnPin> + 'd, |
| 45 | phy: P, | 44 | phy: P, |
| 46 | mac_addr: [u8; 6], | 45 | mac_addr: [u8; 6], |
| 47 | hclk: Hertz, | ||
| 48 | phy_addr: u8, | 46 | phy_addr: u8, |
| 49 | ) -> Self { | 47 | ) -> Self { |
| 50 | unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); | 48 | unborrow!(interrupt, ref_clk, mdio, mdc, crs, rx_d0, rx_d1, tx_d0, tx_d1, tx_en); |
| @@ -118,8 +116,11 @@ impl<'d, P: PHY, const TX: usize, const RX: usize> Ethernet<'d, P, TX, RX> { | |||
| 118 | }); | 116 | }); |
| 119 | } | 117 | } |
| 120 | 118 | ||
| 121 | // Set the MDC clock frequency in the range 1MHz - 2.5MHz | 119 | // NOTE(unsafe) We got the peripheral singleton, which means that `rcc::init` was called |
| 120 | let hclk = unsafe { crate::rcc::get_freqs().ahb1 }; | ||
| 122 | let hclk_mhz = hclk.0 / 1_000_000; | 121 | let hclk_mhz = hclk.0 / 1_000_000; |
| 122 | |||
| 123 | // Set the MDC clock frequency in the range 1MHz - 2.5MHz | ||
| 123 | let clock_range = match hclk_mhz { | 124 | let clock_range = match hclk_mhz { |
| 124 | 0..=34 => 2, // Divide by 16 | 125 | 0..=34 => 2, // Divide by 16 |
| 125 | 35..=59 => 3, // Divide by 26 | 126 | 35..=59 => 3, // Divide by 26 |
