Skip to content

Commit 7a12c20

Browse files
authored
Merge pull request #220 from Sh3Rm4n/memory_x
Improve build.rs and some more.
2 parents 321a503 + f03283b commit 7a12c20

File tree

12 files changed

+134
-68
lines changed

12 files changed

+134
-68
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
- uses: actions/checkout@v2
6565
- uses: actions-rs/toolchain@v1
6666
with:
67-
toolchain: 1.48.0
67+
toolchain: 1.50.0
6868
target: thumbv7em-none-eabihf
6969
override: true
7070
profile: minimal

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3131

3232
### Breaking Changes
3333

34+
- The MSVR was bumped to 1.50 ([#220])
3435
- Replace custom time based units with types defined in the [embedded-time][]
3536
crate ([#192])
3637
- The `rcc` public API now expects time based units in `Megahertz`.
@@ -62,6 +63,9 @@ let clocks = rcc
6263
in alternate function mode ([#189])
6364
- GPIO internal resistor configuration is no longer encoded into pin typestate
6465
in input mode ([#189])
66+
- Remove `stm32` module. Use `use stm32f3xx_hal::pac` instead.
67+
This module was a deprecated in [v0.5.0][] and is now subject for
68+
removal. ([#220])
6569

6670
## [v0.6.1] - 2020-12-10
6771

@@ -316,6 +320,7 @@ let clocks = rcc
316320
[defmt]: https://github.com/knurling-rs/defmt
317321
[filter]: https://defmt.ferrous-systems.com/filtering.html
318322

323+
[#220]: https://github.com/stm32-rs/stm32f3xx-hal/pull/220
319324
[#217]: https://github.com/stm32-rs/stm32f3xx-hal/pull/217
320325
[#216]: https://github.com/stm32-rs/stm32f3xx-hal/pull/216
321326
[#211]: https://github.com/stm32-rs/stm32f3xx-hal/pull/211

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ panic-probe = "0.2"
6161
defmt-rtt = "0.2"
6262
defmt-test = "0.2"
6363

64+
[build-dependencies]
65+
cargo_metadata = "0.13.1"
66+
slice-group-by = "0.2.6"
67+
6468
[features]
6569
default = ["unproven"]
6670
unproven = ["embedded-hal/unproven"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ See the [examples folder](examples) for more example programs.
154154

155155
## Minimum Supported Rust Version (MSRV)
156156

157-
This crate is guaranteed to compile on stable Rust 1.48.0 and up. It *might*
157+
This crate is guaranteed to compile on stable Rust 1.50.0 and up. It *might*
158158
compile with older versions but that may change in any new patch release.
159159

160160
<!-- This should not prevent anyone to use newer features. -->

build.rs

Lines changed: 74 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
use std::{env, fs::File, io::prelude::*, path::PathBuf};
1+
use std::collections::hash_set::HashSet;
2+
use std::env;
3+
use std::fs::File;
4+
use std::io::prelude::*;
5+
use std::path::PathBuf;
6+
7+
use cargo_metadata::MetadataCommand;
8+
// TODO(Sh3Rm4n - 2021-04-28):
9+
// Remove when [feature="slice_group_by"] is stable.
10+
// See with https://github.com/rust-lang/rust/issues/80552.
11+
use slice_group_by::GroupBy;
212

313
fn main() {
414
check_device_feature();
@@ -10,40 +20,75 @@ fn main() {
1020

1121
/// Check device feature selection
1222
fn check_device_feature() {
13-
if !cfg!(feature = "device-selected") {
14-
if cfg!(feature = "direct-call-deprecated") {
15-
eprintln!(
16-
"The feature you selected is deprecated, because it was split up into sub-devices.
23+
// Check if the device is deprecated
24+
if !cfg!(feature = "device-selected") && cfg!(feature = "direct-call-deprecated") {
25+
eprintln!(
26+
"The (device-)feature you selected is deprecated, because it was split up into sub-devices.\n\
27+
\n\
28+
Example: The STM32F3Discovery board has a STM32F303VCT6 chip.\n\
29+
You probably used to use `stm32f303` but now functionalities for the sub-device were added.\n\
30+
In this case replace it with `stm32f303xc` to make your code build again.\n\
31+
\n\
32+
For more information, see \
33+
\x1b]8;;https://github.com/stm32-rs/stm32f3xx-hal#selecting-the-right-chip\x1b\\README \
34+
-> Selecting the right chip\x1b]8;;\x1b\\."
35+
);
36+
std::process::exit(1);
37+
}
1738

18-
Example: The STM32F3Discovery board has a STM32F303VCT6 chip.
19-
You probably used to use `stm32f303` but now functionalities for the sub-device were added.
20-
In this case replace it with `stm32f303xc` to make your code build again.
39+
// get all device variants from the metadata
40+
let metadata = MetadataCommand::new().exec().unwrap();
41+
let device_variants: HashSet<String> = metadata
42+
.root_package()
43+
.unwrap()
44+
.features
45+
.iter()
46+
.filter_map(|(feature, dependent_features)| {
47+
dependent_features
48+
.iter()
49+
.any(|dependent_feature| dependent_feature == "device-selected")
50+
.then(|| feature.clone())
51+
})
52+
.collect();
2153

22-
For more information, see \x1b]8;;https://github.com/stm32-rs/stm32f3xx-hal#selecting-the-right-chip\x1b\\README -> Selecting the right chip\x1b]8;;\x1b\\."
23-
);
24-
} else {
25-
eprintln!(
26-
"This crate requires you to specify your target chip as a feature.
54+
// get all selected features via env variables
55+
let selected_features: HashSet<String> = env::vars()
56+
.filter_map(|(key, _)| {
57+
key.split("CARGO_FEATURE_")
58+
.nth(1)
59+
.map(|s| s.to_owned().to_ascii_lowercase())
60+
})
61+
.collect();
2762

28-
Please select one of the following (`x` denotes any character in [a-z]):
29-
30-
stm32f301x6 stm32f301x8
31-
stm32f318x8
32-
stm32f302x6 stm32f302x8 stm32f302xb stm32f302xc stm32f302xd stm32f302xe
33-
stm32f303x6 stm32f303x8 stm32f303xb stm32f303xc stm32f303xd stm32f303xe
34-
stm32f328x8
35-
stm32f358xc
36-
stm32f398xe
37-
stm32f373x8 stm32f373xb stm32f373xc
38-
stm32f378xc
39-
stm32f334x4 stm32f334x6 stm32f334x8
63+
// check if exactly one device was selected
64+
if device_variants.intersection(&selected_features).count() != 1 {
65+
eprintln!(
66+
"This crate requires you to specify your target chip as a feature.\n\
67+
\n\
68+
Please select **one** of the following (`x` denotes any character in [a-z]):\n"
69+
);
4070

41-
Example: The STM32F3Discovery board has a STM32F303VCT6 chip.
42-
So you need to specify stm32f303xc in your Cargo.toml (note that VC → xc).
71+
// group device variants by type
72+
let mut device_variants: Vec<String> = device_variants.into_iter().collect();
73+
device_variants.sort_unstable();
74+
let device_variants = device_variants.linear_group_by(|a, b| a[..9] == b[..9]);
4375

44-
For more information, see \x1b]8;;https://github.com/stm32-rs/stm32f3xx-hal#selecting-the-right-chip\x1b\\README -> Selecting the right chip\x1b]8;;\x1b\\."
45-
);
76+
// pretty print all avaliable devices
77+
for line in device_variants {
78+
for device in line {
79+
eprint!("{} ", device);
80+
}
81+
eprintln!();
4682
}
83+
84+
eprintln!(
85+
"\nExample: The STM32F3Discovery board has a STM32F303VCT6 chip.\n\
86+
So you need to specify stm32f303xc in your Cargo.toml (note that VC → xc).\n\
87+
\n\
88+
For more information, see \
89+
\x1b]8;;https://github.com/stm32-rs/stm32f3xx-hal#selecting-the-right-chip\x1b\\README \
90+
-> Selecting the right chip\x1b]8;;\x1b\\."
91+
);
4792
std::process::exit(1);
4893
}
4994
}

examples/can.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use stm32f3xx_hal as hal;
99
use cortex_m::asm;
1010
use cortex_m_rt::entry;
1111

12+
use hal::pac;
1213
use hal::prelude::*;
13-
use hal::stm32;
1414
use hal::watchdog::IndependentWatchDog;
1515

1616
use hal::can::{Can, CanFilter, CanFrame, CanId, Filter, Frame, Receiver, Transmitter};
@@ -22,7 +22,7 @@ const ID: u16 = 0b100;
2222

2323
#[entry]
2424
fn main() -> ! {
25-
let dp = stm32::Peripherals::take().unwrap();
25+
let dp = pac::Peripherals::take().unwrap();
2626

2727
let mut flash = dp.FLASH.constrain();
2828
let mut rcc = dp.RCC.constrain();

src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//! API for the ADC (Analog to Digital Converter)
1+
//! Analog to Digital Converter. (Requires feature `stm32f303x[bcde]`)
22
//!
33
//! # Examples
44
//!
5-
//! Check out [examles/adc.rs].
5+
//! Check out [examles/adc.rs][].
66
//!
77
//! It can be built for the STM32F3Discovery running
88
//! `cargo build --example adc --features=stm32f303xc`

src/can.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Controller Area Network
1+
//! Controller Area Network (Requires feature `can`)
22
//!
33
//! CAN is currently not enabled by default, and
44
//! can be enabled by the `can` feature.
@@ -15,18 +15,20 @@ pub use embedded_hal_can::{self, Filter, Frame, Id, Receiver, Transmitter};
1515

1616
use crate::gpio::gpioa;
1717
use crate::gpio::{PushPull, AF9};
18+
use crate::pac;
1819
use crate::rcc::APB1;
19-
use crate::stm32;
2020
use nb::{self, Error};
2121

2222
use core::sync::atomic::{AtomicU8, Ordering};
23-
pub use stm32::can::btr::LBKM_A;
23+
pub use pac::can::btr::LBKM_A;
2424

2525
const EXID_MASK: u32 = 0b1_1111_1111_1100_0000_0000_0000_0000;
2626
const MAX_EXTENDED_ID: u32 = 0x1FFF_FFFF;
2727

28-
/// Options the CAN bus. This is primarily used to set bus timings, but also controls options like enabling loopback or silent mode for debugging.
29-
/// See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
28+
/// Options for the CAN bus.
29+
///
30+
/// This is primarily used to set bus timings, but also controls options like enabling loopback or silent mode for debugging.
31+
/// See <http://www.bittiming.can-wiki.info/#bxCAN> for generating the timing parameters for different baud rates and clocks.
3032
///
3133
/// Use `CanOpts::default()` to get 250kbps at 32mhz system clock
3234
pub struct CanOpts {
@@ -43,25 +45,25 @@ impl CanOpts {
4345
CanOpts::default()
4446
}
4547

46-
/// Set the Baud Rate Prescaler. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
48+
/// Set the Baud Rate Prescaler. See <http://www.bittiming.can-wiki.info/#bxCAN> for generating the timing parameters for different baud rates and clocks.
4749
pub fn brp(mut self, brp: u16) -> Self {
4850
self.brp = brp;
4951
self
5052
}
5153

52-
/// Set the Resynchronisation Jump Width. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
54+
/// Set the Resynchronisation Jump Width. See <http://www.bittiming.can-wiki.info/#bxCAN> for generating the timing parameters for different baud rates and clocks.
5355
pub fn sjw(mut self, sjw: u8) -> Self {
5456
self.sjw = sjw;
5557
self
5658
}
5759

58-
/// Set Time Segment One. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
60+
/// Set Time Segment One. See <http://www.bittiming.can-wiki.info/#bxCAN> for generating the timing parameters for different baud rates and clocks.
5961
pub fn ts1(mut self, ts1: u8) -> Self {
6062
self.ts1 = ts1;
6163
self
6264
}
6365

64-
/// Set Time Segment Two. See http://www.bittiming.can-wiki.info/#bxCAN for generating the timing parameters for different baud rates and clocks.
66+
/// Set Time Segment Two. See <http://www.bittiming.can-wiki.info/#bxCAN> for generating the timing parameters for different baud rates and clocks.
6567
pub fn ts2(mut self, ts2: u8) -> Self {
6668
self.ts2 = ts2;
6769
self
@@ -147,7 +149,7 @@ static FILTER_INDEX: AtomicU8 = AtomicU8::new(0);
147149

148150
/// Controll Area Network (CAN) Peripheral
149151
pub struct Can {
150-
can: stm32::CAN,
152+
can: pac::CAN,
151153
_rx: gpioa::PA11<AF9<PushPull>>,
152154
_tx: gpioa::PA12<AF9<PushPull>>,
153155
}
@@ -160,7 +162,7 @@ pub struct CanFifo {
160162

161163
/// A CAN transmitter which is used to send messages to the CAN network.
162164
pub struct CanTransmitter {
163-
_can: stm32::CAN,
165+
_can: pac::CAN,
164166
_rx: gpioa::PA11<AF9<PushPull>>,
165167
_tx: gpioa::PA12<AF9<PushPull>>,
166168
}
@@ -316,7 +318,7 @@ impl CanFilterData {
316318
impl Can {
317319
/// Initialize the CAN peripheral using the options specified by `opts`.
318320
pub fn new_with_opts(
319-
can: stm32::CAN,
321+
can: pac::CAN,
320322
rx: gpioa::PA11<AF9<PushPull>>,
321323
tx: gpioa::PA12<AF9<PushPull>>,
322324
apb1: &mut APB1,
@@ -362,7 +364,7 @@ impl Can {
362364
}
363365
/// Initialize the CAN Peripheral using default options from `CanOpts::default()`
364366
pub fn new(
365-
can: stm32::CAN,
367+
can: pac::CAN,
366368
rx: gpioa::PA11<AF9<PushPull>>,
367369
tx: gpioa::PA12<AF9<PushPull>>,
368370
apb1: &mut APB1,
@@ -399,7 +401,7 @@ impl Can {
399401
pub fn free(
400402
self,
401403
) -> (
402-
stm32::CAN,
404+
pac::CAN,
403405
gpioa::PA11<AF9<PushPull>>,
404406
gpioa::PA12<AF9<PushPull>>,
405407
) {
@@ -426,7 +428,7 @@ impl embedded_hal_can::Transmitter for CanTransmitter {
426428
&mut self,
427429
frame: &Self::Frame,
428430
) -> Result<Option<Self::Frame>, nb::Error<Self::Error>> {
429-
let can = unsafe { &*stm32::CAN::ptr() };
431+
let can = unsafe { &*pac::CAN::ptr() };
430432

431433
for tx_idx in 0..3 {
432434
let free = match tx_idx {
@@ -489,7 +491,7 @@ impl embedded_hal_can::Transmitter for CanTransmitter {
489491

490492
impl Receiver for CanFifo {
491493
fn receive(&mut self) -> Result<Self::Frame, Error<Self::Error>> {
492-
let can = unsafe { &*stm32::CAN::ptr() };
494+
let can = unsafe { &*pac::CAN::ptr() };
493495

494496
let rx = &can.rx[self.idx];
495497
if can.rfr[self.idx].read().fmp().bits() > 0 {
@@ -541,7 +543,7 @@ impl Receiver for CanFifo {
541543
/// Sets a filter in the next open filter register.
542544
fn set_filter(&mut self, filter: Self::Filter) {
543545
cortex_m::interrupt::free(|_cs| {
544-
let can = unsafe { &*stm32::CAN::ptr() };
546+
let can = unsafe { &*pac::CAN::ptr() };
545547

546548
// Filter init mode
547549
can.fmr.modify(|_, w| w.finit().set_bit());

src/dma.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Direct memory access (DMA) controller
1+
//! Direct memory access (DMA) controller. (Requires feature `stm32f303*` or `stm32f302*`)
22
//!
3-
//! Currently DMA is only supported for STM32F303 MCUs.
3+
//! Currently DMA is only supported for STM32F303 or STM32F302 MCUs.
44
//!
55
//! An example how to use DMA for serial, can be found at [examples/serial_dma.rs]
66
//!

0 commit comments

Comments
 (0)