From 140426a50e52d22156d03072db971edf6a37f91f Mon Sep 17 00:00:00 2001 From: DevDoggo <devdoggo@protonmail.com> Date: Wed, 23 May 2018 02:29:47 +0200 Subject: [PATCH] Created write/read while using registry directly --- compile.sh | 3 ++- examples/bare5.rs | 44 +++++++++++++++++++++++++++++++++++++++----- gdb.sh | 3 ++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/compile.sh b/compile.sh index 65adca8..96c2f24 100755 --- a/compile.sh +++ b/compile.sh @@ -6,4 +6,5 @@ #cargo build --target thumbv7em-none-eabihf --example bare2 #cargo build --target thumbv7em-none-eabihf --release --example bare2 #cargo build --target thumbv7em-none-eabihf --example bare3 -cargo build --target thumbv7em-none-eabihf --example bare4 +#cargo build --target thumbv7em-none-eabihf --example bare4 +cargo build --target thumbv7em-none-eabihf --example bare5 diff --git a/examples/bare5.rs b/examples/bare5.rs index 8d5b122..56e6c1c 100644 --- a/examples/bare5.rs +++ b/examples/bare5.rs @@ -7,6 +7,8 @@ extern crate cortex_m; extern crate cortex_m_rt; +extern crate cortex_m_debug; + // C like API... mod stm32f40x { @@ -126,6 +128,27 @@ fn main() { idle(rcc, gpioa); } + + +////////////////////// Fun API starts here + +pub const G_BASE: u32 = 0x40000000 + 0x00020000; +pub const GPIOA_MODER: u32 = G_BASE; +pub const GPIOA_BSRR: u32 = G_BASE + 0x18; + +fn w_rite(addr: u32, val: u32) { + unsafe { + core::ptr::write_volatile(addr as *mut _, val); + } +} + +fn r_ead(addr: u32) -> u32 { + unsafe { + core::ptr::read_volatile(addr as *const _) + } +} + + // user application fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { let rcc_copy = &rcc; @@ -141,13 +164,24 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { // this is more efficient as the read register is not needed. loop { - // set PA5 high - gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led) - wait(10_000); - // set PA5 low - gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led) + + w_rite(GPIOA_BSRR, 1 << 5); wait(10_000); + // sprintln!("BOYE"); + // ipln!("Boye!"); + + w_rite(GPIOA_BSRR, 1 << (5 + 16)); + wait(10_000); + + + // // set PA5 high + // gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led) + // wait(10_000); + + // // set PA5 low + // gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led) + // wait(10_000); } } diff --git a/gdb.sh b/gdb.sh index 116edf3..e9c6681 100755 --- a/gdb.sh +++ b/gdb.sh @@ -7,4 +7,5 @@ TARGET=thumbv7em-none-eabihf #arm-none-eabi-gdb target/$TARGET/debug/examples/bare2 #arm-none-eabi-gdb target/$TARGET/release/examples/bare2 #arm-none-eabi-gdb target/$TARGET/debug/examples/bare3 -arm-none-eabi-gdb target/$TARGET/debug/examples/bare4 +#arm-none-eabi-gdb target/$TARGET/debug/examples/bare4 +arm-none-eabi-gdb target/$TARGET/debug/examples/bare5 -- GitLab