Skip to content
Snippets Groups Projects
Commit 42377ea6 authored by Ridge's avatar Ridge
Browse files

bare5_1

parent 8e495dd8
No related branches found
No related tags found
No related merge requests found
......@@ -55,15 +55,13 @@ fn wait(i: u32) {
#[entry]
fn main() -> ! {
// configure PA5 as output
let r = read_u32(GPIOA_MODER) & !(0b11 << (5 * 2)); // read and mask
write_u32(GPIOA_MODER, r | 0b01 << (5 * 2)); // set output mode
// power on GPIOA
let r = read_u32(RCC_AHB1ENR); // read
write_u32(RCC_AHB1ENR, r | 1); // set enable
// configure PA5 as output
let r = read_u32(GPIOA_MODER) & !(0b11 << (5 * 2)); // read and mask
write_u32(GPIOA_MODER, r | 0b01 << (5 * 2)); // set output mode
// and alter the data output through the BSRR register
// this is more efficient as the read register is not needed.
......@@ -124,16 +122,18 @@ fn main() -> ! {
//
// Why is it important that ordering of volatile operations are ensured by the compiler?
//
// ** your answer here **
// Some operations have to be executed in a specific order or the code will not act as it's desired.
// Dependencies might also be affected by the order of code.
//
// Give an example in the above code, where reordering might make things go horribly wrong
// (hint, accessing a peripheral not being powered...)
//
// ** your answer here **
// Example is changing the configure of PA5 and putting it before the power on GPIO
// resulting in the LED not blinking.
//
// Without the non-reording proprety of `write_volatile/read_volatile` could that happen in theory
// (argue from the point of data dependencies).
//
// ** your answer here **
// If we read/write in the wrong order, we'd end up getting unexpected results, which obviously isn't good.
//
// Commit your answers (bare4_3)
......@@ -186,14 +186,14 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) {
loop {
// set PA5 high
gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led)
// gpioa.ODR.write(gpioa.ODR.read() | (1 << 5));
// gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led)
gpioa.ODR.write(gpioa.ODR.read() | (1 << 5));
wait(10_000);
// set PA5 low
gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
// gpioa.ODR.write(gpioa.ODR.read() & !(1 << 5));
// gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
gpioa.ODR.write(gpioa.ODR.read() & !(1 << 5));
wait(10_000);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment