Skip to content
Permalink
Browse files

Using rtfm resources, overflow error?

  • Loading branch information...
franssl committed Nov 17, 2019
1 parent 0f7ce51 commit d833e8e1ab7ce380fa202a1672f4712bed588796
Showing with 63 additions and 40 deletions.
  1. +2 −2 openocd.gdb
  2. +61 −38 src/main.rs
@@ -24,15 +24,15 @@ monitor arm semihosting enable
# # send captured ITM to the file itm.fifo
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
# # 8000000 must match the core clock frequency
# monitor tpiu config internal itm.txt uart off 8000000
monitor tpiu config internal itm.txt uart off 48000000

# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
# # 8000000 must match the core clock frequency
# # 2000000 is the frequency of the SWO pin
# monitor tpiu config external uart off 8000000 2000000

# # enable ITM port 0
# monitor itm port 0 on
monitor itm port 0 on

load

@@ -1,54 +1,77 @@
#![deny(unsafe_code)]
#![deny(warnings)]

#![no_main]
#![no_std]

// Halt on panic
#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust#53964
extern crate panic_halt; // panic handler

use cortex_m;
use stm32f4xx_hal as hal;
use cortex_m::{iprint};
use stm32f4xx_hal;

use crate::stm32f4xx_hal::{prelude::*, stm32};
use cortex_m_semihosting::{debug, hprintln};
use rtfm::cyccnt::{Instant, U32Ext};

use crate::hal::{prelude::*, stm32};
const PERIOD: u32 = 48_000_000;

#[rtfm::app(device = stm32f4xx_hal)]
#[rtfm::app(device = stm32f4xx_hal::stm32, peripherals = true, monotonic = rtfm::cyccnt::CYCCNT)]
const APP: () = {
#[init]
fn init(_: init::Context) {
if let (Some(dp), Some(cp)) = (
stm32::Peripherals::take(),
cortex_m::peripheral::Peripherals::take(),
) {
// Set up the LED. On the Nucleo-446RE it's connected to pin PA5.
let gpioa = dp.GPIOA.split();
let mut led = gpioa.pa5.into_push_pull_output();
let mut led4 = gpioa.pa6.into_push_pull_output();

// Set up the system clock. We want to run at 48MHz for this one.
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(48.mhz()).freeze();

// Create a delay abstraction based on SysTick
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);

loop {
// On for 1s, off for 1s.
led.set_high().unwrap();
led4.set_low().unwrap();
delay.delay_ms(1000_u32);
led.set_low().unwrap();
led4.set_high().unwrap();
delay.delay_ms(1000_u32);
}
}

struct Resources {
led : stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>,
is_on : bool,
itm : cortex_m::peripheral::ITM

}

#[idle]
fn idle(_: idle::Context) -> ! {
//dp - device peripherals
#[init(schedule = [blinky])]
fn init(mut cx: init::Context) -> init::LateResources {
//cp - core peripherals
//let _core: cortex_m::Peripherals = cx.core;

// Device specific peripherals
let _device: stm32::Peripherals = cx.device;


// Set up the LED. On the Nucleo-446RE it's connected to pin PA5.
let gpioa = _device.GPIOA.split();
let led = gpioa.pa5.into_push_pull_output();

// Set up the system clock. We want to run at 48MHz for this one.
let rcc = _device.RCC.constrain();
rcc.cfgr.sysclk(48.mhz()).freeze();


// Initialize (enable) the monotonic timer (CYCCNT)
cx.core.DCB.enable_trace();
cx.core.DWT.enable_cycle_counter();
let itm = cx.core.ITM;

let now = cx.start;
cx.schedule.blinky(now + PERIOD.cycles()).unwrap();
init::LateResources { led, is_on: false, itm}

}

#[task(schedule = [blinky], resources = [led, itm])]
fn blinky(cx: blinky::Context) {

static mut IS_ON : bool = false;
let led = cx.resources.led;

if *IS_ON {
led.set_high().unwrap();
} else {
led.set_low().unwrap();
}
*IS_ON=!*IS_ON;

iprint!(&mut cx.resources.itm.stim[0], "{:?}", Instant::now());
cx.schedule.blinky(cx.scheduled + PERIOD.cycles()).unwrap();
}

loop {}
extern "C" {
fn USART1();
}
};

0 comments on commit d833e8e

Please sign in to comment.
You can’t perform that action at this time.