RTFM wfi in critical section not waking up

I'm trying to implement A CPU usage monitor for the RTFM framework in the current version of RTFM 0.5.1.
I'm calling wfi in a lock and the program is not waking up.
The program wakes properly when wfi in not in a critical section.
I've read the RTFM doc but I must be missing something.
I'm not sure if my code is wrong or that interrupts are disabled in critical sections.

#[idle(resources = [sleep_time,itm])]
    fn idle(cx: idle::Context) -> ! {
        let mut itm = cx.resources.itm;
        // let mut sleep_time = cx.resources.sleep_time;
        itm.lock(|itm| {
            iprintln!(&mut itm.stim[0], "idle");
        loop {
            // this code does not wake up
            // sleep_time.lock(|sleep_time: &mut u32| {
            //     let before = cortex_m::peripheral::DWT::get_cycle_count();
            //     cortex_m::asm::wfi();
            //     let after = cortex_m::peripheral::DWT::get_cycle_count();
            //     let elapsed = after.wrapping_sub(before);
            //     *sleep_time += elapsed;
            // });
1 Like

So I just figured out my mistake. The push button interrupt has to be a higher priority than the other task using sleep_time. Working now!


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.