Skip to content

Commit

Permalink
Account for non-resettable peripherals
Browse files Browse the repository at this point in the history
  • Loading branch information
astapleton committed Jun 20, 2024
1 parent 21b6790 commit f41c63e
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions src/rcc/rec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ macro_rules! peripheral_reset_and_enable_control {
($( #[ $tmeta:meta ] $AXBn:ident, $axb_doc:expr => [
$(
$( #[ $pmeta:meta ] )*
$(($Auto:ident))* $p:ident
$(($NoReset:ident))? $p:ident
$([ kernel $clk:ident: $pk:ident $(($Variant:ident))* $ccip:ident $clk_doc:expr ])*
$([ group clk: $pk_g:ident $( $(($Variant_g:ident))* $ccip_g:ident $clk_doc_g:expr )* ])*
$([ fixed clk: $clk_doc_f:expr ])*
Expand Down Expand Up @@ -175,7 +175,7 @@ macro_rules! peripheral_reset_and_enable_control {
$(
#[ $tmeta ]
peripheral_reset_and_enable_control_generator! (
$AXBn, $(($Auto))* $p, [< $p:upper >], [< $p:lower >],
$AXBn, $(($NoReset))* $p, [< $p:upper >], [< $p:lower >],
$( $pmeta )*
$(
[kernel $clk: $pk $(($Variant))* $ccip $clk_doc]
Expand All @@ -193,6 +193,30 @@ macro_rules! peripheral_reset_and_enable_control {
}
}

macro_rules! peripheral_reset_function_behavior {
(
$AXBn:ident,
$p:ident
) => {
paste::item! {
// unsafe: Owned exclusive access to this bitfield
interrupt::free(|_| {
let rstr = unsafe {
&(*RCC::ptr()).[< $AXBn:lower rstr >]()
};
rstr.modify(|_, w| w.
[< $p:lower rst >]().set_bit());
rstr.modify(|_, w| w.
[< $p:lower rst >]().clear_bit());
});
}
};
(
$AXBn:ident,
$NoReset:ident $p:ident
) => { }
}

// This macro uses the paste::item! macro to create identifiers.
//
// https://crates.io/crates/paste
Expand All @@ -202,7 +226,7 @@ macro_rules! peripheral_reset_and_enable_control {
macro_rules! peripheral_reset_and_enable_control_generator {
(
$AXBn:ident,
$(($Auto:ident))* $p:ident,
$(($NoReset:ident))? $p:ident,
$p_upper:ident, // Lower and upper case $p available for use in
$p_lower:ident, // comments, equivalent to with the paste macro.

Expand Down Expand Up @@ -319,16 +343,7 @@ macro_rules! peripheral_reset_and_enable_control_generator {
}
#[inline(always)]
fn reset(self) -> Self {
// unsafe: Owned exclusive access to this bitfield
interrupt::free(|_| {
let rstr = unsafe {
&(*RCC::ptr()).[< $AXBn:lower rstr >]()
};
rstr.modify(|_, w| w.
[< $p:lower rst >]().set_bit());
rstr.modify(|_, w| w.
[< $p:lower rst >]().clear_bit());
});
peripheral_reset_function_behavior!($AXBn, $($NoReset)? $p);
self
}
}
Expand Down Expand Up @@ -469,15 +484,22 @@ peripheral_reset_and_enable_control! {

#[cfg(all())]
AHB1, "AMBA High-performance Bus (AHB1) peripherals" => [
(NoReset) Sram1,
(NoReset) BkpRam,
RamCfg,
Crc,

(NoReset) Flitf,
Gpdma1,
Gpdma2
];
#[cfg(feature = "rm0492")]
AHB1, "" => [
(NoReset) Gtzc1
];

#[cfg(all())]
AHB2, "AMBA High-performance Bus (AHB2) peripherals" => [
(NoReset) Sram2,
Hash,
Gpioh,
Gpiod,
Expand All @@ -496,7 +518,7 @@ peripheral_reset_and_enable_control! {
#[cfg(all())]
APB1L, "Advanced Peripheral Bus 1L (APB1L) peripherals" => [
Crs,

(NoReset) Wwdg,
Tim2, Tim3, Tim6, Tim7
];
#[cfg(feature = "rm0492")]
Expand All @@ -509,7 +531,6 @@ peripheral_reset_and_enable_control! {
Usart2 [kernel clk: Usart2(Variant) ccipr1 "USART2"],
Usart3 [kernel clk: Usart3(Variant) ccipr1 "USART3"],


Spi2 [kernel clk: Spi2(Variant) ccipr3 "SPI2"],
Spi3 [kernel clk: Spi3(Variant) ccipr3 "SPI3"],
Opamp,
Expand Down Expand Up @@ -539,7 +560,8 @@ peripheral_reset_and_enable_control! {

#[cfg(all())]
APB3, "Advanced Peripheral Bus 3 (APB3) peripherals" => [
Sbs
(NoReset) RtcApb,
(NoReset) Sbs
];
#[cfg(feature = "rm0492")]
APB3, "" => [
Expand Down

0 comments on commit f41c63e

Please sign in to comment.