Error: unwinding panic are not supported without std

Hi everyone,
I'm trying to implement a blink LED on the STM32G070RBT6 using RTIC, but I'm getting an error that I don't know how to fix. If anyone could help me, I would really appreciate it.
Thanks in advance!
The code is bellow and the image is the error I found. I kind of used these repository as a base: GitHub - rtic-rs/rtic-examples: Example projects using Real-Time Interrupt-driven Concurrency (RTIC) on different MCUs

main.rs:

#![no_main]
#![no_std]

use rtic::app;
use systick_monotonic::{fugit::{ExtU32, MillisDurationU64}, Systick};
use stm32g0xx_hal as hal;
use hal::prelude::*;
use hal::rcc::{Config, Prescaler};
use hal::stm32;
use stm32g0xx_hal::gpio::{Output, PushPull, PA5};
use panic_halt as _; 

const INTERVAL_MS: u32 = 500;

#[app(
    device = stm32g0xx_hal::pac,
    peripherals = true,
    dispatchers = [SPI1], 
)]
mod app {
    use super::*;

    #[monotonic(binds = SysTick, default = true)]
    type Tonic = Systick<1000>;

    #[local]
    struct Local {
        led: PA5<Output<PushPull>>,
    }

    #[shared]
    struct Shared {}

    #[init]
    fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
        let dp = stm32::Peripherals::take().expect("cannot take peripherals");
        let mut rcc = dp.RCC.freeze(Config::hsi(Prescaler::Div2));

        let gpioa = dp.GPIOA.split(&mut rcc);
        let led = gpioa.pa5.into_push_pull_output(); 

        let mono = Systick::new(cx.core.SYST, 16_000_000); 

        let local = Local { led };


        let _ = blink::spawn_after(INTERVAL_MS.millis().into()); 

        (Shared {}, local, init::Monotonics(mono))
    }

    #[task(local = [led])]
    fn blink(cx: blink::Context) {
        let led = cx.local.led;
        led.toggle().unwrap(); 

        let _ = blink::spawn_after(INTERVAL_MS.millis().into());
    }
}

cargo.toml:

[package]
name = "blink"
version = "0.1.0"
edition = "2021"

[dependencies]
cortex-m-rtic = "1.1.4"
systick-monotonic = "1.0.1"
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
stm32g0 = { version = "0.15.1", default-features = false, features = ["rt", "stm32g070"] }
stm32g0xx-hal = { version = "0.2.0", features = ["rt", "stm32g070"] }
embedded-hal = "1.0.0"
defmt = "0.3.8"
defmt-rtt = "0.4.1"
heapless = { version = "0.8.0", default-features = false }
cortex-m-rt = "0.7.3" #em vez de 3 tava 1
panic-halt = "0.2.0"
nb = "1.1.0"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }





[build]
target = "thumbv6m-none-eabi"




[profile.dev]
opt-level = 1
codegen-units = 16
debug = true
lto = false

[profile.release]
opt-level = "s"   # optimize for size
codegen-units = 1 # better optimizations
debug = true      # symbols are nice and they don't increase the size on Flash
lto = true        # better optimizations

Can you try these steps

[dependencies]
cortex-m = "0.7"
cortex-m-rtic = "0.5"
stm32g0xx-hal = "0.1"
panic-halt = "0.2"

#[rtic::app(device = stm32g0xx_hal::pac, peripherals = true)]
mod app {
    use stm32g0xx_hal::gpio::{Output, PushPull, gpioa::PA5};
    use stm32g0xx_hal::prelude::*;

    #[resources]
    struct Resources {
        led: PA5<Output<PushPull>>,
    }

    #[init]
    fn init(cx: init::Context) -> init::LateResources {
        let dp = cx.device;
        let mut rcc = dp.RCC.constrain();
        let gpioa = dp.GPIOA.split(&mut rcc);
        let led = gpioa.pa5.into_push_pull_output();
        init::LateResources { led }
    }

    #[task(resources = [led])]
    fn blink(cx: blink::Context) {
        cx.resources.led.toggle().unwrap();
        blink::spawn_after(1.secs()).unwrap();
    }

    #[idle]
    fn idle(_cx: idle::Context) -> ! {
        loop {
            rtic::export::wfi();
        }
    }
}

Check for dependency mismatches or pin configuration errors.

I hope this will work for you.....

1 Like

Thank you for your help. But it didn't work. The error still the same.

what is the content of your Embed.toml and/or .cargo/config.toml?

the fact that you put the build.target = "thumbv6m-none-eabi config in the wrong place (hence that cargo's warning), I have to guess that you probably aren't familiar with tools and the building is for the wrong target.

the target is right because I already used before with rust:

embed.toml:

[default.probe]
protocol = "Swd"

[default.general]
chip = "STM32G070RBTx"    

[default.rtt]
enabled = false


[default.gdb]
enabled = false

.cargo/config.toml:

[build]
target = "thumbv6m-none-eabi"

[target.thumbv6m-none-eabi]
runner = "probe-rs run --chip STM32G070RBT6"
linker = "arm-none-eabi-ld"
rustflags = [
    "-C", "link-arg=-Tlink.x",
    "-C", "link-arg=-Tdefmt.x"
]

[profile.dev]
opt-level = "s"

[profile.release]
debug = 2
opt-level = "z" 
lto = true      

then it might be something to do with the panic_handler.

although the compile error says it might not be enough, you can always try to build the code with panic=abort. you can use profile.dev.panic="abort" cargo profile or add a -C panic=abort to your rustflags (or maybe the RUSTFLAGS environment variable).

if that doesn't work, can you try to remove the dependencies containing panic handlers, and define a dummy panic handler instead, something like:

#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
    loop {}
}

I found the error; it was in the Cargo.toml file, specifically in the crates: defmt = "0.3.8" and defmt-rtt = "0.4.1", and the feature: ["print-defmt"]. Thank you all for your help.

1 Like