Skip to content

Commit

Permalink
Add support for TIM23 and TIM24 found on RM0468 parts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardeoin committed Feb 3, 2024
1 parent 2bcf2af commit 9ee8ef0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
72 changes: 71 additions & 1 deletion src/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,56 @@ pins! {
]
}

// Quad channel timers (RM0468)
#[cfg(feature = "rm0468")]
pins! {
pac::TIM23:
CH1(ComplementaryImpossible): [
gpio::PG12<Alternate<13>>,
gpio::PF0<Alternate<13>>,
gpio::PF6<Alternate<13>>
]
CH2(ComplementaryImpossible): [
gpio::PG13<Alternate<13>>,
gpio::PF1<Alternate<13>>,
gpio::PF7<Alternate<13>>
]
CH3(ComplementaryImpossible): [
gpio::PG14<Alternate<13>>,
gpio::PF2<Alternate<13>>,
gpio::PF8<Alternate<13>>
]
CH4(ComplementaryImpossible): [
gpio::PF3<Alternate<13>>,
gpio::PF9<Alternate<13>>
]
CH1N: []
CH2N: []
CH3N: []
CH4N: []
BRK: []
BRK2: []
pac::TIM24:
CH1(ComplementaryImpossible): [
gpio::PF11<Alternate<14>>
]
CH2(ComplementaryImpossible): [
gpio::PF12<Alternate<14>>
]
CH3(ComplementaryImpossible): [
gpio::PF13<Alternate<14>>
]
CH4(ComplementaryImpossible): [
gpio::PF14<Alternate<14>>
]
CH1N: []
CH2N: []
CH3N: []
CH4N: []
BRK: []
BRK2: []
}

// Period and prescaler calculator for 32-bit timers
// Returns (arr, psc)
fn calculate_frequency_32bit(
Expand Down Expand Up @@ -1369,6 +1419,11 @@ tim_hal! {
pac::TIM5: (tim5, Tim5, u32, 32, DIR: cms),
pac::TIM8: (tim8, Tim8, u16, 16, DIR: cms, BDTR: bdtr, enabled, af1, clear_bit, clear_bit),
}
#[cfg(feature = "rm0468")]
tim_hal! {
pac::TIM23: (tim23, Tim23, u32, 32, DIR: cms),
pac::TIM24: (tim24, Tim24, u32, 32, DIR: cms),
}
tim_hal! {
pac::TIM12: (tim12, Tim12, u16, 16),
pac::TIM13: (tim13, Tim13, u16, 16),
Expand Down Expand Up @@ -1621,14 +1676,29 @@ tim_pin_hal! {
(C3, ccmr2_output, oc3pe, oc3m),
(C4, ccmr2_output, oc4pe, oc4m),
}
// Quad channel timers
tim_pin_hal! {
pac::TIM8, u16:
(C1, ccmr1_output, oc1pe, oc1m),
(C2, ccmr1_output, oc2pe, oc2m),
(C3, ccmr2_output, oc3pe, oc3m),
(C4, ccmr2_output, oc4pe, oc4m),
}
#[cfg(feature = "rm0468")]
tim_pin_hal! {
pac::TIM23, u32:
(C1, ccmr1_output, oc1pe, oc1m),
(C2, ccmr1_output, oc2pe, oc2m),
(C3, ccmr2_output, oc3pe, oc3m),
(C4, ccmr2_output, oc4pe, oc4m),
}
#[cfg(feature = "rm0468")]
tim_pin_hal! {
pac::TIM24, u32:
(C1, ccmr1_output, oc1pe, oc1m),
(C2, ccmr1_output, oc2pe, oc2m),
(C3, ccmr2_output, oc3pe, oc3m),
(C4, ccmr2_output, oc4pe, oc4m),
}

// Low-power timers
macro_rules! lptim_hal {
Expand Down
4 changes: 3 additions & 1 deletion src/rcc/rec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ peripheral_reset_and_enable_control! {
];
#[cfg(feature = "rm0468")]
APB1H, "" => [
Swpmi [kernel clk: Swpmi d2ccip1 "SWPMI"]
Swpmi [kernel clk: Swpmi d2ccip1 "SWPMI"],

Tim23, Tim24
];


Expand Down
12 changes: 12 additions & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::stm32::{
TIM1, TIM12, TIM13, TIM14, TIM15, TIM16, TIM17, TIM2, TIM3, TIM4, TIM5,
TIM6, TIM7, TIM8,
};
#[cfg(feature = "rm0468")]
use crate::stm32::{TIM23, TIM24};

use cast::{u16, u32};
use void::Void;
Expand Down Expand Up @@ -58,6 +60,10 @@ impl_tim_ker_ck! {
timx_ker_ck: TIM2, TIM3, TIM4, TIM5, TIM6, TIM7, TIM12, TIM13, TIM14
timy_ker_ck: TIM1, TIM8, TIM15, TIM16, TIM17
}
#[cfg(feature = "rm0468")]
impl_tim_ker_ck! {
timx_ker_ck: TIM23, TIM24
}

/// LPTIM1 Kernel Clock
impl GetClk for LPTIM1 {
Expand Down Expand Up @@ -591,6 +597,12 @@ hal! {
TIM16: (tim16, Tim16, u16),
TIM17: (tim17, Tim17, u16),
}
#[cfg(feature = "rm0468")]
hal! {
// General-purpose
TIM23: (tim23, Tim23, u32),
TIM24: (tim24, Tim24, u32),
}

macro_rules! lptim_hal {
($($TIMX:ident: ($timx:ident, $Rec:ident, $timXpac:ident),)+) => {
Expand Down

0 comments on commit 9ee8ef0

Please sign in to comment.