From 5bdfd21e93b7afe6d53ba2bb7fe117ceca5af032 Mon Sep 17 00:00:00 2001 From: occheung Date: Mon, 25 Jan 2021 11:47:05 +0800 Subject: [PATCH] example/tcp: fix delay reference --- examples/tcp_stm32f407.rs | 14 ++++---------- examples/tx_stm32f407.rs | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/tcp_stm32f407.rs b/examples/tcp_stm32f407.rs index 10e4e7a..80e3278 100644 --- a/examples/tcp_stm32f407.rs +++ b/examples/tcp_stm32f407.rs @@ -13,6 +13,7 @@ use stm32f4xx_hal::{ gpio::GpioExt, time::U32Ext, stm32::ITM, + delay::Delay, spi::Spi, time::Hertz }; @@ -27,9 +28,6 @@ use smoltcp::socket::{SocketSet, TcpSocket, TcpSocketBuffer}; use core::str; use core::fmt::Write; -mod delay; -use delay::AsmDelay; - /// Timer use core::cell::RefCell; use cortex_m::interrupt::Mutex; @@ -99,10 +97,6 @@ static mut NET_STORE: NetStorage = NetStorage { neighbor_cache: [None; 8], }; -pub fn delay_ns(time_ns: u32) { - cortex_m::asm::delay((time_ns*168_000_000)/1_000_000_000 + 1) -} - #[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)] const APP: () = { struct Resources { @@ -130,7 +124,7 @@ const APP: () = { .pclk1(42.mhz()) .require_pll48clk() .freeze(); - let mut asm_delay = AsmDelay::new(clocks.sysclk().0); + let mut delay = Delay::new(c.core.SYST, clocks); // Init ITM let mut itm = c.core.ITM; @@ -150,7 +144,7 @@ const APP: () = { // Map SPISEL: see Table 1, NIC100 Manual let mut spisel = gpioa.pa1.into_push_pull_output(); spisel.set_high().unwrap(); - asm_delay.delay_ms(1_u32); + delay.delay_ms(1_u32); spisel.set_low().unwrap(); // Create SPI1 for HAL @@ -217,7 +211,7 @@ const APP: () = { // Setup SysTick after releasing SYST from Delay // Reference to stm32-eth:examples/ip.rs - timer_setup(c.core.SYST, clocks); + timer_setup(delay.free(), clocks); iprintln!(stim0, "Timer initialized"); init::LateResources { diff --git a/examples/tx_stm32f407.rs b/examples/tx_stm32f407.rs index 93d6ab9..268e254 100644 --- a/examples/tx_stm32f407.rs +++ b/examples/tx_stm32f407.rs @@ -84,10 +84,10 @@ const APP: () = { Hertz(enc424j600::spi::interfaces::SPI_CLOCK_FREQ), clocks); - let delay_ns_fp: fn(u32) -> () = |time_ns| { + let delay_ns: fn(u32) -> () = |time_ns| { cortex_m::asm::delay((time_ns*21)/125 + 1) }; - enc424j600::SpiEth::new(spi_eth_port, spi1_nss, delay_ns_fp) + enc424j600::SpiEth::new(spi_eth_port, spi1_nss, delay_ns) }; // Init