Skip to content

Commit aea2aa8

Browse files
authored
Merge pull request #480 from youndong/blinky_on_stm32h747i_disco
Add new blinky example using GPIOs on STM32H747i-Disco
2 parents cd7c125 + e6f6065 commit aea2aa8

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ opt-level = "s" # optimize for binary size
151151
# `required-features` field specifies the hal features and/or the hardware
152152
# configuration required by the example.
153153

154+
[[example]]
155+
name = "blinky-stm32h747i-disco"
156+
required-features = ["rt", "stm32h747cm7"]
157+
154158
[[example]]
155159
name = "can-echo"
156160
required-features = ["can"]

examples/blinky-stm32h747i-disco.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#![deny(warnings)] // This code runs on stm32h747i-disco and does not use example! macro.
2+
#![allow(unused_macros)]
3+
#![no_main]
4+
#![no_std]
5+
6+
use cortex_m_rt::entry;
7+
use stm32h7xx_hal::{pac, prelude::*};
8+
9+
use log::info;
10+
11+
#[macro_use]
12+
mod utilities;
13+
14+
#[entry]
15+
fn main() -> ! {
16+
utilities::logger::init();
17+
let cp = cortex_m::Peripherals::take().unwrap();
18+
let dp = pac::Peripherals::take().unwrap();
19+
20+
// Constrain and Freeze power
21+
info!("Setup PWR... ");
22+
let pwr = dp.PWR.constrain();
23+
// let pwrcfg = example_power!(pwr).freeze();
24+
let pwrcfg = pwr.smps().freeze(); // This code works normally on stm32h747i-disco.
25+
26+
// Constrain and Freeze clock
27+
// RCC (Reset and Clock Control)
28+
info!("Setup RCC... ");
29+
let rcc = dp.RCC.constrain();
30+
31+
// CCDR (Core Clock Distribution and Reset)
32+
// link: https://docs.rs/stm32h7xx-hal/latest/stm32h7xx_hal/rcc/struct.Ccdr.html
33+
let ccdr = rcc.sys_ck(100.MHz()).freeze(pwrcfg, &dp.SYSCFG);
34+
35+
info!("");
36+
info!("stm32h7xx-hal example - Blinky");
37+
info!("");
38+
39+
let gpioi = dp.GPIOI.split(ccdr.peripheral.GPIOI); // <= GPIO settings for LEDs
40+
41+
// Configure gpio pins as output.
42+
let mut led1 = gpioi.pi12.into_push_pull_output(); // PI12 for LED1
43+
let mut led2 = gpioi.pi13.into_push_pull_output(); // PI13 for LED2
44+
let mut led3 = gpioi.pi14.into_push_pull_output(); // PI14 for LED3
45+
let mut led4 = gpioi.pi15.into_push_pull_output(); // PI15 for LED4
46+
47+
// Get the delay provider.
48+
let mut delay = cp.SYST.delay(ccdr.clocks);
49+
50+
loop {
51+
loop {
52+
led1.set_high();
53+
led2.set_low();
54+
led3.set_high();
55+
led4.set_low();
56+
delay.delay_ms(500_u16);
57+
58+
led1.set_low();
59+
led2.set_high();
60+
led3.set_low();
61+
led4.set_high();
62+
delay.delay_ms(500_u16);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)