Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rcc bit-band #344

Merged
merged 1 commit into from
Jul 27, 2021
Merged

Rcc bit-band #344

merged 1 commit into from
Jul 27, 2021

Conversation

burrbull
Copy link
Member

@burrbull burrbull commented Jul 13, 2021

Depends on #337

@burrbull burrbull mentioned this pull request Jul 13, 2021
@TheZoq2
Copy link
Member

TheZoq2 commented Jul 13, 2021

This seems like a super ergonomic change! I haven't gone through the code in detail, but from an overview, it looks OK from a safety perspective (assuming the bit banding thing is atomic, which it is as far as I can tell)

@burrbull burrbull force-pushed the rcc-enable branch 4 times, most recently from 96394ff to 13e242e Compare July 26, 2021 19:12
@burrbull
Copy link
Member Author

Rebased.

@burrbull burrbull force-pushed the rcc-enable branch 4 times, most recently from f7c6e7f to 249c292 Compare July 27, 2021 05:09
@burrbull
Copy link
Member Author

Removed dependency from #337

@burrbull
Copy link
Member Author

cc @TheZoq2 I think it's ready to merge.

Copy link
Member

@TheZoq2 TheZoq2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good overall, I left a few notes with minor things to change, and a few things for me to look into after lunch.

src/afio.rs Outdated Show resolved Hide resolved
src/rcc.rs Outdated Show resolved Hide resolved
src/rcc.rs Outdated
@@ -576,191 +543,26 @@ impl GetBusFreq for APB2 {
}
}

use crate::pac::rcc::RegisterBlock as RccRB;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this alias, it doesn't seem like just typing out RegisterBlock directly in a few places is that annoying, and saves some jumping around when reading the code (unless there are multiple RegisterBlocks in scope here, though in that case I'd prefer to just write out rcc::RegisterBlock

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

macro_rules! bus {
($($PER:ident => ($apbX:ty, $bit:literal),)+) => {
$(
impl Sealed for crate::pac::$PER {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird spacing (is this a rustfmt oddity?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines +63 to +185
GPIOB => (APB2, 3),
GPIOC => (APB2, 4),
GPIOD => (APB2, 5),
GPIOE => (APB2, 6),
I2C1 => (APB1, 21),
I2C2 => (APB1, 22),
PWR => (APB1, 28),
SPI1 => (APB2, 12),
SPI2 => (APB1, 14),
USART1 => (APB2, 14),
USART2 => (APB1, 17),
USART3 => (APB1, 18),
WWDG => (APB1, 11),
}

#[cfg(any(feature = "xl", feature = "high"))]
bus! {
GPIOF => (APB2, 7),
GPIOG => (APB2, 8),
}

#[cfg(any(feature = "high", feature = "connectivity"))]
bus! {
SPI3 => (APB1, 15),
}

ahb_bus! {
CRC => (6),
DMA1 => (0),
DMA2 => (1),
}

#[cfg(feature = "high")]
ahb_bus! {
FSMC => (8),
}

bus! {
TIM2 => (APB1, 0),
TIM3 => (APB1, 1),
}

#[cfg(any(feature = "stm32f100", feature = "stm32f103", feature = "connectivity"))]
bus! {
TIM1 => (APB2, 11),
}

#[cfg(any(feature = "stm32f100", feature = "high", feature = "connectivity"))]
bus! {
TIM6 => (APB1, 4),
}

#[cfg(any(
all(feature = "high", any(feature = "stm32f101", feature = "stm32f103")),
any(feature = "stm32f100", feature = "connectivity")
))]
bus! {
TIM7 => (APB1, 5),
}

#[cfg(feature = "stm32f100")]
bus! {
TIM15 => (APB2, 16),
TIM16 => (APB2, 17),
TIM17 => (APB2, 18),
}

#[cfg(feature = "medium")]
bus! {
TIM4 => (APB1, 2),
}

#[cfg(any(feature = "high", feature = "connectivity"))]
bus! {
TIM5 => (APB1, 3),
}

#[cfg(any(feature = "xl", all(feature = "stm32f100", feature = "high",)))]
bus! {
TIM12 => (APB1, 6),
TIM13 => (APB1, 7),
TIM14 => (APB1, 8),
}

#[cfg(all(feature = "stm32f103", feature = "high",))]
bus! {
TIM8 => (APB2, 13),
}

#[cfg(feature = "xl")]
bus! {
TIM9 => (APB2, 19),
TIM10 => (APB2, 20),
TIM11 => (APB2, 21),
}

#[cfg(any(feature = "stm32f102", feature = "stm32f103"))]
bus! {
USB => (APB1, 23),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self, check these mappings

src/timer.rs Outdated
Comment on lines 287 to 288
$TIMX::enable(rcc);
$TIMX::reset(rcc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note applies to all copies of enable and reset function calls: Should we not move them out of the unsafe block? They are safe to call so they don't need to be there as far as I can tell?

On the other hand, does it make sense to not have them be unsafe. We could make them public API and mark them as unsafe in case people want to circumvent part of the HAL in a project but still want to init the peripherals via RCC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note applies to all copies of enable and reset function calls: Should we not move them out of the unsafe block? They are safe to call so they don't need to be there as far as I can tell?

Moved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, does it make sense to not have them be unsafe. We could make them public API and mark them as unsafe in case people want to circumvent part of the HAL in a project but still want to init the peripherals via RCC

We can, but I don't see sense to make them unsafe as rcc can be gotten in safe way only during initialization. In all other places we need to use unsafe RCC::ptr().

@TheZoq2
Copy link
Member

TheZoq2 commented Jul 27, 2021

One small final note, these changes should go into Breaking Changes in the changelog, other than that this looks ready for squash and merge

@burrbull
Copy link
Member Author

Done.

@burrbull burrbull merged commit 4a3d23b into stm32-rs:master Jul 27, 2021
@burrbull burrbull deleted the rcc-enable branch August 4, 2021 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants