Skip to content
Snippets Groups Projects
Commit f168e7f5 authored by Otto Kalliorinne's avatar Otto Kalliorinne
Browse files
parents 8292aedc b242ea60
No related branches found
No related tags found
No related merge requests found
...@@ -18,8 +18,8 @@ dependencies = [ ...@@ -18,8 +18,8 @@ dependencies = [
"cortex-m-rtic", "cortex-m-rtic",
"cortex-m-semihosting", "cortex-m-semihosting",
"embedded-hal", "embedded-hal",
"panic-halt", "panic-rtt-target",
"rtt-target", "rtt-target 0.3.0",
"stm32f4 0.13.0", "stm32f4 0.13.0",
"stm32f4xx-hal", "stm32f4xx-hal",
"usb-device", "usb-device",
...@@ -245,10 +245,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" ...@@ -245,10 +245,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae"
[[package]] [[package]]
name = "panic-halt" name = "panic-rtt-target"
version = "0.2.0" version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812" checksum = "cfcd4deccf5edead7dcd0531448f0bab1b935e6d88e47225b4b7c6bd3a443180"
dependencies = [
"cortex-m 0.6.7",
"rtt-target 0.2.2",
]
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
...@@ -297,6 +301,15 @@ dependencies = [ ...@@ -297,6 +301,15 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "rtt-target"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0869b4c5b6a6d8c5583fc473f9eb3423a170f77626b8c8a7fb18eddcda5770e2"
dependencies = [
"ufmt-write",
]
[[package]] [[package]]
name = "rtt-target" name = "rtt-target"
version = "0.3.0" version = "0.3.0"
... ...
......
...@@ -14,13 +14,13 @@ embedded-hal = "0.2.4" ...@@ -14,13 +14,13 @@ embedded-hal = "0.2.4"
usb-device = "0.2.7" usb-device = "0.2.7"
# Panic handlers, comment all but one to generate doc! # Panic handlers, comment all but one to generate doc!
panic-halt = "0.2.0" #panic-halt = "0.2.0"
# Uncomment for the itm panic examples. # Uncomment for the itm panic examples.
#panic-itm = "0.4.2" #panic-itm = "0.4.2"
# Uncomment for the rtt-timing examples. # Uncomment for the rtt-timing examples.
#panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] } panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
# Uncomment for the semihosting examples. # Uncomment for the semihosting examples.
#panic-semihosting = "0.5.6" #panic-semihosting = "0.5.6"
... ...
......
...@@ -3,15 +3,31 @@ ...@@ -3,15 +3,31 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
use panic_halt as _; //use panic_halt as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use stm32f4::{self}; use stm32f4::{self};
use embedded_hal::spi::MODE_3; use embedded_hal::spi::MODE_3;
//use panic_rtt_target as _; use panic_rtt_target as _;
use rtic::cyccnt::{Instant, U32Ext as _}; use rtic::cyccnt::{Instant, U32Ext as _};
use stm32f4xx_hal::{dwt::Dwt, gpio::Speed, gpio::{Alternate, Input, Output, PullUp, PushPull, gpiob, gpioc::{self, PC6, PC7}}, prelude::*, rcc::Clocks, spi::Spi, stm32, timer}; use stm32f4xx_hal::{dwt::Dwt,
gpio::Speed,
gpio::{Alternate,
Input,
Output,
PullUp,
PushPull,
gpiob,
gpioc::{self,
PC6,
PC7}},
prelude::*,
rcc::Clocks,
spi::Spi,
stm32};
const OFFSET: u32 = 1_000_000;
#[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)] #[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)]
const APP: () = { const APP: () = {
...@@ -23,22 +39,24 @@ const APP: () = { ...@@ -23,22 +39,24 @@ const APP: () = {
DPIB1: gpiob::PB13<Input<PullUp>>, DPIB1: gpiob::PB13<Input<PullUp>>,
DPIB2: gpiob::PB12<Input<PullUp>>, DPIB2: gpiob::PB12<Input<PullUp>>,
MB5: gpiob::PB15<Input<PullUp>>, MB5: gpiob::PB15<Input<PullUp>>,
MB4: gpiob::PB14<Input<PullUp>>, MB4: gpiob::PB14<Input<PullUp>>
timer: timer::Timer<stm32::TIM3>
} }
#[init] #[init(schedule = [tick])]
fn init(cx: init::Context) -> init::LateResources { fn init(cx: init::Context) -> init::LateResources {
rtt_init_print!(); rtt_init_print!();
rprintln!("init"); rprintln!("init");
let device = cx.device; let device = cx.device;
let mut core = cx.core;
let rcc = device.RCC.constrain(); core.DCB.enable_trace();
core.DWT.enable_cycle_counter();
// 16 MHz (default, all clocks) let now = cx.start;
let clocks = rcc.cfgr.freeze();
cx.schedule.tick(now + OFFSET.cycles()).unwrap();
let gpioc = device.GPIOC.split(); let gpioc = device.GPIOC.split();
let gpiob = device.GPIOB.split(); let gpiob = device.GPIOB.split();
...@@ -52,10 +70,7 @@ const APP: () = { ...@@ -52,10 +70,7 @@ const APP: () = {
let dpib1 = gpiob.pb13.into_pull_up_input(); let dpib1 = gpiob.pb13.into_pull_up_input();
let dpib2 = gpiob.pb12.into_pull_up_input(); let dpib2 = gpiob.pb12.into_pull_up_input();
let mut timer = timer::Timer::tim3(device.TIM3, 1.khz(), clocks); init::LateResources { MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2}
timer.listen(timer::Event::TimeOut);
init::LateResources { MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2, timer }
} }
#[idle] #[idle]
...@@ -65,9 +80,8 @@ const APP: () = { ...@@ -65,9 +80,8 @@ const APP: () = {
} }
} }
#[task(binds = TIM3, priority = 1, resources = [MB1,MB2,MB4,MB5,DPIB1,DPIB2,timer])] #[task(priority = 1, resources = [MB1,MB2,MB4,MB5,DPIB1,DPIB2], schedule = [tick])]
fn tick(mut cx: tick::Context) { fn tick(mut cx: tick::Context) {
cx.resources.timer.clear_interrupt(timer::Event::TimeOut);
if cx.resources.MB1.is_low().unwrap() { if cx.resources.MB1.is_low().unwrap() {
rprintln!("MB1"); rprintln!("MB1");
} }
...@@ -86,7 +100,11 @@ const APP: () = { ...@@ -86,7 +100,11 @@ const APP: () = {
if cx.resources.DPIB2.is_low().unwrap() { if cx.resources.DPIB2.is_low().unwrap() {
rprintln!("DPIB2"); rprintln!("DPIB2");
} }
cx.schedule.tick(cx.scheduled + OFFSET.cycles()).unwrap();
} }
extern "C" {
fn EXTI0();
}
}; };
...@@ -277,6 +277,16 @@ const APP: () = { ...@@ -277,6 +277,16 @@ const APP: () = {
let gpioc = device.GPIOC.split(); let gpioc = device.GPIOC.split();
let gpiob = device.GPIOB.split(); let gpiob = device.GPIOB.split();
<<<<<<< HEAD
let mb2 = gpioc.pc6.into_pull_up_input();
let mb1 = gpioc.pc7.into_pull_up_input();
let mb5 = gpiob.pb15.into_pull_up_input();
let mb4 = gpiob.pb14.into_pull_up_input();
let dpib1 = gpiob.pb13.into_pull_up_input();
let dpib2 = gpiob.pb12.into_pull_up_input();
=======
// Buttons // Buttons
let mb2 = gpioc.pc6.into_pull_up_input(); let mb2 = gpioc.pc6.into_pull_up_input();
let mb1 = gpioc.pc7.into_pull_up_input(); let mb1 = gpioc.pc7.into_pull_up_input();
...@@ -306,6 +316,7 @@ const APP: () = { ...@@ -306,6 +316,7 @@ const APP: () = {
// set in burst mode // set in burst mode
pmw3389.write_register(Register::MotionBurst, 0x00); pmw3389.write_register(Register::MotionBurst, 0x00);
>>>>>>> 3043b359af07960fb4472e373824f552897ee4aa
// Pull the D+ pin down to send a RESET condition to the USB bus. // Pull the D+ pin down to send a RESET condition to the USB bus.
let mut usb_dp = gpioa.pa12.into_push_pull_output(); let mut usb_dp = gpioa.pa12.into_push_pull_output();
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment