diff --git a/embassy-stm32/CHANGELOG.md b/embassy-stm32/CHANGELOG.md index 000d215b78..13271623c1 100644 --- a/embassy-stm32/CHANGELOG.md +++ b/embassy-stm32/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * **Fix(stm32h5):** Prevent a HardFault crash on STM32H5 devices by changing `uid()` to return `[u8; 12]` by value instead of a reference. (Fixes #2696) ## Unreleased - ReleaseDate +- feat: stm32/hrtim add new_chx_with_config to provide pin configuration - fix flash erase on L4 & L5 - fix: Fixed STM32H5 builds requiring time feature - feat: Derive Clone, Copy for QSPI Config diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index 6fece5eb21..6c68074790 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs @@ -10,6 +10,7 @@ pub use traits::Instance; use crate::gpio::{AfType, AnyPin, OutputType, Speed}; use crate::rcc; use crate::time::Hertz; +pub use crate::timer::simple_pwm::PwmPinConfig; /// HRTIM burst controller instance. pub struct BurstController { @@ -73,7 +74,7 @@ pub struct ComplementaryPwmPin<'d, T, C> { } macro_rules! advanced_channel_impl { - ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { + ($new_chx:ident, $new_chx_with_config:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { impl<'d, T: Instance> PwmPin<'d, T, $channel> { #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] pub fn $new_chx(pin: Peri<'d, impl $pin_trait>) -> Self { @@ -86,6 +87,21 @@ macro_rules! advanced_channel_impl { phantom: PhantomData, } } + + #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with a specific configuration.")] + pub fn $new_chx_with_config( + pin: Peri<'d, impl $pin_trait>, + pin_config: PwmPinConfig, + ) -> Self { + critical_section::with(|_| { + pin.set_low(); + set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed)); + }); + PwmPin { + _pin: pin.into(), + phantom: PhantomData, + } + } } impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel> { @@ -100,6 +116,21 @@ macro_rules! advanced_channel_impl { phantom: PhantomData, } } + + #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance with a specific configuration.")] + pub fn $new_chx_with_config( + pin: Peri<'d, impl $complementary_pin_trait>, + pin_config: PwmPinConfig, + ) -> Self { + critical_section::with(|_| { + pin.set_low(); + set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed)); + }); + ComplementaryPwmPin { + _pin: pin.into(), + phantom: PhantomData, + } + } } impl SealedAdvancedChannel for $channel { @@ -111,13 +142,55 @@ macro_rules! advanced_channel_impl { }; } -advanced_channel_impl!(new_cha, ChA, 0, ChannelAPin, ChannelAComplementaryPin); -advanced_channel_impl!(new_chb, ChB, 1, ChannelBPin, ChannelBComplementaryPin); -advanced_channel_impl!(new_chc, ChC, 2, ChannelCPin, ChannelCComplementaryPin); -advanced_channel_impl!(new_chd, ChD, 3, ChannelDPin, ChannelDComplementaryPin); -advanced_channel_impl!(new_che, ChE, 4, ChannelEPin, ChannelEComplementaryPin); +advanced_channel_impl!( + new_cha, + new_cha_with_config, + ChA, + 0, + ChannelAPin, + ChannelAComplementaryPin +); +advanced_channel_impl!( + new_chb, + new_chb_with_config, + ChB, + 1, + ChannelBPin, + ChannelBComplementaryPin +); +advanced_channel_impl!( + new_chc, + new_chc_with_config, + ChC, + 2, + ChannelCPin, + ChannelCComplementaryPin +); +advanced_channel_impl!( + new_chd, + new_chd_with_config, + ChD, + 3, + ChannelDPin, + ChannelDComplementaryPin +); +advanced_channel_impl!( + new_che, + new_che_with_config, + ChE, + 4, + ChannelEPin, + ChannelEComplementaryPin +); #[cfg(hrtim_v2)] -advanced_channel_impl!(new_chf, ChF, 5, ChannelFPin, ChannelFComplementaryPin); +advanced_channel_impl!( + new_chf, + new_chf_with_config, + ChF, + 5, + ChannelFPin, + ChannelFComplementaryPin +); /// Struct used to divide a high resolution timer into multiple channels pub struct AdvancedPwm<'d, T: Instance> {