Skip to content
Snippets Groups Projects
Commit 163eea59 authored by Samuel Karlsson's avatar Samuel Karlsson
Browse files

bare5: task 1

parent 1d7474a3
No related branches found
No related tags found
No related merge requests found
File added
...@@ -27,8 +27,8 @@ use address::*; ...@@ -27,8 +27,8 @@ use address::*;
#[inline(always)] #[inline(always)]
fn read_u32(addr: u32) -> u32 { fn read_u32(addr: u32) -> u32 {
//unsafe { core::ptr::read_volatile(addr as *const _) } unsafe { core::ptr::read_volatile(addr as *const _) }
core::ptr::read_volatile(addr as *const _) //core::ptr::read_volatile(addr as *const _)
} }
#[inline(always)] #[inline(always)]
......
...@@ -126,6 +126,7 @@ fn main() { ...@@ -126,6 +126,7 @@ fn main() {
idle(rcc, gpioa); idle(rcc, gpioa);
} }
// user application // user application
fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) {
let rcc_copy = &rcc; let rcc_copy = &rcc;
...@@ -140,18 +141,35 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { ...@@ -140,18 +141,35 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) {
// and alter the data output through the BSRR register // and alter the data output through the BSRR register
// this is more efficient as the read register is not needed. // this is more efficient as the read register is not needed.
let gbh: u32 = 0x40000000 + 0x00020000+ 0x18;
loop { loop {
// set PA5 high // set PA5 high
gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led) //gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led)
write_u32(gbh, 1 << 5);
wait(10_000); wait(10_000);
// set PA5 low // set PA5 low
gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led) //gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
//unsafe { ptr::write_volatile(self.value.get(), value)
write_u32(gbh, 1 << (5 + 16));
wait(10_000); wait(10_000);
}
}
fn write_u32(addr: u32, val: u32) {
unsafe {
core::ptr::write_volatile(addr as *mut _, val);
}
}
fn read_u32(addr: u32) -> u32{
unsafe {
core::ptr::read_volatile(addr as *const _)
} }
} }
// 1. C like API //ike API
// In C the .h files are used for defining interfaces, like function signatures (prototypes), // In C the .h files are used for defining interfaces, like function signatures (prototypes),
// structs and macros (but usually not the functions themselves) // structs and macros (but usually not the functions themselves)
// here is a peripheral abstraction quite similar to what you would find in the .h files // here is a peripheral abstraction quite similar to what you would find in the .h files
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment