8000 Use stm32f3xx-hal instead of stm32f30x_hal and upgrade all dependencies by tkeksa · Pull Request #109 · japaric/f3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use stm32f3xx-hal instead of stm32f30x_hal and upgrade all dependencies #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ keywords = ["arm", "cortex-m", "stm32"]
license = "MIT OR Apache-2.0"
name = "f3"
repository = "https://github.com/japaric/f3"
version = "0.6.1"
version = "0.6.2"

[dependencies]
embedded-hal = "0.2.3"
l3gd20 = "0.2.0"
lsm303dlhc = "0.2.0"
stm32f30x-hal = "0.2.0"

[dependencies.stm32f3xx-hal]
version = "0.4.0"
features = ["stm32f303xc"]

[dev-dependencies]
aligned = "0.2.0"
cortex-m = "0.5.0"
cortex-m-rt = "0.6.5"
cortex-m-semihosting = "0.3.2"
aligned = "0.3.2"
cortex-m = "0.6.1"
cortex-m-rt = "0.6.11"
cortex-m-semihosting = "0.3.5"
madgwick = "0.1.1"
panic-semihosting = "0.5.1"
panic-semihosting = "0.5.3"

[dev-dependencies.byteorder]
default-features = false
version = "1.2.1"
version = "1.3.2"

[dev-dependencies.cast]
default-features = false
version = "0.2.2"
version = "0.2.3"

[dev-dependencies.cobs]
default-features = false
version = "0.1.3"
version = "0.1.4"

[dev-dependencies.nb]
version = "0.1.1"

[dev-dependencies.stm32f30x-hal]
version = "0.2.0"
features = ["rt"]

[features]
rt = ["stm32f30x-hal/rt"]
rt = ["stm32f3xx-hal/rt"]

[profile.release]
codegen-units = 1
Expand Down
4 changes: 2 additions & 2 deletions examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ extern crate panic_semihosting;

use cortex_m_rt::entry;
use f3::{
hal::{delay::Delay, prelude::*, stm32f30x},
hal::{delay::Delay, prelude::*, stm32},
led::Led,
};

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

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
Expand Down
10 changes: 6 additions & 4 deletions examples/l3gd20.rs
< 8000 template class="js-file-alert-template">
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ extern crate panic_semihosting;

use cortex_m::asm;
use cortex_m_rt::entry;
use embedded_hal::digital::v1_compat::OldOutputPin;
use embedded_hal::digital::v2::OutputPin;
use f3::{
hal::{prelude::*, spi::Spi, stm32f30x},
hal::{prelude::*, spi::Spi, stm32},
l3gd20, L3gd20,
};

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

let mut flash = p.FLASH.constrain();
let mut rcc = p.RCC.constrain();
Expand All @@ -30,7 +32,7 @@ fn main() -> ! {
let mut nss = gpioe
.pe3
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
nss.set_high();
nss.set_high().unwrap();

// The `L3gd20` abstraction exposed by the `f3` crate requires a specific pin configuration to
// be used and won't accept any configuration other than the one used here. Trying to use a
Expand All @@ -48,7 +50,7 @@ fn main() -> ! {
&mut rcc.apb2,
);

let mut l3gd20 = L3gd20::new(spi, nss).unwrap();
let mut l3gd20 = L3gd20::new(spi, OldOutputPin::from(nss)).unwrap();

// sanity check: the WHO_AM_I register always contains this value
assert_eq!(l3gd20.who_am_i().unwrap(), 0xD4);
Expand Down
4 changes: 2 additions & 2 deletions examples/leds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ extern crate panic_semihosting;

use cortex_m_rt::entry;
use f3::{
hal::{prelude::*, stm32f30x},
hal::{prelude::*, stm32},
led::Leds,
};

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

let mut rcc = p.RCC.constrain();
let gpioe = p.GPIOE.split(&mut rcc.ahb);
Expand Down
17 changes: 10 additions & 7 deletions examples/log-sensors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@

extern crate panic_semihosting;

use core::ops::DerefMut;
use core::ptr;

use aligned::Aligned;
use aligned::{Aligned, A4};
use byteorder::{ByteOrder, LE};
use cortex_m::{asm, itm};
use cortex_m_rt::entry;
use embedded_hal::digital::v1_compat::OldOutputPin;
use embedded_hal::digital::v2::OutputPin;
use f3::{
hal::{i2c::I2c, prelude::*, spi::Spi, stm32f30x, timer::Timer},
hal::{i2c::I2c, prelude::*, spi::Spi, stm32, timer::Timer},
l3gd20::{self, Odr},
lsm303dlhc::{AccelOdr, MagOdr},
L3gd20, Lsm303dlhc,
Expand All @@ -57,7 +60,7 @@ const NSAMPLES: u32 = 32 * FREQUENCY; // = 32 seconds
#[entry]
fn main() -> ! {
let mut cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f30x::Peripherals::take().unwrap();
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
Expand Down Expand Up @@ -120,7 +123,7 @@ fn main() -> ! {
let mut nss = gpioe
.pe3
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
nss.set_high();
nss.set_high().unwrap();
let sck = gpioa.pa5.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
let miso = gpioa.pa6.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
let mosi = gpioa.pa7.into_af5(&mut gpioa.moder, &mut gpioa.afrl);
Expand All @@ -135,7 +138,7 @@ fn main() -> ! {
);

// L3GD20
let mut l3gd20 = L3gd20::new(spi, nss).unwrap();
let mut l3gd20 = L3gd20::new(spi, OldOutputPin::from(nss)).unwrap();
l3gd20.set_odr(Odr::Hz380).unwrap();

// TIMER
Expand All @@ -145,7 +148,7 @@ fn main() -> ! {
itm::write_all(&mut cp.ITM.stim[0], &[0]);

// Capture N samples
let mut tx_buf: Aligned<u32, [u8; 20]> = Aligned([0; 20]);
let mut tx_buf: Aligned<A4, [u8; 20]> = Aligned([0; 20]);
for _ in 0..NSAMPLES {
block!(timer.wait()).unwrap();

Expand Down Expand Up @@ -179,7 +182,7 @@ fn main() -> ! {
LE::write_i16(&mut buf[start..start + 2], g.z);

// Log data
cobs::encode(&buf, &mut tx_buf);
cobs::encode(&buf, tx_buf.deref_mut());

itm::write_aligned(&mut cp.ITM.stim[0], &tx_buf);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/lsm303dlhc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ extern crate panic_semihosting;
use cortex_m::asm;
use cortex_m_rt::entry;
use f3::{
hal::{i2c::I2c, prelude::*, stm32f30x},
hal::{i2c::I2c, prelude::*, stm32},
Lsm303dlhc,
};

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

let mut flash = p.FLASH.constrain();
let mut rcc = p.RCC.constrain();
Expand Down
21 changes: 12 additions & 9 deletions examples/madgwick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@

extern crate panic_semihosting;

use core::ops::DerefMut;
use core::{f32::consts::PI, ptr};

use aligned::Aligned;
use aligned::{Aligned, A4};
use byteorder::{ByteOrder, LE};
use cast::{f32, i32};
use cortex_m::itm;
use cortex_m_rt::entry;
use embedded_hal::digital::v1_compat::OldOutputPin;
use embedded_hal::digital::v2::OutputPin;
use f3::{
hal::{i2c::I2c, prelude::*, spi::Spi, stm32f30x, timer::Timer},
hal::{i2c::I2c, prelude::*, spi::Spi, stm32, timer::Timer},
l3gd20::{self, Odr},
lsm303dlhc::{AccelOdr, MagOdr},
L3gd20, Lsm303dlhc,
Expand Down Expand Up @@ -79,7 +82,7 @@ const BETA: f32 = 1e-3;
#[entry]
fn main() -> ! {
let mut cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f30x::Peripherals::take().unwrap();
let dp = stm32::Peripherals::take().unwrap();

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
Expand Down Expand Up @@ -130,7 +133,7 @@ fn main() -> ! {
let mut nss = gpioe
.pe3
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
nss.set_high();
nss.set_high().unwrap();
let mut led = gpioe
.pe9
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper);
Expand All @@ -148,7 +151,7 @@ fn main() -> ! {
&mut rcc.apb2,
);

let mut l3gd20 = L3gd20::new(spi, nss).unwrap();
let mut l3gd20 = L3gd20::new(spi, OldOutputPin::from(nss)).unwrap();

l3gd20.set_odr(Odr::Hz380).unwrap();

Expand Down Expand Up @@ -182,12 +185,12 @@ fn main() -> ! {
let ar_bias_z = (ar_bias_z / NSAMPLES) as i16;

// Turn on the LED after calibrating the gyroscope
led.set_high();
led.set_high().unwrap();

let mut marg = Marg::new(BETA, 1. / f32(SAMPLE_FREQ));
let mut timer = Timer::tim2(timer.free(), SAMPLE_FREQ.hz(), clocks, &mut rcc.apb1);
let mut timer = Timer::tim2(timer.release(), SAMPLE_FREQ.hz(), clocks, &mut rcc.apb1);

let mut tx_buf: Aligned<u32, [u8; 18]> = Aligned([0; 18]);
let mut tx_buf: Aligned<A4, [u8; 18]> = Aligned([0; 18]);
loop {
block!(timer.wait()).unwrap();

Expand Down Expand Up @@ -241,7 +244,7 @@ fn main() -> ! {
// start += 4;

// Log data
cobs::encode(&buf, &mut tx_buf.array);
cobs::encode(&buf, tx_buf.deref_mut());

itm::write_aligned(&mut cp.ITM.stim[0], &tx_buf);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/roulette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ extern crate panic_semihosting;

use cortex_m_rt::entry;
use f3::{
hal::{delay::Delay, prelude::*, stm32f30x},
hal::{delay::Delay, prelude::*, stm32},
led::Leds,
};

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

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
Expand Down
4 changes: 2 additions & 2 delet CEB7 ions examples/serial-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
extern crate panic_semihosting;

use cortex_m_rt::entry;
use f3::hal::{prelude::*, serial::Serial, stm32f30x};
use f3::hal::{prelude::*, serial::Serial, stm32};
use nb::block;

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

let mut flash = p.FLASH.constrain();
let mut rcc = p.RCC.constrain();
Expand Down
4 changes: 2 additions & 2 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ extern crate panic_semihosting;

use cortex_m::asm;
use cortex_m_rt::entry;
use f3::hal::{prelude::*, serial::Serial, stm32f30x};
use f3::hal::{prelude::*, serial::Serial, stm32};
use nb::block;

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

let mut flash = p.FLASH.constrain();
let mut rcc = p.RCC.constrain();
Expand Down
9 changes: 1 addition & 8 deletions openocd.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Sample OpenOCD configuration for the STM32F3DISCOVERY development board

# Depending on the hardware revision you got you'll have to pick ONE of these
# interfaces. At any time only one interface should be commented out.

# Revision C (newer revision)
source [find interface/stlink-v2-1.cfg]

# Revision A and B (older revisions)
# source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]

source [find target/stm32f3x.cfg]
6 changes: 3 additions & 3 deletions src/led.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use core::ops;

use hal::prelude::*;
use hal::hal::digital::v2::OutputPin;

use hal::gpio::gpioe::{self, PEx, PE10, PE11, PE12, PE13, PE14, PE15, PE8, PE9};
use hal::gpio::{Output, PushPull};
Expand Down Expand Up @@ -165,11 +165,11 @@ ctor!(LD3, LD4, LD5, LD6, LD7, LD8, LD9, LD10);
impl Led {
/// Turns the LED off
pub fn off(&mut self) {
self.pex.set_low()
self.pex.set_low().unwrap()
}

/// Turns the LED on
pub fn on(&mut self) {
self.pex.set_high()
self.pex.set_high().unwrap()
}
}
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@
//! [examples]: examples/index.html

#![deny(missing_docs)]
#![deny(warnings)]
//#![deny(warnings)]
#![no_std]

pub extern crate l3gd20;
pub extern crate lsm303dlhc;
pub extern crate stm32f30x_hal as hal;
pub extern crate stm32f3xx_hal as hal;

use embedded_hal::digital::v1_compat::OldOutputPin;
use hal::gpio::gpioa::{PA5, PA6, PA7};
use hal::gpio::gpiob::{PB6, PB7};
use hal::gpio::gpioe::PE3;
use hal::gpio::{Output, PushPull, AF4, AF5};
use hal::i2c::I2c;
use hal::spi::Spi;
use hal::stm32f30x::{I2C1, SPI1};
use hal::stm32::{I2C1, SPI1};

pub mod examples;
pub mod led;

/// On board L3GD20 connected to the SPI1 bus via the pins PA5, PA6, PA7 and PE3
pub type L3gd20 = l3gd20::L3gd20<Spi<SPI1, (PA5<AF5>, PA6<AF5>, PA7<AF5>)>, PE3<Output<PushPull>>>;
pub type L3gd20 =
l3gd20::L3gd20<Spi<SPI1, (PA5<AF5>, PA6<AF5>, PA7<AF5>)>, OldOutputPin<PE3<Output<PushPull>>>>;

/// On board LSM303DLHC connected to the I2C1 bus via the PB6 and PB7 pins
pub type Lsm303dlhc = lsm303dlhc::Lsm303dlhc<I2c<I2C1, (PB6<AF4>, PB7<AF4>)>>;
Loading
0