Skip to content

Commit e84d5a3

Browse files
authored
Merge pull request #152 from burrbull/rcc_enable
rcc enable
2 parents 797a874 + 3fe518c commit e84d5a3

File tree

19 files changed

+475
-381
lines changed

19 files changed

+475
-381
lines changed

Cargo.toml

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,30 @@ ltdc = []
6262
fmc = ["stm32-fmc"]
6363
usb_hs_phy = []
6464
rt = ["stm32f7/rt"]
65-
stm32f722 = ["stm32f7/stm32f7x2", "device-selected"]
66-
stm32f723 = ["stm32f7/stm32f7x3", "device-selected", "usb_hs_phy"]
67-
stm32f730 = ["stm32f7/stm32f730", "device-selected", "usb_hs_phy", "fmc"]
68-
stm32f732 = ["stm32f7/stm32f7x2", "device-selected"]
69-
stm32f733 = ["stm32f7/stm32f7x3", "device-selected", "usb_hs_phy"]
70-
stm32f745 = ["stm32f7/stm32f745", "device-selected", "gpioj", "gpiok", "fmc"]
71-
stm32f746 = ["stm32f7/stm32f7x6", "device-selected", "gpioj", "gpiok", "ltdc", "fmc", "has-can"]
72-
stm32f756 = ["stm32f7/stm32f7x6", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
73-
stm32f765 = ["stm32f7/stm32f765", "device-selected", "gpioj", "gpiok", "fmc"]
74-
stm32f767 = ["stm32f7/stm32f7x7", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
75-
stm32f769 = ["stm32f7/stm32f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
76-
stm32f777 = ["stm32f7/stm32f7x7", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
77-
stm32f778 = ["stm32f7/stm32f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
78-
stm32f779 = ["stm32f7/stm32f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
65+
66+
svd-f730 = ["stm32f7/stm32f730"]
67+
svd-f745 = ["stm32f7/stm32f745"]
68+
svd-f765 = ["stm32f7/stm32f765"]
69+
svd-f7x2 = ["stm32f7/stm32f7x2"]
70+
svd-f7x3 = ["stm32f7/stm32f7x3"]
71+
svd-f7x6 = ["stm32f7/stm32f7x6"]
72+
svd-f7x7 = ["stm32f7/stm32f7x7"]
73+
svd-f7x9 = ["stm32f7/stm32f7x9"]
74+
75+
stm32f722 = ["svd-f7x2", "device-selected"]
76+
stm32f723 = ["svd-f7x3", "device-selected", "usb_hs_phy"]
77+
stm32f730 = ["svd-f730", "device-selected", "usb_hs_phy", "fmc"]
78+
stm32f732 = ["svd-f7x2", "device-selected"]
79+
stm32f733 = ["svd-f7x3", "device-selected", "usb_hs_phy"]
80+
stm32f745 = ["svd-f745", "device-selected", "gpioj", "gpiok", "fmc"]
81+
stm32f746 = ["svd-f7x6", "device-selected", "gpioj", "gpiok", "ltdc", "fmc", "has-can"]
82+
stm32f756 = ["svd-f7x6", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
83+
stm32f765 = ["svd-f765", "device-selected", "gpioj", "gpiok", "fmc"]
84+
stm32f767 = ["svd-f7x7", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
85+
stm32f769 = ["svd-f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
86+
stm32f777 = ["svd-f7x7", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
87+
stm32f778 = ["svd-f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
88+
stm32f779 = ["svd-f7x9", "device-selected", "gpioj", "gpiok", "ltdc", "fmc"]
7989

8090
fmc_lcd = ["display-interface"]
8191

examples/exti_button.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ fn main() -> ! {
3434
let gpiob = pac_periph.GPIOB.split();
3535
let mut led1 = gpiob.pb0.into_push_pull_output();
3636

37+
// Freeze clocks
38+
let mut rcc = pac_periph.RCC.constrain();
39+
let _clocks = rcc.cfgr.sysclk(216_000_000.Hz()).freeze();
40+
3741
// Push button configuration
38-
let mut rcc = pac_periph.RCC;
3942
let mut syscfg = pac_periph.SYSCFG;
4043
let mut exti = pac_periph.EXTI;
4144
let gpioc = pac_periph.GPIOC.split();
4245
let mut button = gpioc.pc13.into_floating_input();
43-
button.make_interrupt_source(&mut syscfg, &mut rcc);
46+
button.make_interrupt_source(&mut syscfg, &mut rcc.apb2);
4447
button.trigger_on_edge(&mut exti, Edge::Rising);
4548
button.enable_interrupt(&mut exti);
4649

47-
// Freeze clocks
48-
rcc.constrain().cfgr.sysclk(216_000_000.Hz()).freeze();
49-
5050
// Save information needed by the interrupt handler to the global variable
5151
free(|cs| {
5252
BUTTON_PIN.borrow(cs).replace(Some(button));

src/adc.rs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#![allow(dead_code)]
44

5-
use crate::rcc::{Clocks, APB2};
5+
use crate::rcc::{Clocks, Enable, Reset, APB2};
66

77
use crate::gpio::Analog;
88
use crate::gpio::{gpioa, gpiob, gpioc, gpiof};
@@ -193,10 +193,10 @@ macro_rules! adc_hal {
193193
align: Align::default(),
194194
clocks,
195195
};
196-
s.enable_clock(apb2);
196+
<$ADC>::enable(apb2);
197197
if reset {
198198
s.power_down();
199-
s.reset(apb2);
199+
<$ADC>::reset(apb2);
200200
}
201201

202202
s.setup_oneshot();
@@ -266,29 +266,6 @@ macro_rules! adc_hal {
266266
self.rb.cr2.modify(|_, w| w.adon().clear_bit());
267267
}
268268

269-
fn reset(&mut self, apb2: &mut APB2) {
270-
apb2.rstr().modify(|_, w| w.adcrst().set_bit());
271-
apb2.rstr().modify(|_, w| w.adcrst().clear_bit());
272-
}
273-
274-
fn enable_clock(&mut self, apb2: &mut APB2) {
275-
match stringify!($adc) {
276-
"adc1" => apb2.enr().modify(|_, w| w.adc1en().set_bit()), // for ADC1
277-
"adc2" => apb2.enr().modify(|_, w| w.adc2en().set_bit()), // for ADC2
278-
"adc3" => apb2.enr().modify(|_, w| w.adc3en().set_bit()), // for ADC3
279-
_ => unreachable!(),
280-
}
281-
}
282-
283-
fn disable_clock(&mut self, apb2: &mut APB2) {
284-
match stringify!($adc) {
285-
"adc1" => apb2.enr().modify(|_, w| w.adc1en().clear_bit()), // for ADC1
286-
"adc2" => apb2.enr().modify(|_, w| w.adc2en().clear_bit()), // for ADC2
287-
"adc3" => apb2.enr().modify(|_, w| w.adc3en().clear_bit()), // for ADC3
288-
_ => unreachable!(),
289-
}
290-
}
291-
292269
// 15.3.5 Single conversion mode (page: 444)
293270
// CONT bit >> 0 (continuous)
294271
// see EXTEN and EXTSEL[3:0]: for triggers (page:471)
@@ -434,7 +411,7 @@ macro_rules! adc_hal {
434411
/// Powers down the ADC, disables the ADC clock and releases the ADC Peripheral
435412
pub fn release(mut self, apb2: &mut APB2) -> $ADC {
436413
self.power_down();
437-
self.disable_clock(apb2);
414+
<$ADC>::disable(apb2);
438415
self.rb
439416
}
440417
}

src/dac.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
use crate::gpio::{
2-
gpioa::{PA4, PA5},
3-
Analog,
1+
use crate::pac::DAC;
2+
use crate::{
3+
gpio::{
4+
gpioa::{PA4, PA5},
5+
Analog,
6+
},
7+
rcc::{Enable, Reset},
48
};
5-
use crate::pac::{DAC, RCC};
69

710
/// DAC Errors
811
#[derive(Debug)]
@@ -46,15 +49,8 @@ where
4649
PINS: Pins<DAC>,
4750
{
4851
unsafe {
49-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
50-
let rcc = &(*RCC::ptr());
51-
rcc.apb1enr.modify(|_, w| w.dacen().set_bit());
52-
53-
// Stall the pipeline to work around erratum 2.1.13 (DM00037591)
54-
cortex_m::asm::dsb();
55-
56-
rcc.apb1rstr.write(|w| w.dacrst().set_bit());
57-
rcc.apb1rstr.write(|w| w.dacrst().clear_bit());
52+
DAC::enable_unchecked();
53+
DAC::reset_unchecked();
5854

5955
// NOTE(unsafe) ZST, doesn't need initialization.
6056
assert!(mem::size_of::<PINS::Output>() == 0);

src/dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
Interrupt, DMA1, DMA2, NVIC,
1818
},
1919
qspi,
20-
rcc::{sealed::RccBus, Enable, Reset},
20+
rcc::{Enable, RccBus, Reset},
2121
serial, spi, state,
2222
};
2323

src/fmc.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use stm32_fmc::FmcPeripheral;
77
use stm32_fmc::{AddressPinSet, PinsSdram, Sdram, SdramChip, SdramPinSet, SdramTargetBank};
88

99
use crate::embedded_time::rate::Hertz;
10-
use crate::pac as stm32;
11-
use crate::rcc::Clocks;
10+
use crate::pac;
11+
use crate::rcc::{Clocks, Enable, Reset};
1212

1313
use crate::gpio::gpioa::PA7;
1414
use crate::gpio::gpiob::{PB5, PB6, PB7};
@@ -56,7 +56,7 @@ use crate::gpio::Alternate;
5656

5757
/// Storage type for Flexible Memory Controller and its clocks
5858
pub struct FMC {
59-
pub fmc: stm32::FMC,
59+
pub fmc: pac::FMC,
6060
hclk: Hertz,
6161
}
6262

@@ -92,7 +92,7 @@ pub trait FmcExt: Sized {
9292
}
9393
}
9494

95-
impl FmcExt for stm32::FMC {
95+
impl FmcExt for pac::FMC {
9696
/// New FMC instance
9797
fn fmc(self, clocks: &Clocks) -> FMC {
9898
FMC {
@@ -103,17 +103,16 @@ impl FmcExt for stm32::FMC {
103103
}
104104

105105
unsafe impl FmcPeripheral for FMC {
106-
const REGISTERS: *const () = stm32::FMC::ptr() as *const ();
106+
const REGISTERS: *const () = pac::FMC::ptr() as *const ();
107107

108108
fn enable(&mut self) {
109109
// TODO : change it to something safe ...
110-
let rcc = unsafe { &(*stm32::RCC::ptr()) };
111-
112-
// Enable FMC
113-
rcc.ahb3enr.modify(|_, w| w.fmcen().enabled());
114-
// Reset FMC
115-
rcc.ahb3rstr.modify(|_, w| w.fmcrst().reset());
116-
rcc.ahb3rstr.modify(|_, w| w.fmcrst().clear_bit());
110+
unsafe {
111+
// Enable FMC
112+
pac::FMC::enable_unchecked();
113+
// Reset FMC
114+
pac::FMC::reset_unchecked();
115+
}
117116
}
118117

119118
fn source_clock_hz(&self) -> u32 {

src/gpio.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ use embedded_hal::digital::v2::{
5252
InputPin, IoPin, OutputPin, StatefulOutputPin, ToggleableOutputPin,
5353
};
5454

55-
use crate::pac::{EXTI, RCC, SYSCFG};
55+
use crate::pac::{EXTI, SYSCFG};
56+
use crate::rcc::{Enable, APB2};
5657

5758
mod convert;
5859

@@ -160,7 +161,7 @@ impl<MODE> Interruptable for Input<MODE> {}
160161

161162
/// External Interrupt Pin
162163
pub trait ExtiPin {
163-
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG, rcc: &mut RCC);
164+
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG, apb2: &mut APB2);
164165
fn trigger_on_edge(&mut self, exti: &mut EXTI, level: Edge);
165166
fn enable_interrupt(&mut self, exti: &mut EXTI);
166167
fn disable_interrupt(&mut self, exti: &mut EXTI);
@@ -175,9 +176,9 @@ where
175176
{
176177
/// Make corresponding EXTI line sensitive to this pin
177178
#[inline(always)]
178-
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG, rcc: &mut RCC) {
179+
fn make_interrupt_source(&mut self, syscfg: &mut SYSCFG, apb2: &mut APB2) {
179180
// SYSCFG clock must be enabled in order to do register writes
180-
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
181+
SYSCFG::enable(apb2);
181182

182183
let i = self.pin_id();
183184
let port = self.port_id() as u32;
@@ -584,12 +585,13 @@ impl<const P: char, const N: u8> IoPin<Self, Pin<Output<PushPull>, P, N>>
584585
}
585586

586587
macro_rules! gpio {
587-
($GPIOX:ident, $gpiox:ident, $PEPin:ident, $port_id:expr, $PXn:ident, $iopxenr:ident, $iopxrstr:ident, [
588+
($GPIOX:ident, $gpiox:ident, $PEPin:ident, $port_id:expr, $PXn:ident, [
588589
$($PXi:ident: ($pxi:ident, $i:expr, $MODE:ty),)+
589590
]) => {
590591
/// GPIO
591592
pub mod $gpiox {
592-
use crate::pac::{$GPIOX, RCC};
593+
use crate::rcc::{Enable, Reset};
594+
use crate::pac::$GPIOX;
593595
use super::{
594596
Floating, Input,
595597
};
@@ -606,11 +608,10 @@ macro_rules! gpio {
606608
type Parts = Parts;
607609

608610
fn split(self) -> Parts {
609-
// NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
610-
let rcc = unsafe { &(*RCC::ptr()) };
611-
rcc.ahb1enr.modify(|_, w| w.$iopxenr().set_bit());
612-
rcc.ahb1rstr.modify(|_, w| w.$iopxrstr().set_bit());
613-
rcc.ahb1rstr.modify(|_, w| w.$iopxrstr().clear_bit());
611+
unsafe {
612+
<$GPIOX>::enable_unchecked();
613+
<$GPIOX>::reset_unchecked();
614+
}
614615

615616
Parts {
616617
$(
@@ -630,7 +631,7 @@ macro_rules! gpio {
630631
}
631632
}
632633

633-
gpio!(GPIOA, gpioa, PA, 'A', PAn, gpioaen, gpioarst, [
634+
gpio!(GPIOA, gpioa, PA, 'A', PAn, [
634635
PA0: (pa0, 0, Input<Floating>),
635636
PA1: (pa1, 1, Input<Floating>),
636637
PA2: (pa2, 2, Input<Floating>),
@@ -649,7 +650,7 @@ gpio!(GPIOA, gpioa, PA, 'A', PAn, gpioaen, gpioarst, [
649650
PA15: (pa15, 15, Input<Floating>),
650651
]);
651652

652-
gpio!(GPIOB, gpiob, PB, 'B', PBn, gpioben, gpiobrst, [
653+
gpio!(GPIOB, gpiob, PB, 'B', PBn, [
653654
PB0: (pb0, 0, Input<Floating>),
654655
PB1: (pb1, 1, Input<Floating>),
655656
PB2: (pb2, 2, Input<Floating>),
@@ -668,7 +669,7 @@ gpio!(GPIOB, gpiob, PB, 'B', PBn, gpioben, gpiobrst, [
668669
PB15: (pb15, 15, Input<Floating>),
669670
]);
670671

671-
gpio!(GPIOC, gpioc, PC, 'C', PCn, gpiocen, gpiocrst, [
672+
gpio!(GPIOC, gpioc, PC, 'C', PCn, [
672673
PC0: (pc0, 0, Input<Floating>),
673674
PC1: (pc1, 1, Input<Floating>),
674675
PC2: (pc2, 2, Input<Floating>),
@@ -687,7 +688,7 @@ gpio!(GPIOC, gpioc, PC, 'C', PCn, gpiocen, gpiocrst, [
687688
PC15: (pc15, 15, Input<Floating>),
688689
]);
689690

690-
gpio!(GPIOD, gpiod, PD, 'D', PDn, gpioden, gpiodrst, [
691+
gpio!(GPIOD, gpiod, PD, 'D', PDn, [
691692
PD0: (pd0, 0, Input<Floating>),
692693
PD1: (pd1, 1, Input<Floating>),
693694
PD2: (pd2, 2, Input<Floating>),
@@ -706,7 +707,7 @@ gpio!(GPIOD, gpiod, PD, 'D', PDn, gpioden, gpiodrst, [
706707
PD15: (pd15, 15, Input<Floating>),
707708
]);
708709

709-
gpio!(GPIOE, gpioe, PE, 'E', PEn, gpioeen, gpioerst, [
710+
gpio!(GPIOE, gpioe, PE, 'E', PEn, [
710711
PE0: (pe0, 0, Input<Floating>),
711712
PE1: (pe1, 1, Input<Floating>),
712713
PE2: (pe2, 2, Input<Floating>),
@@ -725,7 +726,7 @@ gpio!(GPIOE, gpioe, PE, 'E', PEn, gpioeen, gpioerst, [
725726
PE15: (pe15, 15, Input<Floating>),
726727
]);
727728

728-
gpio!(GPIOF, gpiof, PF, 'F', PFn, gpiofen, gpiofrst, [
729+
gpio!(GPIOF, gpiof, PF, 'F', PFn, [
729730
PF0: (pf0, 0, Input<Floating>),
730731
PF1: (pf1, 1, Input<Floating>),
731732
PF2: (pf2, 2, Input<Floating>),
@@ -744,7 +745,7 @@ gpio!(GPIOF, gpiof, PF, 'F', PFn, gpiofen, gpiofrst, [
744745
PF15: (pf15, 15, Input<Floating>),
745746
]);
746747

747-
gpio!(GPIOG, gpiog, PG, 'G', PGn, gpiogen, gpiogrst, [
748+
gpio!(GPIOG, gpiog, PG, 'G', PGn, [
748749
PG0: (pg0, 0, Input<Floating>),
749750
PG1: (pg1, 1, Input<Floating>),
750751
PG2: (pg2, 2, Input<Floating>),
@@ -763,7 +764,7 @@ gpio!(GPIOG, gpiog, PG, 'G', PGn, gpiogen, gpiogrst, [
763764
PG15: (pg15, 15, Input<Floating>),
764765
]);
765766

766-
gpio!(GPIOH, gpioh, PH, 'H', PHn, gpiohen, gpiohrst, [
767+
gpio!(GPIOH, gpioh, PH, 'H', PHn, [
767768
PH0: (ph0, 0, Input<Floating>),
768769
PH1: (ph1, 1, Input<Floating>),
769770
PH2: (ph2, 2, Input<Floating>),
@@ -782,7 +783,7 @@ gpio!(GPIOH, gpioh, PH, 'H', PHn, gpiohen, gpiohrst, [
782783
PH15: (ph15, 15, Input<Floating>),
783784
]);
784785

785-
gpio!(GPIOI, gpioi, PI, 'I', PIn, gpioien, gpioirst, [
786+
gpio!(GPIOI, gpioi, PI, 'I', PIn, [
786787
PI0: (pi0, 0, Input<Floating>),
787788
PI1: (pi1, 1, Input<Floating>),
788789
PI2: (pi2, 2, Input<Floating>),
@@ -802,7 +803,7 @@ gpio!(GPIOI, gpioi, PI, 'I', PIn, gpioien, gpioirst, [
802803
]);
803804

804805
#[cfg(feature = "gpioj")]
805-
gpio!(GPIOJ, gpioj, PJ, 'J', PJn, gpiojen, gpiojrst, [
806+
gpio!(GPIOJ, gpioj, PJ, 'J', PJn, [
806807
PJ0: (pj0, 0, Input<Floating>),
807808
PJ1: (pj1, 1, Input<Floating>),
808809
PJ2: (pj2, 2, Input<Floating>),
@@ -822,7 +823,7 @@ gpio!(GPIOJ, gpioj, PJ, 'J', PJn, gpiojen, gpiojrst, [
822823
]);
823824

824825
#[cfg(feature = "gpiok")]
825-
gpio!(GPIOK, gpiok, PK, 'K', PKn, gpioken, gpiokrst, [
826+
gpio!(GPIOK, gpiok, PK, 'K', PKn, [
826827
PK0: (pk0, 0, Input<Floating>),
827828
PK1: (pk1, 1, Input<Floating>),
828829
PK2: (pk2, 2, Input<Floating>),

src/i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::gpio::gpioh::{PH4, PH5, PH7, PH8};
1212
use crate::gpio::AlternateOD;
1313
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
1414
use crate::pac::{DWT, I2C1, I2C2, I2C3};
15-
use crate::rcc::{sealed::RccBus, Clocks, Enable, GetBusFreq, Reset};
15+
use crate::rcc::{Clocks, Enable, GetBusFreq, RccBus, Reset};
1616
use nb::Error::{Other, WouldBlock};
1717
use nb::{Error as NbError, Result as NbResult};
1818

0 commit comments

Comments
 (0)