From bc0aca85f4a3dc1432631503292a7fb1644df836 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Tue, 16 Apr 2024 19:11:22 +0100 Subject: [PATCH 1/3] Prepare for cortex-m-rt v0.7.4 --- cortex-m-rt/CHANGELOG.md | 15 +++++++++++---- cortex-m-rt/Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md index 64429627..d4bab576 100644 --- a/cortex-m-rt/CHANGELOG.md +++ b/cortex-m-rt/CHANGELOG.md @@ -7,10 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -- Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary on - safety-critical hardware to properly initialize memory integrity measures. -- Add optional `exception` argument for `HardFault`. It has one option `trampoline` which is true by default. When set to false, no trampoline will be created and the function will be called as the exception handler directly. +## [v0.7.4] + +- Add `zero-init-ram` feature to initialize RAM with zeros on startup. + This can be necessary to properly initialise hardware error detection. +- Add optional `exception` argument for `HardFault`. + It has one option `trampoline` which is true by default. When set to false, + no trampoline will be created and the function will be called as the + exception handler directly. - MSRV increased to 1.60.0 to align with `embedded-hal` version 1. +- Improve linker error message when code does not fit into flash. ## [v0.7.3] @@ -621,7 +627,8 @@ section size addr Initial release -[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/c-m-rt-v0.7.3...HEAD +[Unreleased]: https://github.com/rust-embedded/cortex-m/compare/c-m-rt-v0.7.4...HEAD +[v0.7.4]: https://github.com/rust-embedded/cortex-m/compare/c-m-rt-v0.7.3...c-m-rt-v0.7.4 [v0.7.3]: https://github.com/rust-embedded/cortex-m/compare/c-m-rt-v0.7.2...c-m-rt-v0.7.3 [v0.7.2]: https://github.com/rust-embedded/cortex-m/compare/c-m-rt-v0.7.1...c-m-rt-v0.7.2 [v0.7.1]: https://github.com/rust-embedded/cortex-m-rt/compare/v0.7.0...v0.7.1 diff --git a/cortex-m-rt/Cargo.toml b/cortex-m-rt/Cargo.toml index b222f878..e945bac2 100644 --- a/cortex-m-rt/Cargo.toml +++ b/cortex-m-rt/Cargo.toml @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0" name = "cortex-m-rt" readme = "README.md" repository = "https://github.com/rust-embedded/cortex-m" -version = "0.7.3" +version = "0.7.4" autoexamples = true links = "cortex-m-rt" # Prevent multiple versions of cortex-m-rt being linked edition = "2021" From be045507c4adb3388a6d480fd4a10f05998c9d71 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Tue, 16 Apr 2024 20:00:59 +0100 Subject: [PATCH 2/3] c-m-rt: update docs to cover custom linker scripts and link sections --- cortex-m-rt/CHANGELOG.md | 2 + cortex-m-rt/src/lib.rs | 93 +++++++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md index d4bab576..105bd55c 100644 --- a/cortex-m-rt/CHANGELOG.md +++ b/cortex-m-rt/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). exception handler directly. - MSRV increased to 1.60.0 to align with `embedded-hal` version 1. - Improve linker error message when code does not fit into flash. +- Update documentation on using custom linker scripts and linker sections + and on the `pre_init` function. ## [v0.7.3] diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs index 8b7985a1..238240fe 100644 --- a/cortex-m-rt/src/lib.rs +++ b/cortex-m-rt/src/lib.rs @@ -12,18 +12,23 @@ //! //! - Initializing `static` variables before the program entry point. //! -//! - Enabling the FPU before the program entry point if the target is `thumbv7em-none-eabihf`. +//! - Enabling the FPU before the program entry point if the target is `-eabihf`. //! //! This crate also provides the following attributes: //! //! - [`#[entry]`][attr-entry] to declare the entry point of the program //! - [`#[exception]`][attr-exception] to override an exception handler. If not overridden all //! exception handlers default to an infinite loop. -//! - [`#[pre_init]`][attr-pre_init] to run code *before* `static` variables are initialized //! //! This crate also implements a related attribute called `#[interrupt]`, which allows you //! to define interrupt handlers. However, since which interrupts are available depends on the -//! microcontroller in use, this attribute should be re-exported and used from a device crate. +//! microcontroller in use, this attribute should be re-exported and used from a peripheral +//! access crate (PAC). +//! +//! A [`#[pre_init]`][attr-pre_init] macro is also provided to run a function before RAM +//! initialisation, but its use is deprecated as it is not defined behaviour to execute Rust +//! code before initialisation. It is still possible to create a custom `pre_init` function +//! using assembly. //! //! The documentation for these attributes can be found in the [Attribute Macros](#attributes) //! section. @@ -33,8 +38,9 @@ //! ## `memory.x` //! //! This crate expects the user, or some other crate, to provide the memory layout of the target -//! device via a linker script named `memory.x`. This section covers the contents of `memory.x` -//! The `memory.x` file is used during linking by the `link.x` script provided by this crate. +//! device via a linker script named `memory.x`, described in this section. The `memory.x` file is +//! used during linking by the `link.x` script provided by this crate. If you are using a custom +//! linker script, you do not need a `memory.x` file. //! //! ### `MEMORY` //! @@ -48,7 +54,7 @@ //! MEMORY //! { //! FLASH : ORIGIN = 0x08000000, LENGTH = 64K -//! RAM : ORIGIN = 0x20000000, LENGTH = 20K +//! RAM : ORIGIN = 0x20000000, LENGTH = 20K //! } //! ``` //! @@ -56,7 +62,8 @@ //! //! This optional symbol can be used to indicate where the call stack of the program should be //! placed. If this symbol is not used then the stack will be placed at the *end* of the `RAM` -//! region -- the stack grows downwards towards smaller address. +//! region -- the stack grows downwards towards smaller address. This is generally a sensible +//! default and most applications will not need to specify `_stack_start`. //! //! For Cortex-M, the `_stack_start` must always be aligned to 8 bytes, which is enforced by //! the linker script. If you override it, ensure that whatever value you set is a multiple @@ -65,13 +72,13 @@ //! This symbol can be used to place the stack in a different memory region, for example: //! //! ```text -//! /* Linker script for the STM32F303VCT6 */ +//! /* Linker script for the STM32F303VCT6 with stack in CCM */ //! MEMORY //! { //! FLASH : ORIGIN = 0x08000000, LENGTH = 256K //! //! /* .bss, .data and the heap go in this region */ -//! RAM : ORIGIN = 0x20000000, LENGTH = 40K +//! RAM : ORIGIN = 0x20000000, LENGTH = 40K //! //! /* Core coupled (faster) RAM dedicated to hold the stack */ //! CCRAM : ORIGIN = 0x10000000, LENGTH = 8K @@ -106,17 +113,15 @@ //! graph (see [`#[exception]`]). In this example we define them in the binary crate: //! //! ```no_run -//! // IMPORTANT the standard `main` interface is not used because it requires nightly //! #![no_main] //! #![no_std] //! //! // Some panic handler needs to be included. This one halts the processor on panic. -//! extern crate panic_halt; +//! use panic_halt as _; //! //! use cortex_m_rt::entry; //! -//! // use `main` as the entry point of this application -//! // `main` is not allowed to return +//! // Use `main` as the entry point of this application, which may not return. //! #[entry] //! fn main() -> ! { //! // initialization @@ -133,7 +138,6 @@ //! //! ```text //! $ cat > memory.x < = MaybeUninit::uninit(); //! ``` //! +//! However, note that these sections are not initialised by cortex-m-rt, and so must be used +//! either with `MaybeUninit` types or you must otherwise arrange for them to be initialised +//! yourself, such as in `pre_init`. +//! //! [attr-entry]: attr.entry.html //! [attr-exception]: attr.exception.html //! [attr-pre_init]: attr.pre_init.html @@ -577,7 +590,7 @@ cfg_global_asm! { /// /// **NOTE**: This attribute is exposed by `cortex-m-rt` only when the `device` feature is enabled. /// However, that export is not meant to be used directly -- using it will result in a compilation -/// error. You should instead use the device crate (usually generated using `svd2rust`) re-export of +/// error. You should instead use the PAC (usually generated using `svd2rust`) re-export of /// that attribute. You need to use the re-export to have the compiler check that the interrupt /// exists on the target device. /// @@ -586,7 +599,7 @@ cfg_global_asm! { /// ``` ignore /// extern crate device; /// -/// // the attribute comes from the device crate not from cortex-m-rt +/// // the attribute comes from the PAC not from cortex-m-rt /// use device::interrupt; /// /// #[interrupt] From 602061570287c7841236b84ab71eb85101599739 Mon Sep 17 00:00:00 2001 From: Adam Greig Date: Tue, 16 Apr 2024 20:30:31 +0100 Subject: [PATCH 3/3] Update cortex-m-rt/CHANGELOG.md Co-authored-by: Daniel Egger --- cortex-m-rt/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cortex-m-rt/CHANGELOG.md b/cortex-m-rt/CHANGELOG.md index 105bd55c..2aa839c1 100644 --- a/cortex-m-rt/CHANGELOG.md +++ b/cortex-m-rt/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add `zero-init-ram` feature to initialize RAM with zeros on startup. This can be necessary to properly initialise hardware error detection. - Add optional `exception` argument for `HardFault`. - It has one option `trampoline` which is true by default. When set to false, + It has one option `trampoline` which is `true` by default. When set to `false`, no trampoline will be created and the function will be called as the exception handler directly. - MSRV increased to 1.60.0 to align with `embedded-hal` version 1.