embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
4.86k stars 660 forks source link

Panic running examples/stm32f4/multiprio.rs using embassy from github #2749

Open uliano opened 3 months ago

uliano commented 3 months ago

It works flawlessly with the versioned releases:

embassy-stm32 = { version = "0.1.0" , features =  ["defmt", "time-driver-any", "stm32f446re", "memory-x", "unstable-pac", "exti"] }
embassy-executor = {version = "0.5.0" , features = ["defmt", "arch-cortex-m", "executor-thread", "executor-interrupt", "integrated-timers"] }
embassy-time = { version = "0.3.0", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }

when switched to git = "https://github.com/embassy-rs/embassy" gives the following log:

 WARN defmt_decoder::log::format: logger format contains timestamp but no timestamp implementation was provided; consider removing the timestamp (`{t}` or `{T}`) from the logger format or provide a `defmt::timestamp!` implementation
0.000000 INFO  Hello World!
└─ multiprio::__cortex_m_rt_main @ src\bin\multiprio.rs:126
0.000000 TRACE BDCR ok: 00008200
└─ embassy_stm32::rcc::bd::{impl#2}::init @ C:\Users\uliano\.cargo\git\checkouts\embassy-9312dcb0ed774b29\81cf9d1\embassy-stm32\src\fmt.rs:117
0.000000 DEBUG flash: latency=0
└─ embassy_stm32::rcc::_version::init @ C:\Users\uliano\.cargo\git\checkouts\embassy-9312dcb0ed774b29\81cf9d1\embassy-stm32\src\fmt.rs:130
0.000000 DEBUG rcc: Clocks { hclk1: Some(Hertz(16000000)), hclk2: Some(Hertz(16000000)), hclk3: Some(Hertz(16000000)), hsi_div488: Some(Hertz(32786)), lse: None, pclk1: Some(Hertz(16000000)), pclk1_tim: Some(Hertz(16000000)), pclk2: Some(Hertz(16000000)), pclk2_tim: Some(Hertz(16000000)), pll1_q: None, pllsai1_q: None, rtc: Some(Hertz(32000)), sys: Some(Hertz(16000000)) }
└─ embassy_stm32::rcc::set_freqs @ C:\Users\uliano\.cargo\git\checkouts\embassy-9312dcb0ed774b29\81cf9d1\embassy-stm32\src\fmt.rs:130
0.000488 INFO          [high] tick!
└─ multiprio::__run_high_task::{async_fn#0} @ src\bin\multiprio.rs:71
0.001281 ERROR panicked at 'unwrap failed: embassy_time_driver :: allocate_alarm()'
error: `Unwrap of a None option value`
└─ embassy_executor::raw::{impl#9}::new @ C:\Users\uliano\.cargo\git\checkouts\embassy-9312dcb0ed774b29\81cf9d1\embassy-executor\src\fmt.rs:179
qff233 commented 3 months ago

I have a same problem. My chip is stm32g474vetx. When I use embassy_time::Timer::after_ticks(22222).await in one of tasks, it have same error panicked at embassy_time_driver::allocate_alarm() Here is my code:

#[embassy_executor::task]
pub async fn foc_loop(
    foc: &'static FocMutex,
    mut vbus_adc: VbusAdc<peripherals::ADC2, peripherals::PC5>,
    mut uvw_adcs: Adcs<peripherals::ADC1, peripherals::PA0, peripherals::PA1, peripherals::PA2>,
    mut pwm: Pwms,
) {
    loop {

        info!("current_loop");
        // Timer::after_micros(244444).await
        Timer::after_ticks(22222).await;
    }
}
qff233 commented 3 months ago

I change crate feature from "time-driver-any" to "time-driver-tim3". It run flawlessly!

andresv commented 1 month ago

I stumbled upon the same issue ERROR panicked at 'unwrap failed: embassy_time_driver :: allocate_alarm() with stm32f411ce when converted my app to use 2 executors. Multiple executors idea was taken from: https://github.com/embassy-rs/embassy/blob/4a4b8c9b8de8eaf874372f6239dc1a220f172318/examples/stm32h7rs/src/bin/multiprio.rs

Indeed using time-driver-tim3 instead of time-driver-any fixed the issue.