Hello people, I have a problem and I couldn't solved it. Please help me. This is important, I have a code that is running rtic channels, but it keeps giving this error. By the way: I'm following the example from the rtic book: Channel based communication - Real-Time Interrupt-driven Concurrency
this this code:
#![no_main]
#![no_std]
use cortex_m;
use stm32g0xx_hal as hal;
use hal::pac;
use hal::prelude::*;
use panic_halt as _;
use hal::rcc::{Config, Prescaler};
use rtic::app;
use systick_monotonic::{Systick, fugit::Duration};
use rtic_sync::{channel::*, make_channel};
#[app(device = stm32g0xx_hal::pac, peripherals = true, dispatchers = [SPI1])]
mod app {
use super::*;
#[local]
struct Local {
led1: hal::gpio::gpioa::PA1<hal::gpio::Output<hal::gpio::PushPull>>,
led2: hal::gpio::gpioa::PA2<hal::gpio::Output<hal::gpio::PushPull>>,
led3: hal::gpio::gpioa::PA3<hal::gpio::Output<hal::gpio::PushPull>>,
}
#[shared]
struct Shared {}
const GATE: u64 = 1000;
const CAPACITY: usize = 5;
#[monotonic(binds = SysTick, default = true)]
type MonoTimer = Systick<1000>;
#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics()) {
let (s1, r1) = make_channel!(u32, CAPACITY);
let (s2, r2) = make_channel!(u32, CAPACITY);
first_task::spawn(s1).unwrap();
second_task::spawn(r1, s2).unwrap();
third_task::spawn(r2).unwrap();
let dp: pac::Peripherals = cx.device;
let mut rcc = dp.RCC.freeze(Config::hsi(Prescaler::Div2));
let gpioa = dp.GPIOA.split(&mut rcc);
let led1 = gpioa.pa1.into_push_pull_output();
let led2 = gpioa.pa2.into_push_pull_output();
let led3 = gpioa.pa3.into_push_pull_output();
let systick = Systick::new(cx.core.SYST, 8_000_000);
//first_task::spawn(after(Duration::<u64, 1, 1000>::millis(GATE)), s1.clone()).unwrap();
(Shared {}, Local { led1, led2, led3 }, init::Monotonics(systick))
}
#[task(local = [led1])]
async fn first_task(cx: first_task::Context, mut sender: Sender<'static, u32, CAPACITY>) {
let mut value = 0;
loop {
if value == 1 {
cx.local.led1.set_high().unwrap();
} else {
cx.local.led1.set_low().unwrap();
}
sender.send(value).await.unwrap();
value = if value == 1 { 0 } else { 1 };
blink_led1::spawn_after(Duration::<u64, 1, 1000>::from_ticks(GATE)).unwrap();
}
}
#[task(local = [led2])]
async fn second_task(cx: second_task::Context, mut receiver: Receiver<'static, u32, CAPACITY>, mut sender: Sender<'static, u32, CAPACITY>) {
loop {
let value = receiver.recv().await.unwrap();
if value == 1 {
cx.local.led2.set_high().unwrap();
} else {
cx.local.led2.set_low().unwrap();
}
sender.send(value).await.unwrap();
}
}
#[task(local = [led3])]
async fn third_task(cx: third_task::Context, mut receiver: Receiver<'static, u32, CAPACITY>) {
loop {
let value = receiver.recv().await.unwrap();
if value == 1 {
cx.local.led3.set_high().unwrap();
} else {
cx.local.led3.set_low().unwrap();
}
}
}
}
And it's returning the following error:
Compiling canais v0.1.0
error: this task handler must have type signature `fn(first_task::Context, ..)`
--> src/main.rs:67:14
|
67 | async fn first_task(cx: first_task::Context, mut sender: Sender<'static, u32, CAPACITY>) {
| ^^^^^^^^^^
warning: unused import: `cortex_m`
--> src/main.rs:4:5
|
4 | use cortex_m;
| ^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: unused import: `hal::pac`
--> src/main.rs:6:5
|
6 | use hal::pac;
| ^^^^^^^^
warning: unused import: `hal::prelude::*`
--> src/main.rs:7:5
|
7 | use hal::prelude::*;
| ^^^^^^^^^^^^^^^
warning: unused imports: `Config` and `Prescaler`
--> src/main.rs:9:16
|
9 | use hal::rcc::{Config, Prescaler};
| ^^^^^^ ^^^^^^^^^
warning: unused imports: `Systick` and `fugit::Duration`
--> src/main.rs:11:25
|
11 | use systick_monotonic::{Systick, fugit::Duration};
| ^^^^^^^ ^^^^^^^^^^^^^^^
warning: unused imports: `channel::*` and `make_channel`
--> src/main.rs:12:17
|
12 | use rtic_sync::{channel::*, make_channel};
| ^^^^^^^^^^ ^^^^^^^^^^^^
warning: `canais` (bin "canais") generated 6 warnings
error: could not compile `canais` (bin "canais") due to 1 previous error; 6 warnings emitted
Please help me. I don't know why this is happening. I really need this example working.