Select Git revision
gpio_raw.rs
gpio_raw.rs 1.84 KiB
//! Simple access to gpio
// build without the Rust standard library
#![no_std]
// API to the ARM Cortex M Peripherals
extern crate cortex_m;
// API to the ST stm32f401x Micro controller
extern crate stm32f40x;
// Convenient tracing over semihosting and ITM
#[macro_use]
extern crate cortex_m_debug;
fn main() {
ipln!("ITM: Hello World");
sprintln!("SEMIHOSTING: Hello World");
// to prevent returning
loop {}
}
// use rtfm::app;
// app! {
// device: stm32f40x,
// }
// fn wait(i: u32) {
// for _ in 0..i {
// cortex_m::asm::nop(); // no operation (cannot be optimized out)
// }
// }
// // see the Reference Manual RM0368 (www.st.com/resource/en/reference_manual/dm00096844.pdf)
// // rcc, chapter 6
// // gpio, chapter 8
// fn init(p: init::Peripherals) {
// // power on GPIOA, RM0368 6.3.11
// p.RCC.ahb1enr.modify(|_, w| w.gpioaen().set_bit());
// // configure PA5 as output, RM0368 8.4.1
// p.GPIOA.moder.modify(|_, w| w.moder5().bits(1));
// // loop {
// // // set PA5 high, RM0368 8.4.6
// // p.GPIOA.odr.modify(|_, w| w.odr5().bit(true));
// // wait(10_000);
// // // set PA5 low, RM0368 8.4.6
// // p.GPIOA.odr.modify(|_, w| w.odr5().bit(false));
// // wait(10_000);
// // }
// // rewrite the above code to have the GPIO as output
// // and alter the data output through the BSRR register
// // this is more efficient as the read register (in modify)
// // is not needed.
// loop {
// // set PA5 high, RM0368 8.4.7
// p.GPIOA.bsrr.write(|w| w.bs5().set_bit());
// wait(10_000);
// // set PA5 low, RM0368 8.4.7
// p.GPIOA.bsrr.write(|w| w.br5().set_bit());
// wait(10_000);
// }
// }
// #[inline(never)]
// fn idle() -> ! {
// loop {
// rtfm::wfi();
// }
// }