|
| 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