example/tcp: fix delay reference

This commit is contained in:
occheung 2021-01-25 11:47:05 +08:00
parent d557e2542d
commit 5bdfd21e93
2 changed files with 6 additions and 12 deletions

View File

@ -13,6 +13,7 @@ use stm32f4xx_hal::{
gpio::GpioExt, gpio::GpioExt,
time::U32Ext, time::U32Ext,
stm32::ITM, stm32::ITM,
delay::Delay,
spi::Spi, spi::Spi,
time::Hertz time::Hertz
}; };
@ -27,9 +28,6 @@ use smoltcp::socket::{SocketSet, TcpSocket, TcpSocketBuffer};
use core::str; use core::str;
use core::fmt::Write; use core::fmt::Write;
mod delay;
use delay::AsmDelay;
/// Timer /// Timer
use core::cell::RefCell; use core::cell::RefCell;
use cortex_m::interrupt::Mutex; use cortex_m::interrupt::Mutex;
@ -99,10 +97,6 @@ static mut NET_STORE: NetStorage = NetStorage {
neighbor_cache: [None; 8], 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)] #[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
const APP: () = { const APP: () = {
struct Resources { struct Resources {
@ -130,7 +124,7 @@ const APP: () = {
.pclk1(42.mhz()) .pclk1(42.mhz())
.require_pll48clk() .require_pll48clk()
.freeze(); .freeze();
let mut asm_delay = AsmDelay::new(clocks.sysclk().0); let mut delay = Delay::new(c.core.SYST, clocks);
// Init ITM // Init ITM
let mut itm = c.core.ITM; let mut itm = c.core.ITM;
@ -150,7 +144,7 @@ const APP: () = {
// Map SPISEL: see Table 1, NIC100 Manual // Map SPISEL: see Table 1, NIC100 Manual
let mut spisel = gpioa.pa1.into_push_pull_output(); let mut spisel = gpioa.pa1.into_push_pull_output();
spisel.set_high().unwrap(); spisel.set_high().unwrap();
asm_delay.delay_ms(1_u32); delay.delay_ms(1_u32);
spisel.set_low().unwrap(); spisel.set_low().unwrap();
// Create SPI1 for HAL // Create SPI1 for HAL
@ -217,7 +211,7 @@ const APP: () = {
// Setup SysTick after releasing SYST from Delay // Setup SysTick after releasing SYST from Delay
// Reference to stm32-eth:examples/ip.rs // Reference to stm32-eth:examples/ip.rs
timer_setup(c.core.SYST, clocks); timer_setup(delay.free(), clocks);
iprintln!(stim0, "Timer initialized"); iprintln!(stim0, "Timer initialized");
init::LateResources { init::LateResources {

View File

@ -84,10 +84,10 @@ const APP: () = {
Hertz(enc424j600::spi::interfaces::SPI_CLOCK_FREQ), Hertz(enc424j600::spi::interfaces::SPI_CLOCK_FREQ),
clocks); 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) 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 // Init