Skip to content

Consider using critical_section for the init-context CriticalSection token #1002

Open
@urdh

Description

@urdh

Currently (since rtic-rs/rfcs#32) the init::Context contains a bare_metal critical section token to indicate that the initialization routine runs with interrupts disabled. This causes issues when trying to use RTIC with the STM32F0 HAL and an updated cortex-m crate, which has moved away from using bare_metal to instead use critical_section in rust-embedded/cortex-m#447.

With stm32-rs/stm32f0xx-hal#180, the STM32F0 HAL is going to be usable with more recent cortex-m versions, but this will instead introduce an incompatibility with RTIC which will require users to work around this incompatibility with a bit of unsafe:

    #[init]
    fn init(mut cx: init::Context) -> (Shared, Local) {
        let cs = unsafe { critical_section::CriticalSection::new() };
        // ...
    }

This isn't a show-stopper but given that critical_section::CriticalSection already seems to be used elsewhere in RTIC, and that STM32F0 seems to be the origin of the bare_metal CS to begin with, it seems reasonable to move that CS to critical_section as well.

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