cortex_m/
lib.rs

1//! Low level access to Cortex-M processors
2//!
3//! This crate provides:
4//!
5//! - Access to core peripherals like NVIC, SCB and SysTick.
6//! - Access to core registers like CONTROL, MSP and PSR.
7//! - Interrupt manipulation mechanisms
8//! - Safe wrappers around Cortex-M specific instructions like `bkpt`
9//!
10//! # Optional features
11//!
12//! ## `inline-asm`
13//!
14//! When this feature is enabled the implementation of all the functions inside the `asm` and
15//! `register` modules use inline assembly (`asm!`) instead of external assembly (FFI into separate
16//! assembly files pre-compiled using `arm-none-eabi-gcc`). The advantages of enabling `inline-asm`
17//! are:
18//!
19//! - Reduced overhead. FFI eliminates the possibility of inlining so all operations include a
20//! function call overhead when `inline-asm` is not enabled.
21//!
22//! - Some of the `register` API only becomes available only when `inline-asm` is enabled. Check the
23//! API docs for details.
24//!
25//! The disadvantage is that `inline-asm` requires a Rust version at least 1.59 to use the `asm!()`
26//! macro. In the future 0.8 and above versions of `cortex-m`, this feature will always be enabled.
27//!
28//! ## `critical-section-single-core`
29//!
30//! This feature enables a [`critical-section`](https://github.com/rust-embedded/critical-section)
31//! implementation suitable for single-core targets, based on disabling interrupts globally.
32//!
33//! It is **unsound** to enable it on multi-core targets or for code running in unprivileged mode,
34//! and may cause functional problems in systems where some interrupts must be not be disabled
35//! or critical sections are managed as part of an RTOS. In these cases, you should use
36//! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
37//!
38//! ## `cm7-r0p1`
39//!
40//! This feature enables workarounds for errata found on Cortex-M7 chips with revision r0p1. Some
41//! functions in this crate only work correctly on those chips if this Cargo feature is enabled
42//! (the functions are documented accordingly).
43//!
44//! ## `linker-plugin-lto`
45//!
46//! This feature links against prebuilt assembly blobs that are compatible with [Linker-Plugin LTO].
47//! This allows inlining assembly routines into the caller, even without the `inline-asm` feature,
48//! and works on stable Rust (but note the drawbacks below!).
49//!
50//! If you want to use this feature, you need to be aware of a few things:
51//!
52//! - You need to make sure that `-Clinker-plugin-lto` is passed to rustc. Please refer to the
53//!   [Linker-Plugin LTO] documentation for details.
54//!
55//! - You have to use a Rust version whose LLVM version is compatible with the toolchain in
56//!   `asm-toolchain`.
57//!
58//! - Due to a [Rust bug][rust-lang/rust#75940] in compiler versions **before 1.49**, this option
59//!   does not work with optimization levels `s` and `z`.
60//!
61//! [Linker-Plugin LTO]: https://doc.rust-lang.org/stable/rustc/linker-plugin-lto.html
62//! [rust-lang/rust#75940]: https://github.com/rust-lang/rust/issues/75940
63//!
64//! # Minimum Supported Rust Version (MSRV)
65//!
66//! This crate is guaranteed to compile on stable Rust 1.38 and up. It *might*
67//! compile with older versions but that may change in any new patch release.
68
69#![deny(missing_docs)]
70#![no_std]
71#![allow(clippy::identity_op)]
72#![allow(clippy::missing_safety_doc)]
73// Prevent clippy from complaining about empty match expression that are used for cfg gating.
74#![allow(clippy::match_single_binding)]
75// This makes clippy warn about public functions which are not #[inline].
76//
77// Almost all functions in this crate result in trivial or even no assembly.
78// These functions should be #[inline].
79//
80// If you do add a function that's not supposed to be #[inline], you can add
81// #[allow(clippy::missing_inline_in_public_items)] in front of it to add an
82// exception to clippy's rules.
83//
84// This should be done in case of:
85//  - A function containing non-trivial logic (such as itm::write_all); or
86//  - A generated #[derive(Debug)] function (in which case the attribute needs
87//    to be applied to the struct).
88#![deny(clippy::missing_inline_in_public_items)]
89// Don't warn about feature(asm) being stable on Rust >= 1.59.0
90#![allow(stable_features)]
91
92extern crate bare_metal;
93extern crate volatile_register;
94
95#[macro_use]
96mod call_asm;
97#[macro_use]
98mod macros;
99
100pub mod asm;
101#[cfg(armv8m)]
102pub mod cmse;
103mod critical_section;
104pub mod delay;
105pub mod interrupt;
106#[cfg(all(not(armv6m), not(armv8m_base)))]
107pub mod itm;
108pub mod peripheral;
109pub mod prelude;
110pub mod register;
111
112pub use crate::peripheral::Peripherals;