Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/broken.rs
Original file line number Diff line number Diff line change
@@ -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<stm32g4xx_hal::gpio::Alternate<AF6>> =
gpioa.pa8.into_alternate();
let mut pin2 = gpioa.pa9.into_pull_up_input();
defmt::println!("hej");
pin2.is_high().unwrap(); // <--- Booom

loop {}
}
13 changes: 9 additions & 4 deletions src/gpio.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 },
Expand Down
Loading