Skip to content

Peripherals as scoped parameters to main #403

@bergus

Description

@bergus

Hello!
When using cortex-m-rtfm, I found it incredibly useful and intuitive that the peripherals from the respective device crate are passed into the init function. It's like taking argc and argv parameters in a main function.
Would it be possible to have the same for #[entry]-attributed functions? The current Peripheral API, introduced in the [RFC] Peripherals as scoped singletons is comparably clumsy. I dislike that global initialisation flag and the panicky unwrapping of the Option, and even in case the optimiser is able to eliminate them (I haven't checked) it would be cleaner code if one could just omit the static mut DEVICE_PERIPHERALS: bool from the device crates. I am hoping for something like

#[entry]
fn main(peripherals: stm32f30x::Peripherals) -> ! {
    // initialization
    loop {
        // application logic
    }
}

I'm not sure whether this is feasible at all (especially regarding the dependency hierarchy between cortext-m-rt and the device crates), where the right place to discuss this is (svd2rust? embedded-wg?) and what needs to be done to make this happen (should this be a RFC?). Please provide some guidance :-)

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