Skip to content

Commit e8e9c2d

Browse files
authored
Pwr (#95)
* NOT DONE add pwr config * Start work on voltage scaling * PWR allow dead code for function that will be used to change voltage range once allowed * Forgot to add mod pwr import * Fix examples for the RCC PWR change * PWR - Boost mode inverted
1 parent a33b9fc commit e8e9c2d

18 files changed

+381
-43
lines changed

examples/adc-continious-dma.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::hal::{
1111
delay::SYSTDelayExt,
1212
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
1313
gpio::GpioExt,
14+
pwr::PwrExt,
1415
rcc::{Config, RccExt},
1516
stm32::Peripherals,
1617
};
@@ -33,7 +34,8 @@ fn main() -> ! {
3334

3435
info!("rcc");
3536
let rcc = dp.RCC.constrain();
36-
let mut rcc = rcc.freeze(Config::hsi());
37+
let pwr = dp.PWR.constrain().freeze();
38+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3739

3840
let streams = dp.DMA1.split(&rcc);
3941
let config = DmaConfig::default()

examples/adc-continious.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ use crate::hal::{
88
},
99
delay::SYSTDelayExt,
1010
gpio::GpioExt,
11+
pwr::PwrExt,
1112
rcc::{Config, RccExt},
1213
stm32::Peripherals,
1314
};
1415
use stm32g4xx_hal as hal;
1516

1617
use cortex_m_rt::entry;
1718

18-
use log::info;
19+
use utils::logger::info;
1920

2021
#[macro_use]
2122
mod utils;
@@ -32,7 +33,8 @@ fn main() -> ! {
3233
info!("rcc");
3334

3435
let rcc = dp.RCC.constrain();
35-
let mut rcc = rcc.freeze(Config::hsi());
36+
let pwr = dp.PWR.constrain().freeze();
37+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3638

3739
info!("Setup Gpio");
3840
let gpioa = dp.GPIOA.split(&mut rcc);

examples/adc-one-shot-dma.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::hal::{
1111
delay::SYSTDelayExt,
1212
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
1313
gpio::GpioExt,
14+
pwr::PwrExt,
1415
rcc::{Config, RccExt},
1516
stm32::Peripherals,
1617
};
@@ -33,7 +34,8 @@ fn main() -> ! {
3334
info!("rcc");
3435

3536
let rcc = dp.RCC.constrain();
36-
let mut rcc = rcc.freeze(Config::hsi());
37+
let pwr = dp.PWR.constrain().freeze();
38+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3739

3840
let mut streams = dp.DMA1.split(&rcc);
3941
let config = DmaConfig::default()

examples/adc-one-shot.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#![no_std]
33

44
use crate::hal::{
5-
adc::{config::SampleTime, AdcClaim, ClockSource},
5+
adc::{config::SampleTime, AdcClaim},
66
delay::SYSTDelayExt,
7+
pwr::PwrExt,
78
rcc::Config,
89
stm32::Peripherals,
910
};
@@ -29,26 +30,31 @@ fn main() -> ! {
2930
info!("rcc");
3031

3132
let rcc = dp.RCC.constrain();
32-
let mut rcc = rcc.freeze(Config::hsi());
33+
let pwr = dp.PWR.constrain().freeze();
34+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3335

3436
info!("Setup Adc1");
3537
let mut delay = cp.SYST.delay(&rcc.clocks);
36-
let mut adc = dp
37-
.ADC1
38-
.claim(ClockSource::SystemClock, &rcc, &mut delay, true);
38+
let mut adc = dp.ADC2.claim_and_configure(
39+
stm32g4xx_hal::adc::ClockSource::SystemClock,
40+
&rcc,
41+
stm32g4xx_hal::adc::config::AdcConfig::default(),
42+
&mut delay,
43+
false,
44+
);
3945

4046
info!("Setup Gpio");
4147

4248
let gpioa = dp.GPIOA.split(&mut rcc);
43-
let pa0 = gpioa.pa0.into_analog();
49+
let pa7 = gpioa.pa7.into_analog();
4450

4551
info!("Enter Loop");
4652

4753
loop {
4854
info!("Convert");
49-
let sample = adc.convert(&pa0, SampleTime::Cycles_640_5);
55+
let sample = adc.convert(&pa7, SampleTime::Cycles_640_5);
5056
info!("sample to mv");
5157
let millivolts = adc.sample_to_millivolts(sample);
52-
info!("pa3: {}mV", millivolts);
58+
info!("pa7: {}mV", millivolts);
5359
}
5460
}

examples/blinky_delay.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use hal::delay::DelayFromCountDownTimer;
77
use hal::prelude::*;
8+
use hal::pwr::PwrExt;
89
use hal::rcc::Config;
910
use hal::stm32;
1011
use hal::time::ExtU32;
@@ -24,7 +25,8 @@ fn main() -> ! {
2425
info!("start");
2526
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
2627
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
27-
let mut rcc = dp.RCC.freeze(Config::hsi());
28+
let pwr = dp.PWR.constrain().freeze();
29+
let mut rcc = dp.RCC.freeze(Config::hsi(), pwr);
2830

2931
info!("Init Led");
3032
let gpioa = dp.GPIOA.split(&mut rcc);

examples/can-echo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::hal::{
55
can::CanExt,
66
gpio::{GpioExt as _, Speed},
77
nb::block,
8+
pwr::PwrExt,
89
rcc::{Config, RccExt, SysClockSrc},
910
stm32::Peripherals,
1011
time::RateExtU32,
@@ -46,8 +47,10 @@ fn main() -> ! {
4647

4748
let dp = Peripherals::take().unwrap();
4849
let _cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
50+
51+
let pwr = dp.PWR.constrain().freeze();
4952
let rcc = dp.RCC.constrain();
50-
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.MHz())));
53+
let mut rcc = rcc.freeze(Config::new(SysClockSrc::HSE(24.MHz())), pwr);
5154

5255
info!("Split GPIO");
5356

examples/clockout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ extern crate panic_halt;
99
extern crate stm32g4xx_hal as hal;
1010

1111
use hal::prelude::*;
12+
use hal::pwr::PwrExt;
1213
use hal::rcc::{Config, LSCOSrc, MCOSrc, Prescaler};
1314
use hal::stm32;
1415
use rt::entry;
1516

1617
#[entry]
1718
fn main() -> ! {
1819
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
19-
let mut rcc = dp.RCC.freeze(Config::hsi());
20+
let pwr = dp.PWR.constrain().freeze();
21+
let mut rcc = dp.RCC.freeze(Config::hsi(), pwr);
2022
let gpioa = dp.GPIOA.split(&mut rcc);
2123

2224
let lsco = gpioa.pa2.lsco(LSCOSrc::LSI, &mut rcc);

examples/opamp.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use stm32g4xx_hal::opamp::opamp2::IntoPga as _;
1212
use stm32g4xx_hal::opamp::NonInvertingGain;
1313
use stm32g4xx_hal::opamp::PgaModeInternal;
1414
use stm32g4xx_hal::prelude::*;
15+
use stm32g4xx_hal::pwr::PwrExt;
1516

1617
use utils::logger::info;
1718

@@ -26,9 +27,10 @@ fn main() -> ! {
2627
let dp = stm32g4xx_hal::stm32::Peripherals::take().unwrap();
2728
let cp = cortex_m::Peripherals::take().expect("cannot take core peripherals");
2829

29-
// setup clock
30+
// setup clock and power
31+
let pwr = dp.PWR.constrain().freeze();
3032
let config = stm32g4xx_hal::rcc::Config::hsi();
31-
let mut rcc = dp.RCC.freeze(config);
33+
let mut rcc = dp.RCC.freeze(config, pwr);
3234

3335
// split gpio
3436
let gpioa = dp.GPIOA.split(&mut rcc);

examples/spi-example.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::hal::{
1414
gpio::Alternate,
1515
gpio::AF5,
1616
prelude::*,
17+
pwr::PwrExt,
1718
rcc::Config,
1819
spi,
1920
stm32::Peripherals,
@@ -34,7 +35,8 @@ fn main() -> ! {
3435

3536
let dp = Peripherals::take().unwrap();
3637
let rcc = dp.RCC.constrain();
37-
let mut rcc = rcc.freeze(Config::hsi());
38+
let pwr = dp.PWR.constrain().freeze();
39+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3840
let timer2 = Timer::new(dp.TIM2, &rcc.clocks);
3941
let mut delay_tim2 = DelayFromCountDownTimer::new(timer2.start_count_down(100.millis()));
4042

examples/spi-sd.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use hal::gpio::gpiof::PF9;
1212
use hal::gpio::Alternate;
1313
use hal::gpio::AF5;
1414
use hal::prelude::*;
15+
use hal::pwr::PwrExt;
1516
use hal::rcc::Config;
1617
use hal::spi;
1718

@@ -31,7 +32,8 @@ fn main() -> ! {
3132

3233
let dp = Peripherals::take().unwrap();
3334
let rcc = dp.RCC.constrain();
34-
let mut rcc = rcc.freeze(Config::hsi());
35+
let pwr = dp.PWR.constrain().freeze();
36+
let mut rcc = rcc.freeze(Config::hsi(), pwr);
3537
let gpiob = dp.GPIOB.split(&mut rcc);
3638
let gpiof = dp.GPIOF.split(&mut rcc);
3739

0 commit comments

Comments
 (0)