From 540e0316aa425a8fbd126d31350dbe51fca92791 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 13 Dec 2022 16:45:49 -0700 Subject: Experimental Gpio. This rapidly blinks the sysled on the stm32. This shows the ability to manipulate memory mapped registers. --- src/main.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 146f601..997e532 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,14 +2,37 @@ #![no_std] use core::panic::PanicInfo; +use hal::gpio::get_gpio_port_b; +use crate::hal::gpio; + +mod hal; mod init; #[link_section = ".inits.999"] #[no_mangle] -pub static __MAIN: fn() -> () = main; -pub fn main() -> () { - loop {}; +pub static __MAIN: unsafe fn() -> () = main; +pub unsafe fn main() -> () { + let mut pin = get_gpio_port_b().pin(3); + pin.set_mode(gpio::GpioMode::Output); + pin.set_output_type(gpio::GpioOutputType::PushPull); + pin.set_output_speed(gpio::GpioSpeed::Medium); + pin.set_pull_dir(gpio::GpioPullDir::Down); + + pin.set_high(); + loop { + delay(); + pin.set_low(); + delay(); + pin.set_high(); + } +} + +fn delay() { + let mut cnt = 0; + while cnt < 10000 { + cnt += 1; + } } #[panic_handler] -- cgit