stm32f1xx_hal/
lib.rs

1//! # HAL for the STM32F1 family of microcontrollers
2//!
3//! This is an implementation of the [`embedded-hal`] traits for the STM32F1 family of
4//! microcontrollers.
5//!
6//! [`embedded-hal`]: https://crates.io/crates/embedded-hal
7//!
8//! # Usage
9//!
10//! ## Building an application (binary crate)
11//!
12//! A detailed usage guide can be found in the [README]
13//!
14//! supported microcontrollers are:
15//!
16//! - stm32f103
17//! - stm32f101
18//! - stm32f100
19//! - stm32f105
20//! - stm32f107
21//!
22//! ## Usage
23//!
24//! This crate supports multiple microcontrollers in the
25//! stm32f1 family. Which specific microcontroller you want to build for has to be
26//! specified with a feature, for example `stm32f103`.
27//!
28//! If no microcontroller is specified, the crate will not compile.
29//!
30//! The currently supported variants are
31//!
32//! - `stm32f100`
33//! - `stm32f101`
34//! - `stm32f103`
35//! - `stm32f105`
36//! - `stm32f107`
37//!
38//! You may also need to specify the density of the device with `medium`, `high` or `xl`
39//! to enable certain peripherals. Generally the density can be determined by the 2nd character
40//! after the number in the device name (i.e. For STM32F103C6U, the 6 indicates a low-density
41//! device) but check the datasheet or CubeMX to be sure.
42//! * 4, 6 => low density, no feature required
43//! * 8, B => `medium` feature
44//! * C, D, E => `high` feature
45//! * F, G => `xl` feature
46//!
47//! ## Commonly used setup
48//! Almost all peripherals require references to some registers in `RCC` and `AFIO`. The following
49//! code shows how to set up those registers
50//!
51//! ```rust
52//! // Get access to the device specific peripherals from the peripheral access crate
53//! let dp = pac::Peripherals::take().unwrap();
54//!
55//! // Take ownership over the raw flash and rcc devices and convert them into the corresponding
56//! // HAL structs
57//! let mut flash = dp.FLASH.constrain();
58//! let mut rcc = dp.RCC.constrain();
59//!
60//! // Freeze the configuration of all the clocks in the system and store the frozen frequencies in
61//! // `clocks`
62//! let clocks = rcc.cfgr.freeze(&mut flash.acr);
63//!
64//! // Prepare the alternate function I/O registers
65//! let mut afio = dp.AFIO.constrain();
66//! ```
67//!
68//! ## Usage examples
69//!
70//! See the [examples] folder.
71//!
72//! Most of the examples require the following additional dependencies
73//! ```toml
74//! [dependencies]
75//! embedded-hal = "0.2.3"
76//! nb = "0.1.2"
77//! cortex-m = "0.6.2"
78//! cortex-m-rt = "0.6.11"
79//! # Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
80//! panic-halt = "0.2.0"
81//! ```
82//!
83//! [examples]: https://github.com/stm32-rs/stm32f1xx-hal/tree/v0.7.0/examples
84//! [README]: https://github.com/stm32-rs/stm32f1xx-hal/tree/v0.7.0
85
86#![no_std]
87#![deny(rustdoc::broken_intra_doc_links)]
88
89// If no target specified, print error message.
90#[cfg(not(any(
91    feature = "stm32f100",
92    feature = "stm32f101",
93    feature = "stm32f103",
94    feature = "stm32f105",
95    feature = "stm32f107",
96)))]
97compile_error!("Target not found. A `--features <target-name>` is required.");
98
99// If any two or more targets are specified, print error message.
100#[cfg(any(
101    all(feature = "stm32f100", feature = "stm32f101"),
102    all(feature = "stm32f100", feature = "stm32f103"),
103    all(feature = "stm32f100", feature = "stm32f105"),
104    all(feature = "stm32f100", feature = "stm32f107"),
105    all(feature = "stm32f101", feature = "stm32f103"),
106    all(feature = "stm32f101", feature = "stm32f105"),
107    all(feature = "stm32f101", feature = "stm32f107"),
108    all(feature = "stm32f103", feature = "stm32f105"),
109    all(feature = "stm32f103", feature = "stm32f107"),
110    all(feature = "stm32f105", feature = "stm32f107"),
111))]
112compile_error!(
113    "Multiple targets specified. Only a single `--features <target-name>` can be specified."
114);
115
116#[cfg(feature = "device-selected")]
117use embedded_hal as hal;
118
119#[cfg(feature = "stm32f100")]
120pub use stm32f1::stm32f100 as pac;
121
122#[cfg(feature = "stm32f101")]
123pub use stm32f1::stm32f101 as pac;
124
125#[cfg(feature = "stm32f103")]
126pub use stm32f1::stm32f103 as pac;
127
128#[cfg(any(feature = "stm32f105", feature = "stm32f107"))]
129pub use stm32f1::stm32f107 as pac;
130
131#[cfg(feature = "device-selected")]
132#[deprecated(since = "0.6.0", note = "please use `pac` instead")]
133#[doc(hidden)]
134pub use crate::pac as device;
135
136#[cfg(feature = "device-selected")]
137#[deprecated(since = "0.6.0", note = "please use `pac` instead")]
138#[doc(hidden)]
139pub use crate::pac as stm32;
140
141#[cfg(feature = "device-selected")]
142pub mod adc;
143#[cfg(feature = "device-selected")]
144pub mod afio;
145#[cfg(feature = "device-selected")]
146pub mod backup_domain;
147#[cfg(feature = "device-selected")]
148pub mod bb;
149#[cfg(all(feature = "device-selected", feature = "has-can"))]
150pub mod can;
151#[cfg(feature = "device-selected")]
152pub mod crc;
153#[cfg(feature = "device-selected")]
154pub mod dma;
155#[cfg(feature = "device-selected")]
156pub mod flash;
157#[cfg(feature = "device-selected")]
158pub mod gpio;
159#[cfg(feature = "device-selected")]
160pub mod i2c;
161#[cfg(feature = "device-selected")]
162pub mod prelude;
163#[cfg(feature = "device-selected")]
164pub mod qei;
165#[cfg(feature = "device-selected")]
166pub mod rcc;
167#[cfg(feature = "device-selected")]
168pub mod rtc;
169#[cfg(feature = "device-selected")]
170pub mod serial;
171#[cfg(feature = "device-selected")]
172pub mod spi;
173#[cfg(feature = "device-selected")]
174pub mod time;
175#[cfg(feature = "device-selected")]
176pub mod timer;
177#[cfg(all(feature = "device-selected", feature = "stm32-usbd"))]
178pub mod usb;
179#[cfg(feature = "device-selected")]
180pub mod watchdog;
181
182#[cfg(feature = "device-selected")]
183mod sealed {
184    pub trait Sealed {}
185}
186#[cfg(feature = "device-selected")]
187use sealed::Sealed;