-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstm32f407-dwt.rs
46 lines (36 loc) · 1.43 KB
/
stm32f407-dwt.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! This example shows how to use the DWT (Data Watchpoint and Trace) unit available
//! on some ARM Cortex-M microcontrollers for more accurate data timings.
//!
//! This is especially useful in applications where (potentially long) interrupt handlers
//! may run while an acquisition is in progress. This may lead to incorrect bit timings,
//! resulting in timeouts and/or CRC errors.
#![deny(unsafe_code)]
#![no_main]
#![no_std]
extern crate panic_semihosting;
use cortex_m_rt::entry;
use cortex_m_semihosting::hprintln;
use hal::{prelude::*, stm32};
use stm32f4xx_hal as hal;
use dht11::Dht11;
#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let mut cp = cortex_m::peripheral::Peripherals::take().unwrap();
// Enable the DWT counter. This *needs* to be done manually.
cp.DWT.enable_cycle_counter();
// The DATA pin is connected to PE2.
let gpio = dp.GPIOE.split();
let pin = gpio.pe2.into_open_drain_output();
// Create a delay abstraction based on SysTick.
// We are using the HSE oscillator here for accurate delays.
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.use_hse(8.mhz()).sysclk(168.mhz()).freeze();
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);
// Create an instance of our device
let mut dht11 = Dht11::new(pin);
loop {
hprintln!("{:?}", dht11.perform_measurement(&mut delay)).unwrap();
delay.delay_ms(1000_u16);
}
}