2

I'm new to Rust. Currently I'm working on embedded rust using STM32F303 Discovery board. I am facing a lot of problems while accessing a registers and don't know How to access RCC, FLASH, TIMER and many more in order to complete the task. Can anybody help me out. You can check out the code where I got stuck.

     //! Initialization code

#![no_std]

#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust53964
extern crate panic_itm; // panic handler

pub use cortex_m::{asm::bkpt, iprint, iprintln, peripheral::ITM};
pub use cortex_m_rt::entry;
pub use f3::hal::{prelude, serial::Serial, stm32f30x::usart1, time::MonoTimer};

use f3::hal::{
    prelude::*,
    stm32f30x::{self, USART1},
};

pub fn init() -> (&'static mut usart1::RegisterBlock, MonoTimer, ITM) {
    let cp = cortex_m::Peripherals::take().unwrap();
    let dp = stm32f30x::Peripherals::take().unwrap();

    let mut flash = dp.FLASH.constrain();
    let mut rcc = dp.RCC.constrain();

    let clocks = rcc.cfgr.freeze(&mut flash.acr);

    let mut gpioa = dp.GPIOA.split(&mut rcc.ahb);

    let tx = gpioa.pa9.into_af7(&mut gpioa.moder, &mut gpioa.afrh);
    let rx = gpioa.pa10.into_af7(&mut gpioa.moder, &mut gpioa.afrh);

    Serial::usart1(dp.USART1, (tx, rx), 115_200.bps(), clocks, &mut rcc.apb2);
    // If you are having trouble sending/receiving data to/from the
    // HC-05 bluetooth module, try this configuration instead:
    // Serial::usart1(dp.USART1, (tx, rx), 9600.bps(), clocks, &mut rcc.apb2);

    unsafe {
        (
            &mut *(USART1::ptr() as *mut _),
            MonoTimer::new(cp.DWT, clocks),
            cp.ITM,
        )
    }
}
  • 1
    "I am facing a lot of problems" What problems? You'll need to be specific so that people can give you helpful answers. – loganfsmyth Mar 27 '20 at 02:12
  • I need to know, for what purpose we are using FLASH.constrain() and RCC.contrain(), which are already used in the code. – Fawad Ahmed Mar 27 '20 at 13:04

0 Answers0