diff --git a/code/Cargo.lock b/code/Cargo.lock index bd987c3544cedeb6e32b217ffd65792842715ff2..8499c420d19c9f991ea53b5c9d8dc44f1b143422 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -18,8 +18,8 @@ dependencies = [ "cortex-m-rtic", "cortex-m-semihosting", "embedded-hal", - "panic-halt", - "rtt-target", + "panic-rtt-target", + "rtt-target 0.3.0", "stm32f4 0.13.0", "stm32f4xx-hal", "usb-device", @@ -245,10 +245,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" [[package]] -name = "panic-halt" -version = "0.2.0" +name = "panic-rtt-target" +version = "0.1.1" 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]] name = "proc-macro2" @@ -297,6 +301,15 @@ dependencies = [ "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]] name = "rtt-target" version = "0.3.0" diff --git a/code/Cargo.toml b/code/Cargo.toml index 21177339a63859582871ffe8e8880de135dcee7f..fbede03661387d654bfdb89def8e34f34fc71617 100644 --- a/code/Cargo.toml +++ b/code/Cargo.toml @@ -14,13 +14,13 @@ embedded-hal = "0.2.4" usb-device = "0.2.7" # 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. #panic-itm = "0.4.2" # 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. #panic-semihosting = "0.5.6" diff --git a/code/examples/button_test.rs b/code/examples/button_test.rs index 0099c38eab94f54325cad01c1339e8dd0ae75637..d3bd892dbb61a5898b2a5e4d643f1fd2b6a91250 100644 --- a/code/examples/button_test.rs +++ b/code/examples/button_test.rs @@ -3,15 +3,31 @@ #![no_main] #![no_std] -use panic_halt as _; +//use panic_halt as _; use rtt_target::{rprintln, rtt_init_print}; use stm32f4::{self}; use embedded_hal::spi::MODE_3; -//use panic_rtt_target as _; +use panic_rtt_target 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)] const APP: () = { @@ -23,22 +39,24 @@ const APP: () = { DPIB1: gpiob::PB13<Input<PullUp>>, DPIB2: gpiob::PB12<Input<PullUp>>, MB5: gpiob::PB15<Input<PullUp>>, - MB4: gpiob::PB14<Input<PullUp>>, - timer: timer::Timer<stm32::TIM3> + MB4: gpiob::PB14<Input<PullUp>> } - #[init] + #[init(schedule = [tick])] fn init(cx: init::Context) -> init::LateResources { rtt_init_print!(); rprintln!("init"); 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 clocks = rcc.cfgr.freeze(); + let now = cx.start; + + cx.schedule.tick(now + OFFSET.cycles()).unwrap(); let gpioc = device.GPIOC.split(); let gpiob = device.GPIOB.split(); @@ -52,10 +70,7 @@ const APP: () = { let dpib1 = gpiob.pb13.into_pull_up_input(); let dpib2 = gpiob.pb12.into_pull_up_input(); - let mut timer = timer::Timer::tim3(device.TIM3, 1.khz(), clocks); - timer.listen(timer::Event::TimeOut); - - init::LateResources { MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2, timer } + init::LateResources { MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2} } #[idle] @@ -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) { - cx.resources.timer.clear_interrupt(timer::Event::TimeOut); if cx.resources.MB1.is_low().unwrap() { rprintln!("MB1"); } @@ -86,7 +100,11 @@ const APP: () = { if cx.resources.DPIB2.is_low().unwrap() { rprintln!("DPIB2"); } + cx.schedule.tick(cx.scheduled + OFFSET.cycles()).unwrap(); } + extern "C" { + fn EXTI0(); + } }; diff --git a/code/examples/rtt_rtic_usb_mouse.rs b/code/examples/rtt_rtic_usb_mouse.rs index c1c4d088f0c2f17f62c99fea184d3f79f9579e48..efb90fcc51c6159d8e1da643d82b80470ff3ff6d 100644 --- a/code/examples/rtt_rtic_usb_mouse.rs +++ b/code/examples/rtt_rtic_usb_mouse.rs @@ -15,8 +15,8 @@ use stm32f4xx_hal::{ gpio::{ Speed, Alternate, Input, Output, PullUp, PushPull, gpioa::{PA15}, - gpiob::{}, - gpioc::{PC6, PC7, PC10, PC11, PC12}, + gpiob, + gpioc::{self, PC6, PC7, PC10, PC11, PC12}, }, prelude::*, rcc::Clocks, @@ -266,6 +266,17 @@ const APP: () = { // assert!(clocks.usbclk_valid()); let gpioa = cx.device.GPIOA.split(); + let gpioc = cx.device.GPIOC.split(); + let gpiob = cx.device.GPIOB.split(); + + 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(); // Pull the D+ pin down to send a RESET condition to the USB bus. let mut usb_dp = gpioa.pa12.into_push_pull_output();