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//! ## `critical-section-single-core`
13//!
14//! This feature enables a [`critical-section`](https://github.com/rust-embedded/critical-section)
15//! implementation suitable for single-core targets, based on disabling interrupts globally.
16//!
17//! It is **unsound** to enable it on multi-core targets or for code running in unprivileged mode,
18//! and may cause functional problems in systems where some interrupts must not be disabled
19//! or critical sections are managed as part of an RTOS. In these cases, you should use
20//! a target-specific implementation instead, typically provided by a HAL or RTOS crate.
21//!
22//! The critical section has been optimized to block interrupts for as few cycles as possible,
23//! but -- due to `critical-section` implementation details -- incurs branches in a normal build
24//! configuration. For minimal interrupt latency, you can achieve inlining by enabling
25//! [linker-plugin-based LTO](https://doc.rust-lang.org/rustc/linker-plugin-lto.html).
26//!
27//! ## `cm7-r0p1`
28//!
29//! This feature enables workarounds for errata found on Cortex-M7 chips with revision r0p1. Some
30//! functions in this crate only work correctly on those chips if this Cargo feature is enabled
31//! (the functions are documented accordingly).
32//!
33//! ## `linker-plugin-lto`
34//!
35//! This feature links against prebuilt assembly blobs that are compatible with [Linker-Plugin LTO].
36//! This allows inlining assembly routines into the caller, and works on stable Rust (but note the drawbacks below!).
37//!
38//! If you want to use this feature, you need to be aware of a few things:
39//!
40//! - You need to make sure that `-Clinker-plugin-lto` is passed to rustc. Please refer to the
41//! [Linker-Plugin LTO] documentation for details.
42//!
43//! - You have to use a Rust version whose LLVM version is compatible with the toolchain in
44//! `asm-toolchain`.
45//!
46//! - Due to a [Rust bug][rust-lang/rust#75940] in compiler versions **before 1.49**, this option
47//! does not work with optimization levels `s` and `z`.
48//!
49//! [Linker-Plugin LTO]: https://doc.rust-lang.org/stable/rustc/linker-plugin-lto.html
50//! [rust-lang/rust#75940]: https://github.com/rust-lang/rust/issues/75940
51//!
52//! ## `secure-mode`
53//!
54//! Adds extra non-secure peripherals to the `Peripherals` struct. Only set when your
55//! processor is running in Secure mode, and you need to control operations in nonsecure
56//! mode (e.g. to bootload some nonsecure firmware).
57//!
58//! ## `inline-asm`
59//!
60//! This feature is deprecated.
61//! Enabling this feature does nothing - it exists for backwards-compatibility only.
62//! It will be removed in a future version of this crate.
63//!
64//! # Minimum Supported Rust Version (MSRV)
65//!
66//! This crate is guaranteed to compile on stable Rust 1.85 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
92#[cfg(all(feature = "cm7-r0p1", not(armv7em)))]
93compile_error!("The feature \"cm7-r0p1\" is only compatible with the armv7em target");
94
95extern crate bare_metal;
96extern crate volatile_register;
97
98#[macro_use]
99mod macros;
100
101pub mod asm;
102#[cfg(armv8m)]
103pub mod cmse;
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 psp;
111pub mod register;
112
113pub use crate::peripheral::Peripherals;
114
115#[cfg(all(cortex_m, feature = "critical-section-single-core"))]
116mod critical_section;
117
118/// Used to reexport items for use in macros. Do not use directly.
119/// Not covered by semver guarantees.
120#[doc(hidden)]
121pub mod _export {
122 pub use critical_section;
123}