【发布时间】:2021-08-27 03:28:42
【问题描述】:
我在应用延迟延迟时是否犯了任何错误?
这是我正在使用的代码,用于在延迟后闪烁 LED 3 和 4。
use cortex_m_rt::entry;
use stm32f30x_hal as hal;
use hal::delay::Delay;
use hal::prelude::*;
use hal::stm32f30x;
use panic_halt;
#[entry]
fn main() -> ! {
let device_p = stm32f30x::Peripherals::take().unwrap();
let core_periphs=cortex_m::Peripherals::take().unwrap();
let mut reset_clock_control = device_p.RCC.constrain();
let mut gpioe = device_p.GPIOE.split(&mut reset_clock_control.ahb);
**let mut flash = device_p.FLASH.constrain();
let clocks = reset_clock_control.cfgr.freeze(&mut flash.acr);
let mut delay = Delay::new(core_periphs.SYST,clocks);**
let mut led_3 = gpioe
.pe9
.into_push_pull_output(&mut (gpioe.moder), &mut (gpioe.otyper));
let mut led_4=gpioe.pe8.into_push_pull_output(&mut gpioe.moder,&mut gpioe.otyper);
loop {
led_3.set_high();
**delay.delay_ms(2_000_u16);**
led_4.set_high();
}
}
如果我不使用延迟部分,它工作正常
【问题讨论】:
-
不耽误你到底看到了什么?
-
好的,所以如果我从我的代码中删除延迟部分,即闪存、时钟和延迟,只需提供'led_3.set_high();'内部循环,然后它工作正常。