From a0db00634af3f3fa212dfe728f2c67e7b872b2f5 Mon Sep 17 00:00:00 2001 From: Ongun Kanat Date: Mon, 15 Sep 2025 11:20:21 +0200 Subject: [PATCH 1/2] Implement Deref and DerefMut for Rcc Cordoning off access to RCC registers makes implementing certain software and drivers (e.g. a bootloader for STMF0 cores need SYSCFG) unnecessarily difficult. A completely encapsulated RCC renders peripheral enable registers inaccessible and some drivers (e.g stm32_usbd) opt for using unsafe raw pointer accesses completely eliminating the safety and the structure provided by the HAL. This commit copies an escape hatch from stm32f4xx-hal crate by implementing Deref and DerefMut for Rcc structure. The stm32f4xx-hal implementation can be seen at the link below: https://github.com/stm32-rs/stm32f4xx-hal/blob/0ba01f4fb3f19b0eea40d8ea2403e2e9d4e41609/src/rcc/mod.rs#L56-L67 --- src/rcc.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/rcc.rs b/src/rcc.rs index b396ad6..3a38b00 100644 --- a/src/rcc.rs +++ b/src/rcc.rs @@ -1,5 +1,6 @@ use crate::pac::RCC; use crate::time::Hertz; +use core::ops::{Deref, DerefMut}; /// Extension trait that sets up the `RCC` peripheral pub trait RccExt { @@ -45,6 +46,20 @@ pub struct Rcc { pub(crate) regs: RCC, } +impl Deref for Rcc { + type Target = RCC; + + fn deref(&self) -> &Self::Target { + &self.regs + } +} + +impl DerefMut for Rcc { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.regs + } +} + pub enum HSEBypassMode { /// Not bypassed: for crystals NotBypassed, From e57407971ffd1547f3a727d23f0d4da0ae09c286 Mon Sep 17 00:00:00 2001 From: Ongun Kanat Date: Mon, 15 Sep 2025 11:42:23 +0200 Subject: [PATCH 2/2] Add impl Deref and DerefMut for Rcc to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b392951..e4f6636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - PWM output on complementary channels only for single channel timers (TIM16 + TIM17) - impl embedded_hal_1::spi::SpiBus for SPI - impl embedded_hal_1::digital traits for Pins +- impl core::{Deref, DerefMut} for Rcc ### Fixed