Skip to content
Snippets Groups Projects
Commit 09637d1d authored by Johannes Sjölund's avatar Johannes Sjölund
Browse files

Add stuff

parent f7111f9e
No related branches found
No related tags found
No related merge requests found
File added
docs/Nucleo_f411re.png

553 KiB

docs/Nucleo_f411re_morpho.png

470 KiB

File added
File added
......@@ -46,7 +46,7 @@ app! {
// INITIALIZATION PHASE
fn init(p: init::Peripherals, _r: init::Resources) {
led::init(p.GPIOA, p.RCC);
led::init(p.GPIOB, p.RCC);
let serial = Serial(p.USART2);
serial.init(BAUD_RATE.invert(), Some(p.DMA1), p.GPIOA, p.RCC);
......
......@@ -35,7 +35,7 @@ app! {
// INITIALIZATION PHASE
fn init(p: init::Peripherals, _r: init::Resources) {
led::init(p.GPIOA, p.RCC);
led::init(p.GPIOB, p.RCC);
p.SYST.set_clock_source(SystClkSource::Core);
p.SYST.set_reload(16_000_000 / DIVISOR);
......
//! User LEDs
use stm32f40x::{GPIOA, RCC};
use stm32f40x::{GPIOB, RCC};
/// All the user LEDs
pub static LEDS: [Led; 1] = [
pub static LEDS: [Led; 8] = [
Led { i: 2 },
Led { i: 1 },
Led { i: 15 },
Led { i: 14 },
Led { i: 13 },
Led { i: 5 },
Led { i: 4 },
Led { i: 10 },
];
/// An LED
......@@ -16,28 +23,35 @@ impl Led {
/// Turns off the LED
pub fn off(&self) {
// NOTE(safe) atomic write
unsafe { (*GPIOA.get()).bsrr.write(|w| w.bits(1 << (self.i + 16))) }
unsafe { (*GPIOB.get()).bsrr.write(|w| w.bits(1 << (self.i + 16))) }
}
/// Turns on the LED
pub fn on(&self) {
// NOTE(safe) atomic write
unsafe { (*GPIOA.get()).bsrr.write(|w| w.bits(1 << self.i)) }
unsafe { (*GPIOB.get()).bsrr.write(|w| w.bits(1 << self.i)) }
}
}
/// Initializes all the user LEDs
pub fn init(gpioa: &GPIOA, rcc: &RCC) {
pub fn init(gpioa: &GPIOB, rcc: &RCC) {
// Power up peripherals
rcc.ahb1enr.modify(|_, w| w.gpioaen().set_bit());
rcc.ahb1enr.modify(|_, w| w.gpioben().set_bit());
// Configure pins 8-15 as outputs
gpioa
.moder
.modify(
|_, w| {
w.moder5()
.bits(1)
|_, w| {unsafe {
w.moder2().bits(1)
.moder1().bits(1)
.moder15().bits(1)
.moder14().bits(1)
.moder13().bits(1)
.moder5().bits(1)
.moder4().bits(1)
.moder10().bits(1)
}
},
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment