Skip to content

Commit 68a6ab0

Browse files
Luctiusluctius
authored andcommitted
Added Timer support.
1 parent b65994a commit 68a6ab0

File tree

4 files changed

+545
-11
lines changed

4 files changed

+545
-11
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ nb = "0.1.1"
1717
stm32g4 = "0.13.0"
1818
paste = "1.0"
1919

20+
[dependencies.cast]
21+
version = "0.2.7"
22+
default-features = false
23+
2024
[dependencies.bare-metal]
2125
features = ["const-fn"]
2226
version = "0.2.5"

examples/blinky_delay.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,47 @@
33
#![no_main]
44
#![no_std]
55

6-
extern crate cortex_m;
7-
extern crate cortex_m_rt as rt;
8-
extern crate panic_halt;
9-
extern crate stm32g4xx_hal as hal;
10-
6+
use hal::delay::DelayFromCountDownTimer;
117
use hal::prelude::*;
128
use hal::rcc::Config;
139
use hal::stm32;
14-
use rt::entry;
10+
use hal::timer::Timer;
11+
use stm32g4xx_hal as hal;
12+
13+
use cortex_m_rt::entry;
14+
use log::info;
15+
16+
#[macro_use]
17+
mod utils;
1518

1619
#[entry]
1720
fn main() -> ! {
21+
utils::logger::init();
22+
23+
info!("start");
1824
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
1925
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
2026
let mut rcc = dp.RCC.freeze(Config::hsi());
2127

22-
let gpiob = dp.GPIOB.split(&mut rcc);
23-
let mut led = gpiob.pb8.into_push_pull_output();
28+
info!("Init Led");
29+
let gpioa = dp.GPIOA.split(&mut rcc);
30+
let mut led = gpioa.pa5.into_push_pull_output();
31+
32+
info!("Init SYST delay");
33+
let mut delay_syst = cp.SYST.delay(&rcc.clocks);
2434

25-
let mut delay = cp.SYST.delay(&rcc.clocks);
35+
info!("Init Timer2 delay");
36+
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
37+
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.ms()));
2638

2739
loop {
40+
info!("Toggle");
41+
led.toggle().unwrap();
42+
info!("SYST delay");
43+
delay_syst.delay(1000.ms());
44+
info!("Toggle");
2845
led.toggle().unwrap();
29-
delay.delay(500.ms());
46+
info!("TIM2 delay");
47+
delay_tim2.delay_ms(1000_u16);
3048
}
3149
}

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub extern crate stm32g4;
3131

3232
pub use nb::block;
3333

34+
mod sealed {
35+
pub trait Sealed {}
36+
}
37+
pub(crate) use sealed::Sealed;
38+
3439
#[cfg(feature = "stm32g431")]
3540
pub use stm32g4::stm32g431 as stm32;
3641

@@ -76,5 +81,5 @@ pub mod signature;
7681
// pub mod stopwatch;
7782
pub mod syscfg;
7883
pub mod time;
79-
// pub mod timer;
84+
pub mod timer;
8085
// pub mod watchdog;

0 commit comments

Comments
 (0)