Skip to content

Commit

Permalink
use Delay from embassy-time to wait for PHY response
Browse files Browse the repository at this point in the history
  • Loading branch information
nikvoid committed Jan 22, 2025
1 parent 5885369 commit aca6843
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions embassy-stm32/src/eth/generic_smi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
use core::task::Context;

use chrono::format::DelayedFormat;
#[cfg(feature = "time")]
use embassy_time::{Duration, Timer};
use embassy_time::{Duration, Timer, Delay};
#[cfg(feature = "time")]
use futures_util::FutureExt;

Expand Down Expand Up @@ -52,7 +53,7 @@ pub struct GenericSMI {
impl GenericSMI {
/// Construct the PHY. It assumes the address `phy_addr` in the SMI communication
///
/// Set `phy_addr` to `0xFF` for automatic detection
/// Set `phy_addr` to `0xFF` for automatic detection (only with `time` feature enabled)
pub fn new(phy_addr: u8) -> Self {
Self {
phy_addr,
Expand All @@ -65,6 +66,7 @@ impl GenericSMI {
unsafe impl PHY for GenericSMI {
fn phy_reset<S: StationManagement>(&mut self, sm: &mut S) {
// Detect SMI address
#[cfg(feature = "time")]
if self.phy_addr == 0xFF {
for addr in 0..32 {
sm.smi_write(addr, PHY_REG_BCR, PHY_REG_BCR_RESET);
Expand All @@ -74,14 +76,15 @@ unsafe impl PHY for GenericSMI {
self.phy_addr = addr;
return;
}
cortex_m::asm::delay(1000);
embedded_hal_1::delay::DelayNs::delay_us(&mut Delay, 1000);
cortex_m::asm::delay(1000000);
}
}
panic!("PHY did not respond");
} else {
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 {}
}

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<S: StationManagement>(&mut self, sm: &mut S) {
Expand Down

0 comments on commit aca6843

Please sign in to comment.