Skip to content

Commit f245e26

Browse files
Emil Freskkorken89
authored andcommitted
cortex-m-rt: Added _stack_end symbol for use with MSPLIM
1 parent 6a324a8 commit f245e26

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

cortex-m-rt/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

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

1213
## [v0.7.4]
1314

cortex-m-rt/link.x.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ SECTIONS
185185
/* Place the heap right after `.uninit` in RAM */
186186
PROVIDE(__sheap = __euninit);
187187

188+
/* Place stack end at the end of allocated RAM */
189+
PROVIDE(_stack_end = __euninit);
190+
188191
/* ## .got */
189192
/* Dynamic relocations are unsupported. This section is only used to detect relocatable code in
190193
the input files and raise an error if relocatable code is found */
@@ -229,6 +232,12 @@ If you have set _stack_start, check it's set to an address which is a multiple o
229232
If you haven't, stack starts at the end of RAM by default. Check that both RAM
230233
origin and length are set to multiples of 8 in the `memory.x` file.");
231234

235+
ASSERT(_stack_end % 4 == 0, "
236+
ERROR(cortex-m-rt): end of stack is not 4-byte aligned");
237+
238+
ASSERT(_stack_start >= _stack_end, "
239+
ERROR(cortex-m-rt): stack end address is not below stack start.");
240+
232241
/* # Position checks */
233242

234243
/* ## .vector_table

cortex-m-rt/src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,21 @@
5858
//! }
5959
//! ```
6060
//!
61-
//! ### `_stack_start`
61+
//! ### `_stack_start` / `_stack_end`
6262
//!
63-
//! This optional symbol can be used to indicate where the call stack of the program should be
64-
//! placed. If this symbol is not used then the stack will be placed at the *end* of the `RAM`
65-
//! region -- the stack grows downwards towards smaller address. This is generally a sensible
66-
//! default and most applications will not need to specify `_stack_start`.
63+
//! The `_stack_start` optional symbol can be used to indicate where the call stack of the program
64+
//! should be placed. If this symbol is not used then the stack will be placed at the *end* of the
65+
//! `RAM` region -- the stack grows downwards towards smaller address. This is generally a sensible
66+
//! default and most applications will not need to specify `_stack_start`. The same goes for
67+
//! `_stack_end` which is automatically placed after the end of statically allocated RAM.
68+
//!
69+
//! **NOTE:** If you change `_stack_start`, make sure to also set `_stack_end` correctly to match
70+
//! new stack area if you are using it, e.g for MSPLIM. The `_stack_end` is not used internally by
71+
//! `cortex-m-rt` and is only for application use.
6772
//!
6873
//! For Cortex-M, the `_stack_start` must always be aligned to 8 bytes, which is enforced by
6974
//! the linker script. If you override it, ensure that whatever value you set is a multiple
70-
//! of 8 bytes.
75+
//! of 8 bytes. The `_stack_end` is aligned to 4 bytes.
7176
//!
7277
//! This symbol can be used to place the stack in a different memory region, for example:
7378
//!
@@ -85,6 +90,7 @@
8590
//! }
8691
//!
8792
//! _stack_start = ORIGIN(CCRAM) + LENGTH(CCRAM);
93+
//! _stack_end = ORIGIN(CCRAM); /* Optional, add if used by the application */
8894
//! ```
8995
//!
9096
//! ### `_stext`
@@ -187,7 +193,7 @@
187193
//!
188194
//! ## `paint-stack`
189195
//!
190-
//! Everywhere between `__sheap` and `___stack_start` is painted with the fixed value
196+
//! Everywhere between `__sheap` and `_stack_start` is painted with the fixed value
191197
//! `STACK_PAINT_VALUE`, which is `0xCCCC_CCCC`.
192198
//! You can then inspect memory during debugging to determine how much of the stack has been used -
193199
//! where the stack has been used the 'paint' will have been 'scrubbed off' and the memory will

0 commit comments

Comments
 (0)