You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I am trying to print the current time/tick of the program usingthe debugger console via the macro: hprintln!. I am having trouble taking the time of the monotonics timer. I want to be able to this:
#[task(local = [led1])]
fn blink(cx: blink::Context) {
let now = mono.now();
hprintln!("Blink 1: {}", now);
mono is defined in the init task as:
let mut mono: Systick<1000> = Systick::new(cx.core.SYST, 36_000_000);
I trined to make the mono a shared resource but the function signature of the init task must be as follows:
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics)
I return the next tuple from the init task:
(
Shared {},
Local {
led1,
led2
},
init::Monotonics(mono),
)
And now I cannot access mono in my blink tasks.
The entire code is given below:
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_rtt_target as _;
use rtic::app;
use rtt_target::{rprintln, rtt_init_print};
use stm32f3xx_hal::gpio::{Output, PushPull};
use stm32f3xx_hal::prelude::*;
use systick_monotonic::{fugit::Duration, Systick};
#[app(device = stm32f3xx_hal::pac, peripherals = true, dispatchers = [SPI1, SPI2])]
mod app {
use stm32f3xx_hal::gpio::{PE8, PE9};
use cortex_m_semihosting::hprintln;
use super::*;
#[shared]
struct Shared {}
#[local]
struct Local {
led1: PE8<Output<PushPull>>,
led2: PE9<Output<PushPull>>,
}
#[monotonic(binds = SysTick, default = true)]
type MonoTimer = Systick<1000>;
const SLEEP_TIME: u64 = 1;
#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
// Setup clocks
let mut flash = cx.device.FLASH.constrain();
let mut rcc = cx.device.RCC.constrain();
let mut mono: Systick<1000> = Systick::new(cx.core.SYST, 36_000_000);
rtt_init_print!();
rprintln!("init");
let now = mono.now();
hprintln!("{}", now);
let _clocks = rcc
.cfgr
.use_hse(8.MHz())
.sysclk(36.MHz())
.pclk1(36.MHz())
.freeze(&mut flash.acr);
// Setup LED
let mut gpioe = cx.device.GPIOE.split(&mut rcc.ahb);
let mut led1 = gpioe
.pe8
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
led1.set_high().unwrap();
let led2 = gpioe
.pe9
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
// Schedule the blinking task
blink::spawn_after(Duration::<u64, 1, 1000>::from_ticks(SLEEP_TIME)).unwrap();
blink2::spawn_after(Duration::<u64, 1, 1000>::from_ticks(SLEEP_TIME)).unwrap();
(
Shared {},
Local {
led1,
led2
},
init::Monotonics(mono),
)
}
#[task(local = [led1])]
fn blink(cx: blink::Context) {
let now = mono.now();
hprintln!("Blink 1: {}", now);
cx.local.led1.toggle().unwrap();
blink::spawn_after(Duration::<u64, 1, 1000>::from_ticks(SLEEP_TIME)).unwrap();
}
#[task(local = [led2], priority = 1)]
fn blink2(cx: blink2::Context) {
let now = mono.now(); /// not available in this scope
hprintln!("Blink 1: {}", now);
cx.local.led2.toggle().unwrap();
blink2::spawn_after(Duration::<u64, 1, 1000>::from_ticks(SLEEP_TIME)).unwrap();
}
}
Is there a way to accomplish this using mono, or should I use a different approach?
The text was updated successfully, but these errors were encountered:
Spago123
changed the title
How to get time step in a RTIC Rust Embedded application
How to get the time stamp in a RTIC Rust Embedded application
May 23, 2024
@Spago123 based on your code it looks like you're using an older version of rtic-monotonics, but if you upgrade to the latest version you can call Systick::now() to get a timestamp.
let systick_mono_token = rtic_monotonics::create_systick_token!();
Systick::start(core.SYST, SYS_CLOCK_MHZ.MHz::<1, 1>().raw(), systick_mono_token);
let now = Systick::now();
In the latest version it's a static method so you can call it from anywhere, as long as it's been started previously.
Hello, I am trying to print the current time/tick of the program usingthe debugger console via the macro: hprintln!. I am having trouble taking the time of the monotonics timer. I want to be able to this:
mono is defined in the init task as:
I trined to make the mono a shared resource but the function signature of the init task must be as follows:
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics)
I return the next tuple from the init task:
And now I cannot access mono in my blink tasks.
The entire code is given below:
Is there a way to accomplish this using mono, or should I use a different approach?
The text was updated successfully, but these errors were encountered: