Skip to content

After blinking the LEDs. I started with the chapter register and on the first page itself I got some issues. I read about most of them and find out that the address is const and to use that fixed value we used raw pointer GPIOE_BSRR as *mut u32 which is making a copy of the address(referencing) variable and allowing us to change. #351

@NitinSaxenait

Description

@NitinSaxenait

After blinking the LEDs. I started with the chapter register and on the first page itself I got some issues. I read about most of them and find out that the address is const and to use that fixed value we used raw pointer GPIOE_BSRR as *mut u32 which is making a copy of the address(referencing) variable and allowing us to change.
Second, we are dereferencing using * and putting the statement inside the unsafe block as per the raw pointer deference rules..

I hope till here i am getting it right now the next issue is what we are doing at right-hand side using the shift operator. We are using 9 11 to set and 16, 25 to reset but why 1 in every shift?

`#![no_main]
#![no_std]

#[allow(unused_imports)]
use aux7::{entry, iprint, iprintln};

#[entry]
fn main() -> ! {
aux7::init();

{
// A magic address!
const GPIOE_BSRR: u32 = 0x48001018;

    // Turn on the "North" LED (red)
    //we use the dereference operator * on a raw pointer that requires an unsafe block.
    //change data through the mutable pointer
    (GPIOE_BSRR as *mut u32) = 1 << 9;

    // Turn on the "East" LED (green)
    *(GPIOE_BSRR as *mut u32) = 1 << 11;

    // Turn off the "North" LED
    (GPIOE_BSRR as *mut u32) = 1 << (9 + 16);

    // Turn off the "East" LED
    (GPIOE_BSRR as *mut u32) = 1 << (11 + 16);
}
loop {}

}
`
@adamgreig

Originally posted by @NitinSaxenait in #193 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions