From d8b1132b8a611fb7f9c532fb5ca7eb916fb503ad Mon Sep 17 00:00:00 2001 From: Harry Ho Date: Tue, 27 Apr 2021 16:22:03 +0800 Subject: [PATCH] examples: Replace delay_ns with cortex-m delay --- Cargo.toml | 4 ++-- examples/tcp_stm32f407.rs | 11 ++++------- examples/tx_stm32f407.rs | 11 ++++------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c75624d..a15ca8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,11 +38,11 @@ smoltcp-examples = [ "smoltcp-phy", "smoltcp/socket-tcp", "smoltcp/ethernet" ] tx_stm32f407 = [ - "stm32f4xx-hal/stm32f407", "cortex-m", "cortex-m-rtic", + "stm32f4xx-hal/stm32f407", "cortex-m", "cortex-m-rtic", "cortex-m-cpu", "panic-itm", "log" ] tcp_stm32f407 = [ - "stm32f4xx-hal/stm32f407", "cortex-m", "cortex-m-rt", "cortex-m-rtic", + "stm32f4xx-hal/stm32f407", "cortex-m", "cortex-m-rt", "cortex-m-rtic", "cortex-m-cpu", "smoltcp-examples", "panic-itm", "log"] default = [] diff --git a/examples/tcp_stm32f407.rs b/examples/tcp_stm32f407.rs index 7728ca8..b3ff3d8 100644 --- a/examples/tcp_stm32f407.rs +++ b/examples/tcp_stm32f407.rs @@ -79,8 +79,7 @@ use stm32f4xx_hal::{ }; type SpiEth = enc424j600::Enc424j600< Spi>, PA6>, PA7>)>, - PA4>, - fn(u32) -> () + PA4> >; pub struct NetStorage { @@ -153,14 +152,12 @@ const APP: () = { Hertz(enc424j600::spi::interfaces::SPI_CLOCK_FREQ), clocks); - let delay_ns_fp: fn(u32) -> () = |time_ns| { - cortex_m::asm::delay((time_ns*21)/125 + 1) - }; - SpiEth::new(spi_eth_port, spi1_nss, delay_ns_fp) + SpiEth::new(spi_eth_port, spi1_nss) + .cpu_freq_mhz(168) }; // Init controller - match spi_eth.reset() { + match spi_eth.reset(&mut delay) { Ok(_) => { iprintln!(stim0, "Initializing Ethernet...") } diff --git a/examples/tx_stm32f407.rs b/examples/tx_stm32f407.rs index 2a8619c..50d5dd5 100644 --- a/examples/tx_stm32f407.rs +++ b/examples/tx_stm32f407.rs @@ -29,8 +29,7 @@ use stm32f4xx_hal::{ }; type SpiEth = enc424j600::Enc424j600< Spi>, PA6>, PA7>)>, - PA4>, - fn(u32) -> () + PA4> >; #[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] @@ -84,14 +83,12 @@ const APP: () = { Hertz(enc424j600::spi::interfaces::SPI_CLOCK_FREQ), clocks); - let delay_ns: fn(u32) -> () = |time_ns| { - cortex_m::asm::delay((time_ns*21)/125 + 1) - }; - SpiEth::new(spi_eth_port, spi1_nss, delay_ns) + SpiEth::new(spi_eth_port, spi1_nss) + .cpu_freq_mhz(168) }; // Init - match spi_eth.reset() { + match spi_eth.reset(&mut delay) { Ok(_) => { iprintln!(stim0, "Initializing Ethernet...") }