1 free interrupt (`extern { .. }`) is required to dispatch all soft tasks

Hi! I am new to Rust and maybe asking stupid questions. I am trying to make simple blink with RTFM and stm32f103. This code didn’t work before, but compiled fine.

I am trying to use code like this

#![no_std]
#![no_main]

extern crate stm32f1;
extern crate panic_halt;

use rtfm::app;
// use cortex_m_semihosting::hprintln;

#[app(device = stm32f1::stm32f103)]
const APP: () = {

    #[init(schedule = [led])]
    unsafe fn init() {
        hprintln!("Initializint perphs").unwrap();

        let peripherals = stm32f1::stm32f103::Peripherals::take().unwrap();
        let gpioc = &peripherals.GPIOC;
        let rcc = &peripherals.RCC;

        // enable the GPIO clock for IO port C
        hprintln!("Enabling GPIO").unwrap();
        rcc.apb2enr.write(|w| w.iopcen().set_bit());
        gpioc.crh.write(|w| {
            w.mode13().bits(0b11);
            w.cnf13().bits(0b00)
        });

        hprintln!("Starting loop").unwrap();

        schedule.led(Instant::now() + 2_000_000.cycles()).unwrap();
    }

    #[task(schedule = [led])]
    unsafe fn led() {
        hprintln!("Toggling LED").unwrap();
        gpioc.bsrr.write(|w| w.bs13().set_bit());
        cortex_m::asm::delay(2000000);
        gpioc.brr.write(|w| w.br13().set_bit());
        cortex_m::asm::delay(2000000);
        let now = Instant::now();
        schedule.led(now + 2_000_000.cycles()).unwrap();
    }
    extern "C" {
    }
};

Today I’ve done rustup update and now I get compilation error:

cargo build
   Compiling air v0.1.0 (/Users/ionbuggy/projects/rust/air)
error: 1 free interrupt (`extern { .. }`) is required to dispatch all soft tasks
  --> src/main.rs:10:1
   |
10 | #[app(device = stm32f1::stm32f103)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `air`.

To learn more, run the command again with --verbose.

How should I fix this problem (and read about it more)? Or maybe there are some working blink examples with recent version of rtfm and stm32?

You are missing an interrupt to dispatch your task.
Try to add one interrupt from your hardware to the extern C block.

Also have a look at the documentation about tasks:

https://japaric.github.io/cortex-m-rtfm/book/en/by-example/tasks.html

1 Like

Thanks. What is general safe interrupt to use?

Now I have different error:

cargo build
   Compiling air v0.1.0 (/Users/ionbuggy/projects/rust/air)
error[E0425]: cannot find value `gpioc` in this scope
  --> src/main.rs:38:9
   |
38 |         gpioc.bsrr.write(|w| w.bs13().set_bit());
   |         ^^^^^ not found in this scope

error[E0425]: cannot find value `gpioc` in this scope
  --> src/main.rs:40:9
   |
40 |         gpioc.brr.write(|w| w.br13().set_bit());
   |         ^^^^^ not found in this scope

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
error: Could not compile `air`.

To learn more, run the command again with --verbose.

This code works ok without rtfm, but does not work with it. Any ideas?

Hey,

Regarding the question with the interrupts the answer is simple: use an interrupt that is not used in your application.

Your compilation problem is a little bit complicated. The complier does not know gpioc because you declared it in the init function and after that it is dropped.

Also I think your code will panic on the device because rt takes the peripherals.
Details can be found in the doc about the init function:
https://japaric.github.io/cortex-m-rtfm/book/en/by-example/app.html?highlight=Device#init

In your example you are modifying the registers by hand, so you can easily mess it up. I think it is a good idea to use a Hal crate for your device.

I did a similar example with the same device and a Hal crate: https://github.com/knoby/rustocopter/blob/012b12bb31aabd7b291d84544bb80e29f1e63c4c/src/main.rs

Here is some information about the idea of the embedded eco system: http://blog.japaric.io/brave-new-io/

1 Like

There was a workshop about rtfm on the oxidize conf this year:

https://github.com/korken89/rtfm_workshop

1 Like

THanks for the answers. Thing is, that I am using this crate https://github.com/stm32-rs/stm32-rs because it support CAN bus for stm32. All other examples are using other crate without CAN bus support.