Skip to content

First attempt into rtfm, init function doubt #218

Closed
@thymbahutymba

Description

@thymbahutymba

I have the following code:

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

use stm32f1::stm32f103;
use rtfm::app;

#[app(device = stm32f1)]
const APP: () = {
    static mut PERIPHERALS: stm32f103::Peripherals = stm32f103::Peripherals::take().unwrap();
    
    #[init(spawn = [task1, task2], resources = [PERIPHERALS])]
    fn init(c: config::Context) {
        let rcc = c.resources.PERIPHERALS.RCC;
        let gpioc = c.resources.PERIPHERALS.GPIOC;

        rcc.apb2enr.write(|w| w.iopcen().set_bit());
        gpioc.crh.write(|w| unsafe{
            w.mode13().bits(0b11);
            w.cnf13().bits(0b00)
        });

        c.spawn.task1().unwrap();
        c.spawn.task2().unwrap();
    }

    #[idle]
    fn idle() -> ! {
        loop {}
    }

    #[task(resources = [PERIPHERALS])]
    fn task1(c: task1::Context) {
        let gpioc = c.resources.PERIPHERALS.GPIOC;
        loop {
            gpioc.bsrr.write(|w| w.bs13().set_bit());
            cortex_m::asm::delay(2000000);
        }
    }

    #[task(resources = [PERIPHERALS])]
    fn task2(c: task1::Context) {
        let gpioc = c.resources.PERIPHERALS.GPIOC;
        loop {
            gpioc.brr.write(|w| w.br13().set_bit());
            cortex_m::asm::delay(2000000);
        }
    }

    extern "C" {
        fn TIM2();
    }
};

What i get from compilation is the following error:

`init` must have type signature `[unsafe] fn() [-> init::LateResources]`

I don't know how to fix it, I'm reading the examples that seems to have the same syntax of mine.
For now I don't care about the correctness of the tasks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions