Read values from the ADC and pipe them to the terminal
These values look realistic!
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
pub use f3::hal::stm32f30x::{adc1, gpioa, gpioc, rcc};
|
pub use f3::hal::stm32f30x::{adc1, gpioa, gpioc, rcc};
|
||||||
|
|
||||||
use f3::hal::stm32f30x::{self, ADC1, ADC1_2, GPIOA, GPIOD, GPIOE, RCC};
|
use f3::hal::stm32f30x::{self, ADC1, ADC1_2, ITM, GPIOA, GPIOD, GPIOE, RCC};
|
||||||
|
|
||||||
pub struct Peripherals {
|
pub struct Peripherals {
|
||||||
pub gpioa: GPIOA,
|
pub gpioa: GPIOA,
|
||||||
@@ -11,12 +11,14 @@ pub struct Peripherals {
|
|||||||
pub gpioe: GPIOE,
|
pub gpioe: GPIOE,
|
||||||
pub rcc: RCC,
|
pub rcc: RCC,
|
||||||
pub adc1: ADC1,
|
pub adc1: ADC1,
|
||||||
pub adc1_2: ADC1_2
|
pub adc1_2: ADC1_2,
|
||||||
|
pub itm: ITM,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init() -> Peripherals {
|
pub fn init() -> Peripherals {
|
||||||
// restrict access to the other peripherals
|
// restrict access to the other peripherals
|
||||||
let per = stm32f30x::Peripherals::take().unwrap();
|
let per = stm32f30x::Peripherals::take().unwrap();
|
||||||
|
let core_per = stm32f30x::CorePeripherals::take().unwrap();
|
||||||
|
|
||||||
Peripherals {
|
Peripherals {
|
||||||
gpioa: per.GPIOA,
|
gpioa: per.GPIOA,
|
||||||
@@ -25,5 +27,6 @@ pub fn init() -> Peripherals {
|
|||||||
rcc: per.RCC,
|
rcc: per.RCC,
|
||||||
adc1: per.ADC1,
|
adc1: per.ADC1,
|
||||||
adc1_2: per.ADC1_2,
|
adc1_2: per.ADC1_2,
|
||||||
|
itm: core_per.ITM,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -112,12 +112,13 @@ extern crate panic_itm; // panic handler
|
|||||||
|
|
||||||
mod bsp;
|
mod bsp;
|
||||||
|
|
||||||
|
use cortex_m::iprintln;
|
||||||
use cortex_m::asm::{bkpt, delay};
|
use cortex_m::asm::{bkpt, delay};
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let per = bsp::init();
|
let mut per = bsp::init();
|
||||||
|
|
||||||
// Configure clock gates
|
// Configure clock gates
|
||||||
per.rcc.ahbenr.modify(|_, w| {
|
per.rcc.ahbenr.modify(|_, w| {
|
||||||
@@ -235,6 +236,7 @@ fn main() -> ! {
|
|||||||
per.gpioe.odr.modify(|_, w| {
|
per.gpioe.odr.modify(|_, w| {
|
||||||
w.odr8().bit(push_button)
|
w.odr8().bit(push_button)
|
||||||
});
|
});
|
||||||
|
iprintln!(&mut per.itm.stim[0], "ADC: {:x}", per.adc1.dr.read().bits());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user