Skip to content
Snippets Groups Projects
Commit 140426a5 authored by DevDoggo's avatar DevDoggo
Browse files

Created write/read while using registry directly

parent 329c5022
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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)
w_rite(GPIOA_BSRR, 1 << 5);
wait(10_000);
// sprintln!("BOYE");
// ipln!("Boye!");
// set PA5 low
gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
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);
}
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment