Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Implement `embedded_hal::i2c::I2c` for `I2cMasterDma` [#838]
- Back to `stm32f4`
- Implement `Ptr`, `Sealed`, `Steal` for generic `Periph` [#834]
- Use `&mut RCC` for `PER::enable/reset`
- Unmacro `Adc` [#832]
- Use `write` instead of `modify` to clear flags [#829]
- Bump `stm32f4-staging` to 0.18, update other dependencies [#831]
Expand Down
37 changes: 18 additions & 19 deletions examples/analog-stopwatch-with-spi-ssd1306.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#![no_main]

use panic_semihosting as _;
use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

use crate::hal::{
gpio::{Edge, Input, PA0},
interrupt, pac,
prelude::*,
rcc::{Clocks, Rcc},
rcc::Rcc,
spi::{Mode, Phase, Polarity, Spi},
timer::{CounterUs, Event, FTimer, Flag, Timer},
};
Expand Down Expand Up @@ -84,14 +84,12 @@ fn main() -> ! {
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
dp.RCC.apb2enr().write(|w| w.syscfgen().enabled());

let rcc = dp.RCC.constrain();
let mut rcc = setup_clocks(dp.RCC);

let clocks = setup_clocks(rcc);
let mut syscfg = dp.SYSCFG.constrain(&mut rcc);

let mut syscfg = dp.SYSCFG.constrain();

let gpioa = dp.GPIOA.split();
let gpioe = dp.GPIOE.split();
let gpioa = dp.GPIOA.split(&mut rcc);
let gpioe = dp.GPIOE.split(&mut rcc);

let mut board_btn = gpioa.pa0.into_pull_down_input();
board_btn.make_interrupt_source(&mut syscfg);
Expand All @@ -117,17 +115,17 @@ fn main() -> ! {
phase: Phase::CaptureOnFirstTransition,
},
2000.kHz(),
&clocks,
&mut rcc,
);

// Set up the LEDs. On the stm32f429i-disco they are connected to pin PG13 and PG14.
let gpiog = dp.GPIOG.split();
let gpiog = dp.GPIOG.split(&mut rcc);
let mut led3 = gpiog.pg13.into_push_pull_output();
let mut led4 = gpiog.pg14.into_push_pull_output();

let dc = gpioe.pe3.into_push_pull_output();
let mut ss = gpioe.pe4.into_push_pull_output();
let mut delay = Timer::syst(cp.SYST, &clocks).delay();
let mut delay = Timer::syst(cp.SYST, &rcc.clocks).delay();

ss.set_high();
delay.delay_ms(100);
Expand All @@ -142,7 +140,7 @@ fn main() -> ! {
disp.flush().unwrap();

// Create a 1ms periodic interrupt from TIM2
let mut timer = FTimer::new(dp.TIM2, &clocks).counter();
let mut timer = FTimer::new(dp.TIM2, &mut rcc).counter();
timer.start(1.secs()).unwrap();
timer.listen(Event::Update);

Expand Down Expand Up @@ -223,13 +221,14 @@ fn main() -> ! {
}
}

fn setup_clocks(rcc: Rcc) -> Clocks {
rcc.cfgr
.hclk(180.MHz())
.sysclk(180.MHz())
.pclk1(45.MHz())
.pclk2(90.MHz())
.freeze()
fn setup_clocks(rcc: pac::RCC) -> Rcc {
rcc.freeze(
Config::hsi()
.hclk(180.MHz())
.sysclk(180.MHz())
.pclk1(45.MHz())
.pclk2(90.MHz()),
)
}

#[interrupt]
Expand Down
9 changes: 4 additions & 5 deletions examples/blinky-timer-irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use panic_halt as _;

use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

use crate::hal::{
gpio::{self, Output, PushPull},
Expand Down Expand Up @@ -66,19 +66,18 @@ fn TIM2() {
fn main() -> ! {
let dp = Peripherals::take().unwrap();

let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(16.MHz()).pclk1(8.MHz()).freeze();
let mut rcc = dp.RCC.freeze(Config::hsi().sysclk(16.MHz()).pclk1(8.MHz()));

// Configure PA5 pin to blink LED
let gpioa = dp.GPIOA.split();
let gpioa = dp.GPIOA.split(&mut rcc);
let mut led = gpioa.pa5.into_push_pull_output();
led.set_high(); // Turn off

// Move the pin into our global storage
cortex_m::interrupt::free(|cs| *G_LED.borrow(cs).borrow_mut() = Some(led));

// Set up a timer expiring after 1s
let mut timer = dp.TIM2.counter(&clocks);
let mut timer = dp.TIM2.counter(&mut rcc);
timer.start(1.secs()).unwrap();

// Generate an interrupt when the timer expires
Expand Down
4 changes: 3 additions & 1 deletion examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use cortex_m_rt::entry;
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();

let gpioc = p.GPIOC.split();
let mut rcc = p.RCC.constrain();

let gpioc = p.GPIOC.split(&mut rcc);
let mut led = gpioc.pc13.into_push_pull_output();

loop {
Expand Down
11 changes: 5 additions & 6 deletions examples/can-send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ use bxcan::filter::Mask32;
use bxcan::{Fifo, Frame, StandardId};
use cortex_m_rt::entry;
use nb::block;
use stm32f4xx_hal::rcc::Config;
use stm32f4xx_hal::{pac, prelude::*};

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

let rcc = dp.RCC.constrain();

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

let gpiob = dp.GPIOB.split();
let gpiob = dp.GPIOB.split(&mut rcc);
let mut can1 = {
let rx = gpiob.pb8;
let tx = gpiob.pb9;

// let can = Can::new(dp.CAN1, (tx, rx));
// or
let can = dp.CAN1.can((tx, rx));
let can = dp.CAN1.can((tx, rx), &mut rcc);

bxcan::Can::builder(can)
// APB1 (PCLK1): 8MHz, Bit rate: 500kBit/s, Sample Point 87.5%
Expand All @@ -47,7 +46,7 @@ fn main() -> ! {
let tx = gpiob.pb13;
let rx = gpiob.pb12;

let can = dp.CAN2.can((tx, rx));
let can = dp.CAN2.can((tx, rx), &mut rcc);

let can2 = bxcan::Can::builder(can)
// APB1 (PCLK1): 8MHz, Bit rate: 500kBit/s, Sample Point 87.5%
Expand Down
13 changes: 6 additions & 7 deletions examples/delay-syst-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use panic_halt as _; // panic handler

use cortex_m_rt::entry;
use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

use crate::hal::{pac, prelude::*};

Expand All @@ -19,16 +19,15 @@ fn main() -> ! {
pac::Peripherals::take(),
cortex_m::peripheral::Peripherals::take(),
) {
// Set up the system clock. We want to run at 48MHz for this one.
let mut rcc = dp.RCC.freeze(Config::hsi().sysclk(48.MHz()));

// Set up the LED. On the Nucleo-446RE it's connected to pin PA5.
let gpioa = dp.GPIOA.split();
let gpioa = dp.GPIOA.split(&mut rcc);
let mut led = gpioa.pa5.into_push_pull_output();

// Set up the system clock. We want to run at 48MHz for this one.
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();

// Create a delay abstraction based on SysTick
let mut delay = cp.SYST.delay(&clocks);
let mut delay = cp.SYST.delay(&rcc.clocks);

loop {
// On for 1s, off for 1s.
Expand Down
13 changes: 6 additions & 7 deletions examples/delay-timer-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use panic_halt as _; // panic handler

use cortex_m_rt::entry;
use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

use crate::hal::{pac, prelude::*};

Expand All @@ -19,16 +19,15 @@ fn main() -> ! {
pac::Peripherals::take(),
cortex_m::peripheral::Peripherals::take(),
) {
// Set up the system clock. We want to run at 48MHz for this one.
let mut rcc = dp.RCC.freeze(Config::hse(25.MHz()).sysclk(48.MHz()));

// Set up the LED. On the Mini-F4 it's connected to pin PC13.
let gpioc = dp.GPIOC.split();
let gpioc = dp.GPIOC.split(&mut rcc);
let mut led = gpioc.pc13.into_push_pull_output();

// Set up the system clock. We want to run at 48MHz for this one.
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.use_hse(25.MHz()).sysclk(48.MHz()).freeze();

// Create a delay abstraction based on general-pupose 32-bit timer TIM5
let mut delay = dp.TIM5.delay_us(&clocks);
let mut delay = dp.TIM5.delay_us(&mut rcc);

loop {
// On for 1s, off for 3s.
Expand Down
24 changes: 11 additions & 13 deletions examples/display-touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use stm32f4xx_hal::{
gpio::Speed,
pac,
prelude::*,
rcc::Rcc,
rcc::Config,
};

use embedded_graphics_07::{
Expand Down Expand Up @@ -53,17 +53,15 @@ fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();

let rcc: Rcc = p.RCC.constrain();
let mut rcc = p.RCC.freeze(Config::hsi().sysclk(100.MHz()));
let mut delay = cp.SYST.delay(&rcc.clocks);

let clocks = rcc.cfgr.sysclk(100.MHz()).freeze();
let mut delay = cp.SYST.delay(&clocks);

let gpiob = p.GPIOB.split();
let gpioc = p.GPIOC.split();
let gpiod = p.GPIOD.split();
let gpioe = p.GPIOE.split();
let gpiof = p.GPIOF.split();
let gpiog = p.GPIOG.split();
let gpiob = p.GPIOB.split(&mut rcc);
let gpioc = p.GPIOC.split(&mut rcc);
let gpiod = p.GPIOD.split(&mut rcc);
let gpioe = p.GPIOE.split(&mut rcc);
let gpiof = p.GPIOF.split(&mut rcc);
let gpiog = p.GPIOG.split(&mut rcc);

// Pins connected to the LCD on the board
use stm32f4xx_hal::gpio::alt::fsmc as alt;
Expand Down Expand Up @@ -122,7 +120,7 @@ fn main() -> ! {
let read_timing = Timing::default().data(8).address_setup(8).bus_turnaround(0);

// Initialise FSMC memory provider
let (_fsmc, interface) = FsmcLcd::new(p.FSMC, lcd_pins, &read_timing, &write_timing);
let (_fsmc, interface) = FsmcLcd::new(p.FSMC, lcd_pins, &read_timing, &write_timing, &mut rcc);

// Pass display-interface instance ST7789 driver to setup a new display
let mut disp = ST7789::new(
Expand All @@ -148,7 +146,7 @@ fn main() -> ! {
// STM32F412 uses I2c1 type for i2c bus.
// The pins are mentioned in documentation -um2135-discovery-kit-with-stm32f412zg-mcu-stmicroelectronics
#[cfg(feature = "stm32f412")]
let mut i2c = { I2c::new(p.I2C1, (gpiob.pb6, gpiob.pb7), 400.kHz(), &clocks) };
let mut i2c = { I2c::new(p.I2C1, (gpiob.pb6, gpiob.pb7), 400.kHz(), &mut rcc) };

// STM32F413 uses FMPI2C1 type.
// The pins are mentioned in documentation -um2135-discovery-kit-with-stm32f413zh-mcu-stmicroelectronics
Expand Down
13 changes: 6 additions & 7 deletions examples/dwt-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ use crate::hal::{
};
use cortex_m_rt::entry;
use panic_halt as _;
use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

#[entry]
fn main() -> ! {
if let (Some(dp), Some(cp)) = (
pac::Peripherals::take(),
cortex_m::peripheral::Peripherals::take(),
) {
// Set up the system clock. We want to run at 48MHz for this one.
let mut rcc = dp.RCC.freeze(Config::hsi().sysclk(48.MHz()));

// Set up the LEDs. On the STM32F429I-DISC[O1] they are connected to pin PG13/14.
let gpiog = dp.GPIOG.split();
let gpiog = dp.GPIOG.split(&mut rcc);
let mut led1 = gpiog.pg13.into_push_pull_output();
let mut led2 = gpiog.pg14.into_push_pull_output();

// Set up the system clock. We want to run at 48MHz for this one.
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();

// Create a delay abstraction based on DWT cycle counter
let dwt = cp.DWT.constrain(cp.DCB, &clocks);
let dwt = cp.DWT.constrain(cp.DCB, &rcc.clocks);
let mut delay = dwt.delay();

// Create a stopwatch for maximum 9 laps
Expand Down
8 changes: 3 additions & 5 deletions examples/dynamic-gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();

// Take ownership over raw device and convert it into the corresponding HAL struct
let rcc = dp.RCC.constrain();

// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
// `clocks`
let clocks = rcc.cfgr.freeze();
let mut rcc = dp.RCC.constrain();

// Acquire the GPIOC peripheral
let gpioc = dp.GPIOC.split();
let gpioc = dp.GPIOC.split(&mut rcc);

let mut pin = gpioc.pc13.into_dynamic();
// Configure the syst timer to trigger an update every second
let mut timer = Timer::syst(cp.SYST, &clocks).counter_us();
let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_us();
timer.start(1.secs()).unwrap();

// Wait for the timer to trigger an update and change the state of the LED
Expand Down
24 changes: 12 additions & 12 deletions examples/f413disco-lcd-ferris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use panic_halt as _;
use rtt_target::{self, rtt_init_print, ChannelMode};

use stm32f4xx_hal as hal;
use stm32f4xx_hal::{self as hal, rcc::Config};

use crate::hal::{
fsmc_lcd::{DataPins16, FsmcLcd, LcdPins, Timing},
Expand Down Expand Up @@ -697,16 +697,15 @@ fn main() -> ! {
rtt_init_print!(ChannelMode::NoBlockTrim);

if let (Some(p), Some(cp)) = (Peripherals::take(), CorePeripherals::take()) {
// Split all the GPIO blocks we need
let gpiob = p.GPIOB.split();
let gpiod = p.GPIOD.split();
let gpioe = p.GPIOE.split();
let gpiof = p.GPIOF.split();
let gpiog = p.GPIOG.split();

// Configure and lock the clocks at maximum warp
let rcc = p.RCC.constrain();
let clocks = rcc.cfgr.sysclk(100.MHz()).freeze();
let mut rcc = p.RCC.freeze(Config::hsi().sysclk(100.MHz()));

// Split all the GPIO blocks we need
let gpiob = p.GPIOB.split(&mut rcc);
let gpiod = p.GPIOD.split(&mut rcc);
let gpioe = p.GPIOE.split(&mut rcc);
let gpiof = p.GPIOF.split(&mut rcc);
let gpiog = p.GPIOG.split(&mut rcc);

// Define the pins we need for our 16bit parallel bus
use stm32f4xx_hal::gpio::alt::fsmc as alt;
Expand All @@ -729,14 +728,15 @@ fn main() -> ! {
let mut _te = gpiob.pb14.into_floating_input();

// Get delay provider
let mut delay = cp.SYST.delay(&clocks);
let mut delay = cp.SYST.delay(&rcc.clocks);

// Set up timing
let write_timing = Timing::default().data(3).address_setup(3).bus_turnaround(0);
let read_timing = Timing::default().data(8).address_setup(8).bus_turnaround(0);

// Initialise FSMC memory provider
let (_fsmc, interface) = FsmcLcd::new(p.FSMC, lcd_pins, &read_timing, &write_timing);
let (_fsmc, interface) =
FsmcLcd::new(p.FSMC, lcd_pins, &read_timing, &write_timing, &mut rcc);

// Pass display-interface instance ST7789 driver to setup a new display
let mut disp = ST7789::new(
Expand Down
Loading