Skip to content
Snippets Groups Projects
Commit 47812ef5 authored by Per's avatar Per
Browse files

added GPIO

parent fbe2c008
Branches
No related tags found
No related merge requests found
......@@ -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
......@@ -39,5 +39,17 @@
"isDefault": true
}
},
{
"type": "shell",
"label": "xargo build --example gpio",
"command": "xargo build --example gpio",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
]
}
\ No newline at end of file
......@@ -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 = []
......
......
//! 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();
}
}
//! 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]
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment