diff --git a/compile.sh b/compile.sh index 65adca879844a2b363aa785a468b0876d1bd69e7..96c2f2434948add79239513de39cadaa5075c5c3 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 8d5b12289f0f3d46886ab5822808c360f9b7e5e3..56e6c1cd7405b8756cf97abce7c6023b1e54a5af 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 116edf3efdeb377bb51c00e7c3513348b1e59c36..e9c668178d5bdaaff0db227afb76c70c50cc2c27 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