Skip to content

Peripheral definitions in cortex-m are not Send, while those from svd2rust generated crates are #79

Closed
@codyps

Description

@codyps

Comparing something like:

Notably:

  • Send is omitted from cortex_m::ITM
  • mutable access (in the form of ptr() -> *mut RegisterBlock and DerefMut are removed from stm32f103xx::TIM6

I ran into this while trying to pass around ITM in cortex_m_rtfm, which wants Send on resources:

error[E0277]: the trait bound `*const (): core::marker::Send` is not satisfied in `cortex_m::peripheral::ITM`
  --> src/main.rs:16:1
   |
16 | / app! {
17 | |     device: stm32f429,
18 | |
19 | |     resources: {
...  |
29 | |     },
30 | | }
   | |_^ `*const ()` cannot be sent between threads safely
   |
   = help: within `cortex_m::peripheral::ITM`, the trait `core::marker::Send` is not implemented for `*const ()`
   = note: required because it appears within the type `core::marker::PhantomData<*const ()>`
   = note: required because it appears within the type `cortex_m::peripheral::ITM`

I've used a quick wrapper to workaround:

...
use core::ops::{Deref,DerefMut};
pub struct ITM(cortex_m::peripheral::ITM);

impl Deref for ITM {
    type Target = cortex_m::peripheral::ITM;
    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl DerefMut for ITM {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}
unsafe impl Send for ITM {}

...
app! {
...
    resources: {
        static R_ITM: ITM;
        ...
    },

    tasks: {
        TIM7: {
            path: periodic,
            resources: [R_ITM, ...],
        },
    },
}

...
fn init(mut p: init::Peripherals) -> init::LateResources {
    ...

    init::LateResources {
        R_ITM: ITM(p.core.ITM),
        R_TIM7: tim,
    }
}

...

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