Skip to content

Commit 37f32c7

Browse files
authored
Merge pull request #618 from stm32-rs/rcc-tim
enable_unchecked, timer features
2 parents 4fe1da0 + 9f65a9f commit 37f32c7

File tree

22 files changed

+378
-424
lines changed

22 files changed

+378
-424
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
- Add autoimplementations of `DMASet` [#614]
1111
- Simplify `gpio::Outport` [#611]
12+
- rcc `enable_unchecked`, timer features
1213
- Split SPI master and slave implementations [#609]
1314
- Split USART and UART implementations [#608]
1415
- Add `lapce` editor settings [#601]

Cargo.toml

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,22 @@ gpio-f401 = [
121121
"otg-fs",
122122
"sdio",
123123
"spi3", "spi4",
124-
"tim2",
124+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim9", "tim10", "tim11",
125125
]
126126
gpio-f410 = [
127127
"dac",
128128
"fmpi2c1",
129129
"lptim1",
130130
"spi5",
131+
"tim1", "tim5", "tim6", "tim9", "tim11",
131132
]
132133
gpio-f411 = [
133134
"gpiod", "gpioe", # "gpioi",
134135
"i2c3",
135136
"otg-fs",
136137
"sdio",
137-
"tim2",
138+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim9", "tim10", "tim11",
138139
"spi3", "spi4", "spi5",
139-
140140
]
141141
gpio-f412 = [
142142
"gpiod", "gpioe", "gpiof", "gpiog",
@@ -150,7 +150,7 @@ gpio-f412 = [
150150
"rng",
151151
"sdio",
152152
"spi3", "spi4", "spi5",
153-
"tim2", "tim8",
153+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
154154
"usart3",
155155
]
156156
gpio-f413 = [
@@ -169,7 +169,7 @@ gpio-f413 = [
169169
"sai1",
170170
"sdio",
171171
"spi3", "spi4", "spi5",
172-
"tim2", "tim8",
172+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
173173
"usart3", "uart4", "uart5", "uart7", "uart8", "uart9", "uart10",
174174
]
175175
gpio-f417 = [
@@ -186,7 +186,7 @@ gpio-f417 = [
186186
"rng",
187187
"sdio",
188188
"spi3",
189-
"tim2", "tim8",
189+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
190190
"usart3", "uart4", "uart5",
191191
]
192192
gpio-f427 = [
@@ -204,7 +204,7 @@ gpio-f427 = [
204204
"sai1",
205205
"sdio",
206206
"spi3", "spi4", "spi5", "spi6",
207-
"tim2", "tim8",
207+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
208208
"usart3", "uart4", "uart5", "uart7", "uart8",
209209
]
210210
gpio-f446 = [
@@ -224,7 +224,7 @@ gpio-f446 = [
224224
#"sdio",
225225
"spi3", "spi4",
226226
"spdifrx",
227-
"tim2", "tim8",
227+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
228228
"usart3", "uart4", "uart5",
229229
]
230230
gpio-f469 = [
@@ -245,7 +245,7 @@ gpio-f469 = [
245245
"sai1",
246246
"sdio",
247247
"spi3", "spi4", "spi5", "spi6",
248-
"tim2", "tim8",
248+
"tim1", "tim2", "tim3", "tim4", "tim5", "tim6", "tim7", "tim8", "tim9", "tim10", "tim11", "tim12", "tim13", "tim14",
249249
"usart3", "uart4", "uart5", "uart7", "uart8",
250250
]
251251

@@ -296,8 +296,20 @@ spi4 = []
296296
spi5 = []
297297
spi6 = []
298298
spdifrx = []
299+
tim1 = []
299300
tim2 = []
301+
tim3 = []
302+
tim4 = []
303+
tim5 = []
304+
tim6 = []
305+
tim7 = []
300306
tim8 = []
307+
tim9 = []
308+
tim10 = []
309+
tim11 = []
310+
tim12 = []
311+
tim13 = []
312+
tim14 = []
301313
usart3 = []
302314
uart4 = []
303315
uart5 = []

src/can.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ impl<CAN: Instance> Can<CAN> {
7878
/// Creates a CAN interface.
7979
pub fn new(can: CAN, pins: (impl Into<CAN::Tx>, impl Into<CAN::Rx>)) -> Self {
8080
unsafe {
81-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
82-
let rcc = &(*crate::pac::RCC::ptr());
83-
CAN::enable(rcc);
84-
CAN::reset(rcc);
81+
CAN::enable_unchecked();
82+
CAN::reset_unchecked();
8583
}
8684

8785
let pins = (pins.0.into(), pins.1.into());

src/crc32.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! It operates word-at-a-time, and takes 4 AHB/HCLK cycles per word
88
//! to calculate. This operation stalls the AHB bus for that time.
99
10-
use crate::pac::{CRC, RCC};
10+
use crate::pac::CRC;
1111
use crate::rcc::{Enable, Reset};
1212
use core::mem::MaybeUninit;
1313
use core::ptr::copy_nonoverlapping;
@@ -21,11 +21,9 @@ impl Crc32 {
2121
/// Create a new Crc32 HAL peripheral
2222
pub fn new(crc: CRC) -> Self {
2323
unsafe {
24-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
25-
let rcc = &(*RCC::ptr());
2624
// enable CRC clock.
27-
CRC::enable(rcc);
28-
CRC::reset(rcc);
25+
CRC::enable_unchecked();
26+
CRC::reset_unchecked();
2927
}
3028

3129
let mut new = Self { periph: crc };
@@ -120,11 +118,9 @@ impl Crc32 {
120118

121119
/// Consume the HAL peripheral, returning the PAC peripheral
122120
pub fn release(self) -> CRC {
121+
// Disable CRC clock
123122
unsafe {
124-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
125-
let rcc = &(*RCC::ptr());
126-
// Disable CRC clock
127-
CRC::disable(rcc);
123+
CRC::disable_unchecked();
128124
}
129125

130126
self.periph

src/dac.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use crate::{
88
gpio::{Analog, PA4, PA5},
9-
pac::{DAC, RCC},
9+
pac::DAC,
1010
rcc::{Enable, Reset},
1111
};
1212

@@ -54,12 +54,9 @@ where
5454
PINS: Pins<DAC>,
5555
{
5656
unsafe {
57-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
58-
let rcc = &(*RCC::ptr());
59-
6057
// Enable and reset clock.
61-
DAC::enable(rcc);
62-
DAC::reset(rcc);
58+
DAC::enable_unchecked();
59+
DAC::reset_unchecked();
6360

6461
PINS::init()
6562
}

src/dma/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use core::{
1717
};
1818
use embedded_dma::{ReadBuffer, WriteBuffer};
1919

20-
use crate::pac::RCC;
2120
use crate::{pac, rcc};
2221

2322
pub mod traits;
@@ -267,10 +266,8 @@ impl<DMA: rcc::Enable + rcc::Reset> StreamsTuple<DMA> {
267266
/// Splits the DMA peripheral into streams.
268267
pub fn new(_regs: DMA) -> Self {
269268
unsafe {
270-
//NOTE(unsafe) this reference will only be used for atomic writes with no side effects
271-
let rcc = &(*RCC::ptr());
272-
DMA::enable(rcc);
273-
DMA::reset(rcc);
269+
DMA::enable_unchecked();
270+
DMA::reset_unchecked();
274271
}
275272
Self(
276273
StreamX::new(),

src/fsmc_lcd/mod.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ use core::marker::PhantomData;
6868
pub use self::pins::{AddressPins, ChipSelectPins, DataPins, LcdPins, Pins};
6969
pub use self::timing::{AccessMode, Timing};
7070

71-
use crate::pac::RCC;
7271
use crate::rcc::{Enable, Reset};
7372

7473
// Use the FMC or FSMC, whichever is available, and treat it like an FSMC
@@ -204,11 +203,9 @@ where
204203
) -> (Self, PINS::Lcds) {
205204
use self::sealed::Conjure;
206205
unsafe {
207-
//NOTE(unsafe) this reference will only be used for atomic writes with no side effects
208-
let rcc = &(*RCC::ptr());
209206
// Enable the FSMC/FMC peripheral
210-
FSMC::enable(rcc);
211-
FSMC::reset(rcc);
207+
FSMC::enable_unchecked();
208+
FSMC::reset_unchecked();
212209
}
213210

214211
// Configure memory type and basic interface settings
@@ -238,13 +235,10 @@ where
238235
/// This function also resets and disables the FSMC.
239236
pub fn release(self, _lcds: PINS::Lcds) -> (FSMC, PINS) {
240237
unsafe {
241-
//NOTE(unsafe) this reference will only be used for atomic writes with no side effects
242-
let rcc = &(*RCC::ptr());
243-
// All STM32F4 models with an FSMC or FMC use bit 0 in AHB3ENR and AHB3RSTR.
244238
// Reset FSMC/FMC
245-
FSMC::reset(rcc);
239+
FSMC::reset_unchecked();
246240
// Disable the FSMC/FMC peripheral
247-
FSMC::disable(rcc);
241+
FSMC::disable_unchecked();
248242
}
249243

250244
(self.fsmc, self.pins)

src/gpio.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ macro_rules! gpio {
490490
]) => {
491491
/// GPIO
492492
pub mod $gpiox {
493-
use crate::pac::{$GPIOX, RCC};
493+
use crate::pac::$GPIOX;
494494
use crate::rcc::{Enable, Reset};
495495

496496
/// GPIO parts
@@ -506,12 +506,9 @@ macro_rules! gpio {
506506

507507
fn split(self) -> Parts {
508508
unsafe {
509-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
510-
let rcc = &(*RCC::ptr());
511-
512509
// Enable clock.
513-
$GPIOX::enable(rcc);
514-
$GPIOX::reset(rcc);
510+
$GPIOX::enable_unchecked();
511+
$GPIOX::reset_unchecked();
515512
}
516513
Parts {
517514
$(

src/i2c.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::pac::{self, i2c1};
44
use crate::rcc::{Enable, Reset};
55

66
use crate::gpio;
7-
use crate::pac::RCC;
87

98
use crate::rcc::Clocks;
109
use embedded_hal_one::i2c::blocking::Operation;
@@ -162,12 +161,9 @@ where
162161
clocks: &Clocks,
163162
) -> Self {
164163
unsafe {
165-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
166-
let rcc = &(*RCC::ptr());
167-
168164
// Enable and reset clock.
169-
I2C::enable(rcc);
170-
I2C::reset(rcc);
165+
I2C::enable_unchecked();
166+
I2C::reset_unchecked();
171167
}
172168

173169
let pins = (pins.0.into(), pins.1.into());

src/i2s.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module is only available if the `i2s` feature is enabled.
44
55
use crate::gpio::{self, NoPin};
6-
use crate::pac::{self, RCC};
6+
use crate::pac;
77
use crate::rcc;
88
use crate::rcc::Clocks;
99
use fugit::HertzU32 as Hertz;
@@ -94,11 +94,9 @@ impl<SPI: Instance> I2s<SPI> {
9494
) -> Self {
9595
let input_clock = SPI::i2s_freq(clocks);
9696
unsafe {
97-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
98-
let rcc = &(*RCC::ptr());
9997
// Enable clock, enable reset, clear, reset
100-
SPI::enable(rcc);
101-
SPI::reset(rcc);
98+
SPI::enable_unchecked();
99+
SPI::reset_unchecked();
102100
}
103101

104102
let pins = (pins.0.into(), pins.1.into(), pins.2.into(), pins.3.into());

0 commit comments

Comments
 (0)