Reading from external input and setting the LEDs

Next: analog input
This commit is contained in:
Colin 2019-09-15 18:17:33 -07:00
commit 74de03ea3c
4 changed files with 175 additions and 0 deletions

14
Cargo.toml Normal file
View File

@ -0,0 +1,14 @@
[package]
authors = ["Colin <colin@uninsane.org>"]
edition = "2018"
name = "colin-ddr"
version = "0.1.0"
[dependencies]
cortex-m = "0.5.6"
cortex-m-rt = "0.6.3"
panic-itm = "0.4.0"
[dependencies.f3]
features = ["rt"]
version = "0.6.1"

10
openocd.gdb Normal file
View File

@ -0,0 +1,10 @@
target remote :3333
set print asm-demangle on
set print pretty on
monitor tpiu config internal itm.txt uart off 8000000
monitor itm port 0 on
load
break DefaultHandler
break UserHardFault
break main
continue

27
src/bsp.rs Normal file
View File

@ -0,0 +1,27 @@
//! Initialization code
pub use f3::hal::stm32f30x::{gpioa, gpioc, rcc};
use f3::hal::stm32f30x::{self, GPIOA, GPIOD, GPIOE, RCC};
pub struct Peripherals {
pub gpioa: &'static gpioa::RegisterBlock,
pub gpiod: &'static gpioc::RegisterBlock,
pub gpioe: &'static gpioc::RegisterBlock,
pub rcc: &'static rcc::RegisterBlock,
}
pub fn init() -> Peripherals {
// restrict access to the other peripherals
(stm32f30x::Peripherals::take().unwrap());
unsafe {
Peripherals {
gpioa: &*GPIOA::ptr(),
gpiod: &*GPIOD::ptr(),
gpioe: &*GPIOE::ptr(),
rcc: &*RCC::ptr(),
}
}
}

124
src/main.rs Normal file
View File

@ -0,0 +1,124 @@
#![no_main]
#![no_std]
// Which GPIOs are free to use??
// Rather, which are taken?
// PA0 - AIN_1 with some filtering
// PA2 - STLINK_TX
// PA3 - STLINK_RX
// PA5 - SCL/SPC, T_JTCK
// PA6 - SA0/SDO, T_JTDO
// PA7 - SDA/SDI/SDO, T_JTDI
// PA8 - MCO (with LPF)
// PA9 - maybe tied to PA11
// PA10 - maybe tied to PA12
// PA11 - D-, maybe tied to PA9
// PA12 - D+, maybe tied to PA10
// PA13 - TMS/SWDIO
// PA14 - TCK/SWCLK
// PA15 - JTDI
// PB0 - T_NRST
// PB2 - GND
// PB3 - T_SWO
// PB4 - JNTRST
// PB5 - SWIM_RST_IN
// PB6 - SWIM_RST, SCL
// PB7 - SWIM_IN, SDA
// PB8 - SWIM
// PB9 - SWIM_IN
// PB10 - SWIM_IN
// PB11 - SWIM
// PB12 - T_SWDIO_IN connected to PB14
// PB13 - T_JTCK
// PB14 - T_JTMS connected to PB12
// PC4 - USARTI_RX
// PC5 - USARTI_TX
// PC13 - 10k pulldown
// PC14 - 10k pulldown (not fitted) tied to PC14-OSC32_IN
// PC15 - tied to PC15-OSC32_OUT
// PE0 - INT1
// PE1 - DRDY/INT2
// PE2 - DRDY
// PE3 - CS_I2C/SPI
// PE4 - INT1
// PE5 - INT2
// PE8 - LD4 blue
// PE9 - LD3 red
// PE10 - LD5 orange
// PE11 - LD7 green
// PE12 - LD9 blue
// PE13 - LD10 red
// PE14 - LD8 orange
// PE15 - LD6 green
// PF0 - tied to PF0-OSC_IN
// PF1 - tied to PF1-OSC_OUT
//
// It looks like Port D is safe to use, most of port c
extern crate panic_itm; // panic handler
mod bsp;
use cortex_m::asm::bkpt;
use cortex_m_rt::entry;
#[entry]
fn main() -> ! {
let per = bsp::init();
// Configure clock gates
per.rcc.ahbenr.modify(|_, w| {
// enable IO Port A (push-button)
w.iopaen().set_bit();
// enable IO Pord D (piezo)
w.iopden().set_bit();
// enable IO Port E (LEDs)
w.iopeen().set_bit()
});
// All LEDS are outputs
per.gpioe.moder.modify(|_, w| {
// NB colin: there's also a .analog() mode!
w.moder8().output();
w.moder9().output();
w.moder10().output();
w.moder11().output();
w.moder12().output();
w.moder13().output();
w.moder14().output();
w.moder15().output()
});
// Configure push-button as input:
per.gpioa.moder.modify(|_, w| {
w.moder0().input()
});
// Configure piezo as digital input
per.gpiod.moder.modify(|_, w| {
w.moder0().input()
});
// Turn on all the LEDs in the compass
per.gpioe.odr.write(|w| {
w.odr8().set_bit();
w.odr9().set_bit();
w.odr10().set_bit();
w.odr11().set_bit();
w.odr12().set_bit();
w.odr13().set_bit();
w.odr14().set_bit();
w.odr15().set_bit()
});
bkpt();
loop {
//let push_button = per.gpioa.idr.read().idr0().bit();
let push_button = per.gpiod.idr.read().idr0().bit();
per.gpioe.odr.modify(|_, w| {
w.odr8().bit(push_button)
});
}
}