diff --git a/.vscode/launch.json b/.vscode/launch.json index d3c2e2a128eba1866d959d64e480da7f53b0d0e5..822733975745f91aebca8adc45f67da9da4e1e3e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -58,5 +58,23 @@ ], "cwd": "${workspaceRoot}" }, + { + "type": "gdb", + "request": "attach", + "name": "gpio", + "gdbpath": "/usr/bin/arm-none-eabi-gdb", + "executable": "./target/thumbv7em-none-eabihf/debug/examples/gpio", + "target": ":3333", + "remote": true, + "autorun": [ + "monitor reset init", + "monitor arm semihosting enable", + "monitor tpiu config internal /tmp/itm.log uart off 64000000", + "monitor itm port 0 on", + "load", + "monitor reset init" + ], + "cwd": "${workspaceRoot}" + }, ] } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index c825d3b62539fbb79127f4217b20faef5e18213a..d2d5a4664d418c9789dc34933231b4ab644f4fc1 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -30,7 +30,19 @@ { "type": "shell", "label": "xargo build --example loop", - "command": "xargo build --example loop ", + "command": "xargo build --example loop", + "problemMatcher": [ + "$rustc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "xargo build --example gpio", + "command": "xargo build --example gpio", "problemMatcher": [ "$rustc" ], diff --git a/Cargo.toml b/Cargo.toml index c0f4057d5006a60ad979bfcd9850000a0cf79d57..22657d4f44e2620cfa32c713eaacfd95060b0b44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,10 @@ git = "https://gitlab.henriktjader.com/pln/STM32F40x.git" features = ["rt"] version = "0.1.0" +[dependencies.f4] +git = "https://github.com/jsjolund/f4" +version = "0.1.0" + [features] wcet_bkpt = [] wcet_nop = [] diff --git a/examples/gpio.rs b/examples/gpio.rs new file mode 100644 index 0000000000000000000000000000000000000000..eb398dce22566ec0a75de33081be7c69329f09c4 --- /dev/null +++ b/examples/gpio.rs @@ -0,0 +1,64 @@ +//! Simple access to gpio +#![deny(unsafe_code)] +#![feature(proc_macro)] +#![no_std] + +extern crate cortex_m; +extern crate cortex_m_rtfm as rtfm; +extern crate stm32f40x; + +use rtfm::app; + +app! { + device: stm32f40x, +} + +fn wait(i: u32) { + for _ in 0..i { + cortex_m::asm::nop(); // no operation (cannot be optimized out) + } +} + +// see the Reference Manual RM0368 (www.st.com/resource/en/reference_manual/dm00096844.pdf) +// rcc, chapter 6 +// gpio, chapter 8 + +fn init(p: init::Peripherals) { + // power on GPIOA, RM0368 6.3.11 + p.RCC.ahb1enr.modify(|_, w| w.gpioaen().set_bit()); + + // configure PA5 as output, RM0368 8.4.1 + p.GPIOA.moder.modify(|_, w| w.moder5().bits(1)); + + // loop { + // // set PA5 high, RM0368 8.4.6 + // p.GPIOA.odr.modify(|_, w| w.odr5().bit(true)); + // wait(10_000); + + // // set PA5 low, RM0368 8.4.6 + // p.GPIOA.odr.modify(|_, w| w.odr5().bit(false)); + // wait(10_000); + // } + + // rewrite the above code to have the GPIO as output + // and alter the data output through the BSRR register + // this is more efficient as the read register (in modify) + // is not needed. + + loop { + // set PA5 high, RM0368 8.4.7 + p.GPIOA.bsrr.write(|w| w.bs5().set_bit()); + wait(10_000); + + // set PA5 low, RM0368 8.4.7 + p.GPIOA.bsrr.write(|w| w.br5().set_bit()); + wait(10_000); + } +} + +#[inline(never)] +fn idle() -> ! { + loop { + rtfm::wfi(); + } +} diff --git a/examples/loop.rs b/examples/loop.rs index c98cd2dfdb10a608b65ce85a771d020372d16f20..30ea0f4338f1fa80bc663ec9f71539d51253f233 100644 --- a/examples/loop.rs +++ b/examples/loop.rs @@ -1,7 +1,4 @@ -//! Nesting claims and how the preemption threshold works -//! -//! If you run this program you'll hit the breakpoints as indicated by the -//! letters in the comments: A, then B, then C, etc. +//! Simple loop to calculate the sum of integers 0..10 #![deny(unsafe_code)] #![feature(proc_macro)] #![no_std]