From 80181ef22c82c117ab6e0f945c745d0ba7a01d6e Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Wed, 29 Jan 2025 20:27:39 +0100 Subject: [PATCH 1/2] Not working in release mode --- examples/broken.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 examples/broken.rs diff --git a/examples/broken.rs b/examples/broken.rs new file mode 100644 index 00000000..d4811f76 --- /dev/null +++ b/examples/broken.rs @@ -0,0 +1,29 @@ +//This example puts the timer in PWM mode using the specified pin with a frequency of 100Hz and a duty cycle of 50%. +#![no_main] +#![no_std] + +use cortex_m_rt::entry; +use utils::logger::println; +use hal::gpio::AF6; +use hal::prelude::*; +use hal::stm32; +use stm32g4xx_hal as hal; +extern crate cortex_m_rt as rt; + +#[macro_use] +mod utils; + +#[entry] +fn main() -> ! { + let dp = stm32::Peripherals::take().expect("cannot take peripherals"); + let mut rcc = dp.RCC.constrain(); + + let gpioa = dp.GPIOA.split(&mut rcc); + let _pin: stm32g4xx_hal::gpio::gpioa::PA8> = + gpioa.pa8.into_alternate(); + let mut pin2 = gpioa.pa9.into_pull_up_input(); + defmt::println!("hej"); + pin2.is_high().unwrap(); // <--- Booom + + loop {} +} From ed2504b4ab129ff0ffc85f729a527902bf9de2de Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Thu, 30 Jan 2025 21:29:37 +0100 Subject: [PATCH 2/2] Enable *and* reset gpio in split method --- src/gpio.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gpio.rs b/src/gpio.rs index b0bac608..22ff324b 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -1,8 +1,8 @@ //! General Purpose Input / Output use core::marker::PhantomData; -use crate::rcc::Rcc; -use crate::stm32::EXTI; +use crate::rcc::{Enable, Rcc, Reset}; +use crate::stm32::{self, EXTI}; use crate::syscfg::SysCfg; /// Default pin mode @@ -256,8 +256,13 @@ macro_rules! gpio { impl GpioExt for $GPIOX { type Parts = Parts; - fn split(self, rcc: &mut Rcc) -> Parts { - rcc.rb.ahb2enr().modify(|_, w| w.$iopxenr().set_bit()); + fn split(self, _rcc: &mut Rcc) -> Parts { + unsafe { + let rcc_ptr = &(*stm32::RCC::ptr()); + $GPIOX::enable(rcc_ptr); + $GPIOX::reset(rcc_ptr); + }; + Parts { $( $pxi: $PXi { _mode: PhantomData },