-
Notifications
You must be signed in to change notification settings - Fork 7
/
stm32f407.rs
36 lines (28 loc) · 971 Bytes
/
stm32f407.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
#![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 cp = cortex_m::peripheral::Peripherals::take().unwrap();
// 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);
}
}