RTFM blinking example via periodic task dont work

#1

Hi i tried to do a toy example of periodic task in the framework of the RTFM with the blue-pill board, but the foo() task is never executed, here is the code:

#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]

extern crate panic_semihosting;
// use stm32f1xx_hal::{delay, gpio, i2c, spi, stm32, timer};
// use cortex_m_semihosting::hprintln;
use rtfm::{app, Instant};
use stm32f1xx_hal::prelude::*;
use stm32f1xx_hal::{gpio};
const PERIOD: u32 = 8_000_000;

type LED = gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>;
type BUZZER = gpio::gpioc::PC15<gpio::Output<gpio::PushPull>>;

#[app(device = stm32f1xx_hal::stm32)]
const APP: () = {
    static mut BUZZER: BUZZER = ();
    static mut LED: LED = ();

    #[init(schedule = [foo])]
    fn init() -> init::LateResources {
        schedule.foo(Instant::now() + PERIOD.cycles()).unwrap();
        let device: stm32f1xx_hal::stm32::Peripherals = device;
        let mut flash = device.FLASH.constrain();
        let mut rcc = device.RCC.constrain();
        let mut _afio = device.AFIO.constrain(&mut rcc.apb2);
        let _clocks = rcc
            .cfgr
            .use_hse(8.mhz())
            .sysclk(72.mhz())
            .pclk1(36.mhz())
            .freeze(&mut flash.acr);
        let mut gpioc = device.GPIOC.split(&mut rcc.apb2);
        let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
        led.set_low();
        let mut buzzer_output = gpioc.pc15.into_push_pull_output(&mut gpioc.crh);
        buzzer_output.set_low();
        // call to the scheduller
        init::LateResources {
            LED: led,
            BUZZER: buzzer_output,
        }
    }

    #[task(schedule = [foo], resources = [BUZZER, LED])]
    fn foo() {

        if resources.LED.is_set_high() {
            resources.LED.set_low();
        } else {
            resources.LED.set_high();
        }

        schedule.foo(scheduled + PERIOD.cycles()).unwrap();
    }

    extern "C" {
        fn UART4();
    }
};
0 Likes

#2

Hey, I had the same Probleme. You can try another interrupt for handling the Task:

extern ā€œCā€ {
fn EXTI0();
}

0 Likes

#3

Yeah works!!! thanks!!!. Why is an interruption necessary? if we are only using software tasks.

0 Likes

#4

The Interrupts are used to dispatch the tasks.

The user doc gives some more information.

But I wonder why some interrupts are not working. Perhaps @japaric has an idea.

0 Likes