0xBAAAAAAD address

    This address is close to the GPIOE_BSRR address we used before but this address is invalid.Invalid in the sense that there’s no register at this address.

    Now, let’s try it.

    1. $ cargo run
    2. Breakpoint 3, main () at src/07-registers/src/main.rs:9
    3. 9 aux7::init();
    4. (gdb) continue
    5. Continuing.
    6. Breakpoint 2, UserHardFault_ (ef=0x10001fc0)
    7. at $REGISTRY/cortex-m-rt-0.6.3/src/lib.rs:535
    8. 535 loop {

    We tried to do an invalid operation, reading memory that doesn’t exist, so the processor raised anexception, a hardware exception.

    There are different kind of exceptions. Each kind of exception is raised by different conditions andeach one is handled by a different exception handler.

    The aux7 crate depends on the cortex-m-rt crate which defines a defaulthard fault handler, named UserHardFault, that handles the “invalid memoryaddress” exception. openocd.gdb placed a breakpoint on ; that’s whythe debugger halted your program while it was executing the exception handler.We can get more information about the exception from the debugger. Let’s see:

    ef is a snapshot of the program state right before the exception occurred. Let’s inspect it:

    1. $1 = cortex_m_rt::ExceptionFrame {
    2. r0: 0x48001800,
    3. r1: 0x48001800,
    4. r2: 0xb,
    5. r3: 0xc,
    6. r12: 0xd,
    7. lr: 0x800019f,
    8. pc: 0x80028d6,
    9. xpsr: 0x1000000
    10. }

    The exception was caused by the ldr r0, [r0, #0] instruction, a read instruction. The instructiontried to read the memory at the address indicated by the r0 register. By the way, r0 is a CPU(processor) register not a memory mapped register; it doesn’t have an associated address like, say,.

    Wouldn’t it be nice if we could check what the value of the r0 register was right at the instantwhen the exception was raised? Well, we already did! The r0 field in the ef value we printedbefore is the value of r0 register had when the exception was raised. Here it is again:

    1. $1 = cortex_m_rt::ExceptionFrame {
    2. r0: 0x48001800,
    3. r1: 0x48001800,
    4. r2: 0xb,
    5. r3: 0xc,
    6. r12: 0xd,
    7. lr: 0x800019f,
    8. pc: 0x80028d6,
    9. xpsr: 0x1000000
    10. }

    r0 contains the value which is the invalid address we called the read_volatilefunction with.