Skip to content

"Safe" pin manipulation not actually safe #178

@robomancer-or

Description

@robomancer-or

So this might be me setting something up wrong, but if so I really don't see what it is... here's how to recreate the bug:

I'm testing this on an STM32F407 with LEDs on the obvious pins

`fn main() {
let p = stm32f40x::Peripherals::take().unwrap();
p.RCC.ahb1enr.write(|w| w.gpioeen().enabled());
unsafe {
p.GPIOE.moder.modify(|r, w| w.bits(r.bits() | 0x0550_0000));
p.GPIOE.otyper.modify(|r, w| w.bits(r.bits() & 0b11_0000_1111_1111_11));
}
p.GPIOE.odr.write(|w| w.odr10().set_bit());
p.GPIOE.odr.write(|w| w.odr11().set_bit());
p.GPIOE.odr.write(|w| w.odr12().set_bit());
p.GPIOE.odr.write(|w| w.odr13().set_bit());

loop {
asm::nop();
}
}
`

Expected behavior: all 4 LEDs off (they're low side switched).

Observed behavior: only the LED connected to GPIOE_13 is off. You can modulate which LED is off by commenting out odrX set_bit calls that come after the target LED in the code.

My guess: the compiler is dicking around because some "don't mess with this" flag is missing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions