Commit 141f9791 authored by DevDoggo's avatar DevDoggo

Made LED blink with Modify

parent 6e8b8a45
......@@ -7,6 +7,8 @@
extern crate cortex_m;
extern crate cortex_m_rt;
#[macro_use]
extern crate cortex_m_debug;
......@@ -135,6 +137,7 @@ fn main() {
pub const G_BASE: u32 = 0x40000000 + 0x00020000;
pub const GPIOA_MODER: u32 = G_BASE;
pub const GPIOA_BSRR: u32 = G_BASE + 0x18;
pub const GPIOA_ODR: u32 = G_BASE + 0x14;
fn w_rite(addr: u32, val: u32) {
unsafe {
......@@ -144,7 +147,7 @@ fn w_rite(addr: u32, val: u32) {
fn r_ead(addr: u32) -> u32 {
unsafe {
core::ptr::read_volatile(addr as *const _)
core::ptr::read_volatile(addr as *const u32)
}
}
......@@ -158,8 +161,19 @@ fn r_ead(addr: u32) -> u32 {
// commit your answers (bare5_2)
fn m_odify(addr: u32, offset: u32, width: u32, val: u32) {
//something like this, it's a start
addr = addr | (val << offset);
let r = r_ead(addr); //- 0x4); //ODR registry commented out
let v: u32 = (!(1 << offset) as u16) as u32;
sprintln!("r::ODR: {:#b}", r);
sprintln!("v: {:#b}", v);
sprintln!("r&v: {:#b}", (r & v));
//Experimental XOR to heck up 0s
//let xor =
let out = (r & v) | (val << offset);
sprintln!("out: {:#b}", out);
w_rite(addr, out);
}
......@@ -178,14 +192,30 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) {
// this is more efficient as the read register is not needed.
loop {
w_rite(GPIOA_BSRR, 1 << 3);
//w_rite(GPIOA_BSRR, 1 << 5);
//wait(10_000);
//w_rite(GPIOA_BSRR, 1 << (5 + 16));
//wait(10_000);
//w_rite(GPIOA_BSRR, 1 << 5);
//wait(10_000);
// As it turns out, GPIOA_BSRR is a Write-Only registry
// Use ODR, which is a read/write registry
// let x = r_ead(GPIOA_ODR);
// sprintln!("ODR: {:#b}", x);
w_rite(GPIOA_BSRR, 1 << 5);
wait(10_000);
// sprintln!("BOYE");
// ipln!("Boye!");
w_rite(GPIOA_BSRR, 1 << (5 + 16));
//cortex_m::asm::bkpt();
// Turn LED on
sprintln!("\n--- Turn On!");
m_odify(GPIOA_ODR, 5, 1, 0b1);
wait(10_000);
// Turn LED off
sprintln!("\n--- Turn Off!");
m_odify(GPIOA_ODR, 5, 1, 0b0);
wait(10_000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment