Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // run with gdb, either from terminal or in vscode
- //
- // from terminal:
- // start openocd in separate terminal
- // > openocd -f openocd.cfg
- //
- // start gdb
- // > arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/examples/rtic_blinky -x openocd.gdb
- #![deny(unsafe_code)]
- #![deny(warnings)]
- #![no_main]
- #![no_std]
- use panic_semihosting as _;
- #[rtic::app(device = stm32f2xx_hal::stm32, dispatchers = [EXTI0], peripherals = true)]
- mod app {
- use cortex_m_semihosting::hprintln;
- use dwt_systick_monotonic::DwtSystick;
- use rtic::time::{duration::Seconds};
- const MONO_HZ: u32 = 8_000_000; // 8 MHz
- #[monotonic(binds = SysTick, default = true)]
- type MyMono = DwtSystick<MONO_HZ>;
- #[shared]
- struct Shared {
- gpioa: stm32f2xx_hal::stm32::GPIOA,
- toggle: bool,
- }
- #[local]
- struct Local {}
- #[init]
- fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
- let mut dcb = cx.core.DCB;
- let dwt = cx.core.DWT;
- let systick = cx.core.SYST;
- let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000); // maybe MONO_HZ?
- let device = cx.device;
- // 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));
- hprintln!("init").ok();
- // Schedule `toggle` to run 8e6 cycles (clock cycles) in the future
- toggle::spawn_after(Seconds(1u32)).ok();
- (
- Shared {
- gpioa: device.GPIOA,
- toggle: false,
- },
- Local {},
- init::Monotonics(mono),
- )
- }
- #[task(shared = [toggle, gpioa])]
- fn toggle(cx: toggle::Context) {
- let toggle = cx.shared.toggle;
- let gpioa = cx.shared.gpioa;
- (toggle, gpioa).lock(|toggle, gpioa| {
- hprintln!("toggle: {} @ !", toggle).unwrap();
- if *toggle {
- gpioa.bsrr.write(|w| w.bs5().set_bit());
- } else {
- gpioa.bsrr.write(|w| w.br5().set_bit());
- }
- *toggle = !*toggle;
- });
- toggle::spawn_after(Seconds(1u32)).ok();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement