-
-
Save metajack/657fe7d9e243fa70988805ff391c74d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_main] | |
#![no_std] | |
use cortex_m_rt::entry; | |
use hal::{gpio::GpioExt, hal::digital::v2::OutputPin, pwr::PwrExt, rcc::RccExt}; | |
use panic_halt as _; | |
use pwm_pca9685::{Address, Channel, Pca9685}; | |
use stm32h7xx_hal::{self as hal, pac, prelude::*}; | |
#[entry] | |
fn main() -> ! { | |
let cp = cortex_m::Peripherals::take().unwrap(); | |
let dp = pac::Peripherals::take().unwrap(); | |
let pwr = dp.PWR.constrain(); | |
// set to Vcore = maximum freq, vos0 | |
let pwrcfg = pwr.vos0(&dp.SYSCFG).freeze(); | |
let rcc = dp.RCC.constrain(); | |
// 480MHz system clock | |
let ccdr = rcc | |
.use_hse(16.mhz()) | |
.sys_ck(480.mhz()) | |
.pll1_strategy(hal::rcc::PllConfigStrategy::Iterative) | |
.pll1_p_ck(480.mhz()) // 480 MHz | |
.pll1_q_ck(160.mhz()) // 160 MHz | |
.pll1_r_ck(320.mhz()) // 320 MHz | |
.pll3_strategy(hal::rcc::PllConfigStrategy::Iterative) | |
.pll3_p_ck(49_166_667.hz()) | |
.pll3_q_ck(157_333_334.hz()) | |
.pll3_r_ck(24_583_334.hz()) | |
.freeze(pwrcfg, &dp.SYSCFG); | |
// set up I2C for leds, which is i2c1, scl is B8, sda is B9, run at 1MHz | |
let gpiob = dp.GPIOB.split(ccdr.peripheral.GPIOB); | |
let scl = gpiob.pb8.into_alternate_af4().set_open_drain(); | |
let sda = gpiob.pb9.into_alternate_af4().set_open_drain(); | |
let i2c = dp.I2C1.i2c((scl, sda), 1.mhz(), ccdr.peripheral.I2C1, &ccdr.clocks); | |
let mut pwm = Pca9685::new(i2c, Address::default()).unwrap(); | |
pwm.set_prescale(100).unwrap(); | |
pwm.enable().unwrap(); | |
let gpioc = dp.GPIOC.split(ccdr.peripheral.GPIOC); | |
let mut led = gpioc.pc7.into_push_pull_output(); | |
let mut delay = cp.SYST.delay(ccdr.clocks); | |
// loop { | |
// led.set_high().unwrap(); | |
// delay.delay_ms(500_u16); | |
// led.set_low().unwrap(); | |
// delay.delay_ms(500_u16); | |
// } | |
loop { | |
led.set_high().unwrap(); | |
//pwm.set_channel_on_off(Channel::C0, 0, 2047).unwrap(); | |
delay.delay_ms(500_u16); | |
led.set_low().unwrap(); | |
//pwm.set_channel_on_off(Channel::C0, 0, 0).unwrap(); | |
delay.delay_ms(500_u16); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment