Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cortex-m-rt: Added _stack_end symbol for use with MSPLIM #565

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cortex-m-rt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

- MSRV is now Rust 1.61 to support syn verions >=2.0.68
- The `_stack_end` symbol is added, e.g. for use with MSPLIM.

## [v0.7.4]

Expand Down
9 changes: 9 additions & 0 deletions cortex-m-rt/link.x.in
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ SECTIONS
/* Place the heap right after `.uninit` in RAM */
PROVIDE(__sheap = __euninit);

/* Place stack end at the end of allocated RAM */
PROVIDE(_stack_end = __euninit);

/* ## .got */
/* Dynamic relocations are unsupported. This section is only used to detect relocatable code in
the input files and raise an error if relocatable code is found */
Expand Down Expand Up @@ -229,6 +232,12 @@ If you have set _stack_start, check it's set to an address which is a multiple o
If you haven't, stack starts at the end of RAM by default. Check that both RAM
origin and length are set to multiples of 8 in the `memory.x` file.");

ASSERT(_stack_end % 4 == 0, "
ERROR(cortex-m-rt): end of stack is not 4-byte aligned");

ASSERT(_stack_start >= _stack_end, "
ERROR(cortex-m-rt): stack end address is not below stack start.");

/* # Position checks */

/* ## .vector_table
Expand Down
20 changes: 13 additions & 7 deletions cortex-m-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@
//! }
//! ```
//!
//! ### `_stack_start`
//! ### `_stack_start` / `_stack_end`
//!
//! 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. This is generally a sensible
//! default and most applications will not need to specify `_stack_start`.
//! The `_stack_start` 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. This is generally a sensible
//! default and most applications will not need to specify `_stack_start`. The same goes for
//! `_stack_end` which is automatically placed after the end of statically allocated RAM.
//!
//! **NOTE:** If you change `_stack_start`, make sure to also set `_stack_end` correctly to match
//! new stack area if you are using it, e.g for MSPLIM. The `_stack_end` is not used internally by
//! `cortex-m-rt` and is only for application use.
//!
//! 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
//! of 8 bytes.
//! of 8 bytes. The `_stack_end` is aligned to 4 bytes.
//!
//! This symbol can be used to place the stack in a different memory region, for example:
//!
Expand All @@ -85,6 +90,7 @@
//! }
//!
//! _stack_start = ORIGIN(CCRAM) + LENGTH(CCRAM);
//! _stack_end = ORIGIN(CCRAM); /* Optional, add if used by the application */
//! ```
//!
//! ### `_stext`
Expand Down Expand Up @@ -187,7 +193,7 @@
//!
//! ## `paint-stack`
//!
//! Everywhere between `__sheap` and `___stack_start` is painted with the fixed value
//! Everywhere between `__sheap` and `_stack_start` is painted with the fixed value
//! `STACK_PAINT_VALUE`, which is `0xCCCC_CCCC`.
//! You can then inspect memory during debugging to determine how much of the stack has been used -
//! where the stack has been used the 'paint' will have been 'scrubbed off' and the memory will
Expand Down