diff --git a/.vscode/.cortex-debug.peripherals.state.json b/.vscode/.cortex-debug.peripherals.state.json index 0637a088a01e8ddab3bf3fa98dbe804cbde1a0dc..e2f2139a1427819d59854ccd9496b80fe32a8974 100644 --- a/.vscode/.cortex-debug.peripherals.state.json +++ b/.vscode/.cortex-debug.peripherals.state.json @@ -1 +1 @@ -[] \ No newline at end of file +[{"node":"UART9","expanded":true,"format":0},{"node":"USART2.SR","expanded":true,"format":0}] \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index f7747fef91e5e7d0380504c0092c82640ce7acb0..8a618295510500eb16e5c9d992062a0add863945 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -184,6 +184,34 @@ "svdFile": "STM32F413.svd", "cwd": "${workspaceRoot}" }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "rtfm_blinky (debug)", + "preLaunchTask": "cargo build --example rtfm_blinky", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/rtfm_blinky", + // uses local config files + "configFiles": [ + "./stlink.cfg", + "./stm32f4x.cfg" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM", + "port": 0 + } + ] + }, + "svdFile": "STM32F413.svd", + "cwd": "${workspaceRoot}" + }, { "type": "cortex-debug", "request": "launch", @@ -609,5 +637,69 @@ "svdFile": "STM32F413.svd", "cwd": "${workspaceRoot}" }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "bare10 (reselase)", + "preLaunchTask": "cargo build --example bare10 --release", + "executable": "./target/thumbv7em-none-eabihf/release/examples/bare10", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32f4x.cfg" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM0", + "port": 0 + }, + { + "type": "console", + "label": "ITM1", + "port": 1 + } + ] + }, + "svdFile": "STM32F413.svd", + "cwd": "${workspaceRoot}" + }, + { + "type": "cortex-debug", + "request": "launch", + "servertype": "openocd", + "name": "bare10 (debug)", + "preLaunchTask": "cargo build --example bare10", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/bare10", + "configFiles": [ + "interface/stlink.cfg", + "target/stm32f4x.cfg" + ], + "swoConfig": { + "enabled": true, + "cpuFrequency": 16000000, + "swoFrequency": 2000000, + "source": "probe", + "decoders": [ + { + "type": "console", + "label": "ITM0", + "port": 0 + }, + // { + // "type": "console", + // "label": "ITM1", + // "port": 1 + // } + ] + }, + "svdFile": "STM32F413.svd", + "cwd": "${workspaceRoot}" + }, ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 8436e314a33e1975ebb68fce7260acdc2cf37e30..bf7899aa65c7c6108fc824b9549827501cb992bc 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -87,6 +87,18 @@ "isDefault": true } }, + { + "type": "shell", + "label": "cargo build --example rtfm_blinky", + "command": "cargo build --example rtfm_blinky --features \"hal rtfm\"", + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, { "type": "shell", "label": "cargo build --example rtfm_interrupt --features \"pac rtfm\"", @@ -267,5 +279,29 @@ "isDefault": true } }, + { + "type": "shell", + "label": "cargo build --example bare10", + "command": "cargo build --example bare10 --features \"hal rtfm\"", + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "cargo build --example bare10 --release", + "command": "cargo build --example bare10 --release --features \"hal rtfm\"", + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, ] } \ No newline at end of file diff --git a/examples/bare9.rs b/examples/bare9.rs index 5cbd3b786e0371cd7f7081f8596b27cc62a82b7f..6000b7396b3d542bd79840aebd47ff5a8443509c 100644 --- a/examples/bare9.rs +++ b/examples/bare9.rs @@ -14,11 +14,11 @@ use hal::stm32::ITM; use heapless::consts::*; use heapless::spsc::{Consumer, Producer, Queue}; +use nb::block; use rtfm::app; #[app(device = hal::stm32)] - const APP: () = { // Late resources static mut TX: Tx<hal::stm32::USART2> = (); @@ -38,7 +38,7 @@ const APP: () = { let (producer, consumer) = RB.as_mut().unwrap().split(); let stim = &mut core.ITM.stim[0]; - iprintln!(stim, "start"); + iprintln!(stim, "bare9"); let rcc = device.RCC.constrain(); @@ -49,6 +49,7 @@ const APP: () = { let tx = gpioa.pa2.into_alternate_af7(); let rx = gpioa.pa3.into_alternate_af7(); // try comment out + // let rx = gpioa.pa3.into_alternate_af6(); // try uncomment let mut serial = Serial::usart2( device.USART2, @@ -101,7 +102,7 @@ const APP: () = { match rx.read() { Ok(byte) => { - let _ = tx.write(byte); + block!(tx.write(byte)).unwrap(); match resources.PRODUCER.enqueue(byte) { Ok(_) => {} Err(_) => asm::bkpt(), diff --git a/examples/rtfm_blinky.rs b/examples/rtfm_blinky.rs new file mode 100644 index 0000000000000000000000000000000000000000..7297c645cae59b11496129a7ddbb51e23cc28cf3 --- /dev/null +++ b/examples/rtfm_blinky.rs @@ -0,0 +1,46 @@ +#![no_main] +#![no_std] + +extern crate panic_halt; + +use cortex_m::peripheral::syst::SystClkSource; +use stm32f4::stm32f413::GPIOA; + +use rtfm::app; + +#[app(device = stm32f4::stm32f413)] +const APP: () = { + // late resorce binding + static mut GPIOA: GPIOA = (); + + // init runs in an interrupt free section + #[init] + fn init() { + // configures the system timer to trigger a SysTick exception every second + core.SYST.set_clock_source(SystClkSource::Core); + core.SYST.set_reload(16_000_000); // period = 1s + core.SYST.enable_counter(); + core.SYST.enable_interrupt(); + + // power on GPIOA, RM0368 6.3.11 + device.RCC.ahb1enr.modify(|_, w| w.gpioaen().set_bit()); + // configure PA5 as output, RM0368 8.4.1 + device.GPIOA.moder.modify(|_, w| w.moder5().bits(1)); + + // pass on late resources + GPIOA = device.GPIOA; + } + + #[exception (resources = [GPIOA])] + fn SysTick() { + static mut TOGGLE: bool = false; + + if *TOGGLE { + GPIOA.bsrr().write(|w| w.bs5().set_bit()); + } else { + GPIOA.bsrr.write(|w| w.br5().set_bit()); + } + + *TOGGLE = !TOGGLE; + } + };