embassy-rs / chiptool

Apache License 2.0
37 stars 21 forks source link

Add missing interrupt definitions so that generated pac's can be used in an RTIC application #10

Closed noppej closed 1 year ago

noppej commented 1 year ago

The intention is to regenerate stm32-metapac crate, to include interrupt definitions, similar to those in peripheral access crates that are based on svd2rust, so that the embassy-stm32 HAL can be used in an RTIC application.

With current functionality, it is possible to do this in an RTIC app - thanks to @korken89 and @MathiasKoch for the pointers :

pub mod pac {
    pub const NVIC_PRIO_BITS: u8 = 2;
    pub use cortex_m_rt::interrupt;
    pub use embassy_stm32::pac::Interrupt as interrupt;
    pub use embassy_stm32::pac::*;
}

#[app(device = crate::pac, peripherals = false)]

The intention would be to reduce it to:

#[app(device = embassy_stm32, peripherals = false)]

WIP plan of attack:

[x] Expose interrupt attribute macro, Interrupt enum. (This was the 'easy' part, and I am using it to validate that all the [patch.crates-io] paths work in my tests.). Using this PR to update the stm32-metapac, this reduces the required code from above to:

  pub mod pac {
      pub const NVIC_PRIO_BITS: u8 = 2;
      // pub use cortex_m_rt::interrupt;
      // pub use embassy_stm32::pac::Interrupt as interrupt;
      pub use embassy_stm32::pac::*;
  }

  #[app(device = crate::pac, peripherals = false)]

[x] Expose NVIC_PRIO_BITS in chiptool

[x] Expose NVIC_PRIO_BITS in stm32-metapac Unmerged PR

[x] Test with new generated stm32-metapac. Can successfully build and run an RTIC v2 app, using the following:

#[app(device = embassy_stm32::pac, peripherals = false, dispatchers = [FDCAN1_IT0, FDCAN2_IT0])]

TBD : @Dirbaio , and @korken89, the device = <crate> still requires appending the ::pac qualifier. Is it necessary to modify the embassy_stm32 crate to eliminate this, or is this an acceptable user experience?

noppej commented 1 year ago

@Dirbaio This turned out to be easier than I thought ... mostly thanks to your tips. If you are OK with this, then I will update the stm32-data PR when this is merged.

Dirbaio commented 1 year ago

the device = <crate> still requires appending the ::pac qualifier. Is it necessary to modify the embassy_stm32 crate to eliminate this, or is this an acceptable user experience?

This is intended, the device attr needs the PAC, not the HAL. You can do device = "embassy_stm32::pac", or device = "stm32_metapac". The former is better though because you automatically get the same PAC version.

Dirbaio commented 1 year ago

Thank you!