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?
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?
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.
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.