Getting panic when running Rust-Embedded code to set GPIO mode

Viewed 97

So since I worked on a C HAL for STM32 I really wanted to switch to Rust-Embedded. I already did some projects in Rust but just started working with Rust-Embedded.
So I started reworking my HAL with Rust and started with the GPIO drivers.
The problem now is, when I try to execute an unsafe{} code, I get a panic and the STM32 stops executing:

pub fn gpio_b_enable(pin: u8, mode: gpio_mode) {
    let periph = Peripherals::take().unwrap();
    periph.rcc.ahb1enr.modify(|_, w| w.gpioben().set_bit());
    periph.GPIOB.moder.modify(|_, w| unsafe{ w.bits((mode as u32) << (pin * 2))});
}

Following panic happens in the last line of the function.

halted: PC: 0x080009c4                                                                                                                                                                                                                                                                                                                                                                                           
Breakpoint 3, panic_halt::panic (_info=0x2001ff20) at /home/sl7/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-halt-0.2.0/src/lib.rs:33                                                              
33              atomic::compiler_fence(Ordering::SeqCst);

I'm new to Rust-Embedded, I will be really thankful if you could explain why the panic occurs

0 Answers
Related