diff --git a/examples/.bare5.rs.swp b/examples/.bare5.rs.swp new file mode 100644 index 0000000000000000000000000000000000000000..5f9c56a8961c6eeb8293d8357fd0d60aae8d53b0 Binary files /dev/null and b/examples/.bare5.rs.swp differ diff --git a/examples/bare4.rs b/examples/bare4.rs index 13b684d1f89789a378432e2dacc85b3ddb1dc144..91f9b371adea911e5a42a41fa929c6eed6657bb9 100644 --- a/examples/bare4.rs +++ b/examples/bare4.rs @@ -27,8 +27,8 @@ use address::*; #[inline(always)] fn read_u32(addr: u32) -> u32 { - //unsafe { core::ptr::read_volatile(addr as *const _) } - core::ptr::read_volatile(addr as *const _) + unsafe { core::ptr::read_volatile(addr as *const _) } + //core::ptr::read_volatile(addr as *const _) } #[inline(always)] diff --git a/examples/bare5.rs b/examples/bare5.rs index 8d5b12289f0f3d46886ab5822808c360f9b7e5e3..eaf19e296661162064a262aae028eabb5198a5fb 100644 --- a/examples/bare5.rs +++ b/examples/bare5.rs @@ -126,6 +126,7 @@ fn main() { idle(rcc, gpioa); } + // user application fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { let rcc_copy = &rcc; @@ -140,18 +141,35 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) { // and alter the data output through the BSRR register // this is more efficient as the read register is not needed. + let gbh: u32 = 0x40000000 + 0x00020000+ 0x18; + loop { // 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); // 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); + } + +} + +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), // 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