Skip to content

Commit 2f957d1

Browse files
committed
&mut Rcc
1 parent e78625e commit 2f957d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+728
-787
lines changed

examples/adc-dma-circ.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ use panic_halt as _;
99
use cortex_m::{asm, singleton};
1010

1111
use cortex_m_rt::entry;
12-
use stm32f1xx_hal::{adc, dma::Half, pac, prelude::*};
12+
use stm32f1xx_hal::{adc, dma::Half, pac, prelude::*, rcc};
1313

1414
#[entry]
1515
fn main() -> ! {
1616
// Acquire peripherals
1717
let p = pac::Peripherals::take().unwrap();
1818
let mut flash = p.FLASH.constrain();
19-
let rcc = p.RCC.constrain();
2019

2120
// Configure ADC clocks
2221
// Default value is the slowest possible ADC clock: PCLK2 / 8. Meanwhile ADC
2322
// clock is configurable. So its frequency may be tweaked to meet certain
2423
// practical needs. User specified value is be approximated using supported
2524
// prescaler values 2/4/6/8.
26-
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
25+
let mut rcc = p
26+
.RCC
27+
.freeze(rcc::Config::hsi().adcclk(2.MHz()), &mut flash.acr);
2728

28-
let dma_ch1 = p.DMA1.split().1;
29+
let dma_ch1 = p.DMA1.split(&mut rcc).1;
2930

3031
// Setup ADC
31-
let adc1 = adc::Adc::new(p.ADC1, &clocks);
32+
let adc1 = adc::Adc::new(p.ADC1, &mut rcc);
3233

3334
// Setup GPIOA
34-
let mut gpioa = p.GPIOA.split();
35+
let mut gpioa = p.GPIOA.split(&mut rcc);
3536

3637
// Configure pa0 as an analog input
3738
let adc_ch0 = gpioa.pa0.into_analog(&mut gpioa.crl);

examples/adc-dma-rx.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,30 @@ use panic_halt as _;
99
use cortex_m::{asm, singleton};
1010

1111
use cortex_m_rt::entry;
12-
use stm32f1xx_hal::{adc, pac, prelude::*};
12+
use stm32f1xx_hal::{adc, pac, prelude::*, rcc};
1313

1414
#[entry]
1515
fn main() -> ! {
1616
// Acquire peripherals
1717
let p = pac::Peripherals::take().unwrap();
1818
let mut flash = p.FLASH.constrain();
19-
let rcc = p.RCC.constrain();
2019

2120
// Configure ADC clocks
2221
// Default value is the slowest possible ADC clock: PCLK2 / 8. Meanwhile ADC
2322
// clock is configurable. So its frequency may be tweaked to meet certain
2423
// practical needs. User specified value is be approximated using supported
2524
// prescaler values 2/4/6/8.
26-
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
25+
let mut rcc = p
26+
.RCC
27+
.freeze(rcc::Config::hsi().adcclk(2.MHz()), &mut flash.acr);
2728

28-
let dma_ch1 = p.DMA1.split().1;
29+
let dma_ch1 = p.DMA1.split(&mut rcc).1;
2930

3031
// Setup ADC
31-
let adc1 = adc::Adc::new(p.ADC1, &clocks);
32+
let adc1 = adc::Adc::new(p.ADC1, &mut rcc);
3233

3334
// Setup GPIOA
34-
let mut gpioa = p.GPIOA.split();
35+
let mut gpioa = p.GPIOA.split(&mut rcc);
3536

3637
// Configure pa0 as an analog input
3738
let adc_ch0 = gpioa.pa0.into_analog(&mut gpioa.crl);

examples/adc.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use panic_semihosting as _;
66

77
use cortex_m_rt::entry;
8-
use stm32f1xx_hal::{adc, pac, prelude::*};
8+
use stm32f1xx_hal::{adc, pac, prelude::*, rcc};
99

1010
use cortex_m_semihosting::hprintln;
1111

@@ -14,24 +14,26 @@ fn main() -> ! {
1414
// Acquire peripherals
1515
let p = pac::Peripherals::take().unwrap();
1616
let mut flash = p.FLASH.constrain();
17-
let rcc = p.RCC.constrain();
1817

1918
// Configure ADC clocks
2019
// Default value is the slowest possible ADC clock: PCLK2 / 8. Meanwhile ADC
2120
// clock is configurable. So its frequency may be tweaked to meet certain
2221
// practical needs. User specified value is be approximated using supported
2322
// prescaler values 2/4/6/8.
24-
let clocks = rcc.cfgr.adcclk(2.MHz()).freeze(&mut flash.acr);
25-
hprintln!("adc freq: {}", clocks.adcclk());
23+
let mut rcc = p
24+
.RCC
25+
.freeze(rcc::Config::hsi().adcclk(2.MHz()), &mut flash.acr);
26+
27+
hprintln!("adc freq: {}", rcc.clocks.adcclk());
2628

2729
// Setup ADC
28-
let mut adc1 = adc::Adc::new(p.ADC1, &clocks);
30+
let mut adc1 = adc::Adc::new(p.ADC1, &mut rcc);
2931

3032
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
31-
let mut adc2 = adc::Adc::new(p.ADC2, &clocks);
33+
let mut adc2 = adc::Adc::new(p.ADC2, &mut rcc);
3234

3335
// Setup GPIOB
34-
let mut gpiob = p.GPIOB.split();
36+
let mut gpiob = p.GPIOB.split(&mut rcc);
3537

3638
// Configure pb0, pb1 as an analog input
3739
let mut ch0 = gpiob.pb0.into_analog(&mut gpiob.crl);

examples/adc_temperature.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use panic_semihosting as _;
66

77
use cortex_m_rt::entry;
8-
use stm32f1xx_hal::{pac, prelude::*};
8+
use stm32f1xx_hal::{pac, prelude::*, rcc};
99

1010
use cortex_m_semihosting::hprintln;
1111

@@ -14,31 +14,34 @@ fn main() -> ! {
1414
// Acquire peripherals
1515
let p = pac::Peripherals::take().unwrap();
1616
let mut flash = p.FLASH.constrain();
17-
let rcc = p.RCC.constrain();
18-
19-
let clocks = rcc
20-
.cfgr
21-
.use_hse(8.MHz())
22-
.sysclk(56.MHz())
23-
.pclk1(28.MHz())
24-
.adcclk(14.MHz())
25-
.freeze(&mut flash.acr);
17+
let mut rcc = p.RCC.freeze(
18+
rcc::Config::hse(8.MHz())
19+
.sysclk(56.MHz())
20+
.pclk1(28.MHz())
21+
.adcclk(14.MHz()),
22+
&mut flash.acr,
23+
);
24+
2625
/*
2726
// Alternative configuration using dividers and multipliers directly
28-
let clocks = rcc.cfgr.freeze_with_config(rcc::Config {
29-
hse: Some(8_000_000),
30-
pllmul: Some(7),
31-
hpre: rcc::HPre::DIV1,
32-
ppre1: rcc::PPre::DIV2,
33-
ppre2: rcc::PPre::DIV1,
34-
usbpre: rcc::UsbPre::DIV1_5,
35-
adcpre: rcc::AdcPre::DIV2,
36-
}, &mut flash.acr);*/
37-
hprintln!("sysclk freq: {}", clocks.sysclk());
38-
hprintln!("adc freq: {}", clocks.adcclk());
27+
let rcc = p.RCC.freeze_raw(
28+
rcc::RawConfig {
29+
hse: Some(8_000_000),
30+
pllmul: Some(7),
31+
hpre: rcc::HPre::Div1,
32+
ppre1: rcc::PPre::Div2,
33+
ppre2: rcc::PPre::Div1,
34+
usbpre: rcc::UsbPre::Div1_5,
35+
adcpre: rcc::AdcPre::Div2,
36+
..Default::default()
37+
},
38+
&mut flash.acr,
39+
);*/
40+
hprintln!("sysclk freq: {}", rcc.clocks.sysclk());
41+
hprintln!("adc freq: {}", rcc.clocks.adcclk());
3942

4043
// Setup ADC
41-
let mut adc = p.ADC1.adc(&clocks);
44+
let mut adc = p.ADC1.adc(&mut rcc);
4245

4346
// Read temperature sensor
4447
loop {

examples/blinky.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@ fn main() -> ! {
2323
// Get access to the device specific peripherals from the peripheral access crate
2424
let dp = pac::Peripherals::take().unwrap();
2525

26-
// Take ownership over the raw flash and rcc devices and convert them into the corresponding
27-
// HAL structs
28-
let mut flash = dp.FLASH.constrain();
29-
let rcc = dp.RCC.constrain();
30-
31-
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
32-
// `clocks`
33-
let clocks = rcc.cfgr.freeze(&mut flash.acr);
26+
let mut rcc = dp.RCC.constrain();
3427

3528
// Acquire the GPIOC peripheral
36-
let mut gpioc = dp.GPIOC.split();
29+
let mut gpioc = dp.GPIOC.split(&mut rcc);
3730

3831
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
3932
// in order to configure the port. For pins 0-7, crl should be passed instead.
4033
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
4134
// Configure the syst timer to trigger an update every second
42-
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
35+
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
4336
timer.start(1.Hz()).unwrap();
4437

4538
// Wait for the timer to trigger an update and change the state of the LED

examples/blinky_generic.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@ fn main() -> ! {
1616
let cp = cortex_m::Peripherals::take().unwrap();
1717
let dp = pac::Peripherals::take().unwrap();
1818

19-
let mut flash = dp.FLASH.constrain();
20-
let rcc = dp.RCC.constrain();
21-
22-
let clocks = rcc.cfgr.freeze(&mut flash.acr);
19+
let mut rcc = dp.RCC.constrain();
2320

2421
// Acquire the GPIO peripherals
25-
let mut gpioa = dp.GPIOA.split();
26-
let mut gpioc = dp.GPIOC.split();
22+
let mut gpioa = dp.GPIOA.split(&mut rcc);
23+
let mut gpioc = dp.GPIOC.split(&mut rcc);
2724

2825
// Configure the syst timer to trigger an update every second
29-
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
26+
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
3027
timer.start(1.Hz()).unwrap();
3128

3229
// Create an array of LEDS to blink

examples/blinky_rtc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ fn main() -> ! {
2222
let dp = pac::Peripherals::take().unwrap();
2323

2424
let mut pwr = dp.PWR;
25-
let rcc = dp.RCC.constrain();
25+
let mut rcc = dp.RCC.constrain();
2626

2727
// Set up the GPIO pin
28-
let mut gpioc = dp.GPIOC.split();
28+
let mut gpioc = dp.GPIOC.split(&mut rcc);
2929
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
3030

3131
// Set up the RTC
3232
// Enable writes to the backup domain
33-
let mut backup_domain = rcc.bkp.constrain(dp.BKP, &mut pwr);
33+
let mut backup_domain = dp.BKP.constrain(&mut pwr, &mut rcc);
3434
// Start the RTC
35-
let mut rtc = Rtc::new(dp.RTC, &mut backup_domain);
35+
let mut rtc = Rtc::new(dp.RTC, &mut backup_domain, &mut rcc);
3636

3737
let mut led_on = false;
3838
loop {

examples/blinky_rtcalarm_irq.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ fn main() -> ! {
7878
let dp = Peripherals::take().unwrap();
7979

8080
let mut pwr = dp.PWR;
81-
let rcc = dp.RCC.constrain();
81+
let mut rcc = dp.RCC.constrain();
8282

8383
// Set up the GPIO pin
84-
let mut gpioc = dp.GPIOC.split();
84+
let mut gpioc = dp.GPIOC.split(&mut rcc);
8585
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
8686
let _ = led.set_high(); // Turn off
8787

@@ -96,9 +96,9 @@ fn main() -> ! {
9696

9797
// Set up the RTC
9898
// Enable writes to the backup domain
99-
let mut backup_domain = rcc.bkp.constrain(dp.BKP, &mut pwr);
99+
let mut backup_domain = dp.BKP.constrain(&mut pwr, &mut rcc);
100100
// Start the RTC
101-
let mut rtc = Rtc::new(dp.RTC, &mut backup_domain);
101+
let mut rtc = Rtc::new(dp.RTC, &mut backup_domain, &mut rcc);
102102
rtc.set_time(0);
103103
rtc.set_alarm(TOGGLE_INTERVAL_SECONDS);
104104
rtc.listen_alarm();

examples/blinky_timer_irq.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::hal::{
1818
gpio::{gpioc, Output, PinState, PushPull},
1919
pac::{interrupt, Interrupt, Peripherals, TIM2},
2020
prelude::*,
21+
rcc,
2122
timer::{CounterMs, Event},
2223
};
2324

@@ -69,16 +70,14 @@ fn TIM2() {
6970
fn main() -> ! {
7071
let dp = Peripherals::take().unwrap();
7172

72-
let rcc = dp.RCC.constrain();
7373
let mut flash = dp.FLASH.constrain();
74-
let clocks = rcc
75-
.cfgr
76-
.sysclk(8.MHz())
77-
.pclk1(8.MHz())
78-
.freeze(&mut flash.acr);
74+
let mut rcc = dp.RCC.freeze(
75+
rcc::Config::hsi().sysclk(8.MHz()).pclk1(8.MHz()),
76+
&mut flash.acr,
77+
);
7978

8079
// Configure PC13 pin to blink LED
81-
let mut gpioc = dp.GPIOC.split();
80+
let mut gpioc = dp.GPIOC.split(&mut rcc);
8281
let led = Output::new(gpioc.pc13, &mut gpioc.crh, PinState::High);
8382
//or
8483
//let led = gpioc.pc13.into_push_pull_output_with_state(&mut gpioc.crh, PinState::High);
@@ -87,7 +86,7 @@ fn main() -> ! {
8786
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));
8887

8988
// Set up a timer expiring after 1s
90-
let mut timer = dp.TIM2.counter_ms(&clocks);
89+
let mut timer = dp.TIM2.counter_ms(&mut rcc);
9190
timer.start(1.secs()).unwrap();
9291

9392
// Generate an interrupt when the timer expires

examples/can-echo.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,28 @@ use panic_halt as _;
1010
use bxcan::filter::Mask32;
1111
use cortex_m_rt::entry;
1212
use nb::block;
13-
use stm32f1xx_hal::{pac, prelude::*};
13+
use stm32f1xx_hal::{pac, prelude::*, rcc};
1414

1515
#[entry]
1616
fn main() -> ! {
1717
let dp = pac::Peripherals::take().unwrap();
1818

1919
let mut flash = dp.FLASH.constrain();
20-
let rcc = dp.RCC.constrain();
2120

2221
// To meet CAN clock accuracy requirements an external crystal or ceramic
2322
// resonator must be used. The blue pill has a 8MHz external crystal.
2423
// Other boards might have a crystal with another frequency or none at all.
25-
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
24+
let mut rcc = dp.RCC.freeze(rcc::Config::hse(8.MHz()), &mut flash.acr);
2625

2726
let mut can1 = {
28-
let gpioa = dp.GPIOA.split();
27+
let gpioa = dp.GPIOA.split(&mut rcc);
2928
let rx = gpioa.pa11;
3029
let tx = gpioa.pa12;
3130

3231
#[cfg(not(feature = "connectivity"))]
33-
let can = dp.CAN.can(dp.USB, (tx, rx));
32+
let can = dp.CAN.can(dp.USB, (tx, rx), &mut rcc);
3433
#[cfg(feature = "connectivity")]
35-
let can = dp.CAN1.can((tx, rx));
34+
let can = dp.CAN1.can((tx, rx), &mut rcc);
3635

3736
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
3837
// Value was calculated with http://www.bittiming.can-wiki.info/
@@ -47,8 +46,8 @@ fn main() -> ! {
4746

4847
#[cfg(feature = "connectivity")]
4948
let _can2 = {
50-
let gpiob = dp.GPIOB.split();
51-
let can = dp.CAN2.can((gpiob.pb6, gpiob.pb5));
49+
let gpiob = dp.GPIOB.split(&mut rcc);
50+
let can = dp.CAN2.can((gpiob.pb6, gpiob.pb5), &mut rcc);
5251

5352
// APB1 (PCLK1): 8MHz, Bit rate: 125kBit/s, Sample Point 87.5%
5453
// Value was calculated with http://www.bittiming.can-wiki.info/

examples/can-loopback.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ use panic_halt as _;
1212

1313
use cortex_m_rt::entry;
1414
use nb::block;
15-
use stm32f1xx_hal::{can::Can, gpio::Floating, pac, prelude::*};
15+
use stm32f1xx_hal::{can::Can, gpio::Floating, pac, prelude::*, rcc};
1616

1717
#[entry]
1818
fn main() -> ! {
1919
let dp = pac::Peripherals::take().unwrap();
2020

2121
let mut flash = dp.FLASH.constrain();
22-
let rcc = dp.RCC.constrain();
2322

2423
// To meet CAN clock accuracy requirements, an external crystal or ceramic
2524
// resonator must be used.
26-
rcc.cfgr.use_hse(8.MHz()).freeze(&mut flash.acr);
25+
let mut rcc = dp.RCC.freeze(rcc::Config::hse(8.MHz()), &mut flash.acr);
2726

2827
#[cfg(not(feature = "connectivity"))]
29-
let can = Can::<_, Floating>::new_loopback(dp.CAN, dp.USB);
28+
let can = Can::<_, Floating>::new_loopback(dp.CAN, dp.USB, &mut rcc);
3029
#[cfg(feature = "connectivity")]
31-
let can = Can::<_, Floating>::new_loopback(dp.CAN1);
30+
let can = Can::<_, Floating>::new_loopback(dp.CAN1, &mut rcc);
3231

3332
// Use loopback mode: No pins need to be assigned to peripheral.
3433
// APB1 (PCLK1): 8MHz, Bit rate: 500Bit/s, Sample Point 87.5%
@@ -109,7 +108,7 @@ fn main() -> ! {
109108
assert!(can.receive().is_err());
110109
}
111110

112-
let mut gpiob = dp.GPIOB.split();
111+
let mut gpiob = dp.GPIOB.split(&mut rcc);
113112
let mut led = gpiob.pb9.into_push_pull_output(&mut gpiob.crh);
114113
led.set_high();
115114

0 commit comments

Comments
 (0)