Skip to content

Commit 1a1b55c

Browse files
Merge #282
282: Doc adding memory sections in memory.x r=therealprof a=tstellanova As noted in #281 it is possible to define additional memory sections in `memory.x`. Added some documentation on how to do this. Co-authored-by: Todd Stellanova <[email protected]>
2 parents 1ac1453 + d1ddbce commit 1a1b55c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cortex-m-rt/src/lib.rs

+35
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,41 @@
387387
//! undefined behavior. At some point in the future we may add an attribute to safely place static
388388
//! variables in this section.
389389
//!
390+
//! ## Extra Sections
391+
//!
392+
//! Some microcontrollers provide additional memory regions beyond RAM and FLASH.
393+
//! For example, some STM32 devices provide "CCM" or core-coupled RAM that is
394+
//! only accessible from the core. In order to access these using
395+
//! [`link_section`] attributes from your code, you need to modify `memory.x`
396+
//! to declare the additional sections:
397+
//!
398+
//! [`link_section`]: https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute
399+
//!
400+
//! ```text
401+
//! MEMORY
402+
//! {
403+
//! FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
404+
//! RAM (rw) : ORIGIN = 0x20000000, LENGTH = 128K
405+
//! CCMRAM (rw) : ORIGIN = 0x10000000, LENGTH = 64K
406+
//! }
407+
//!
408+
//! SECTIONS
409+
//! {
410+
//! .ccmram (NOLOAD) : ALIGN(4)
411+
//! {
412+
//! *(.ccmram .ccmram.*);
413+
//! . = ALIGN(4);
414+
//! } > CCMRAM
415+
//! } INSERT AFTER .bss;
416+
//! ```
417+
//!
418+
//! You can then use something like this to place a variable into this specific section of memory:
419+
//!
420+
//! ```no_run,edition2018
421+
//! #[link_section=".ccmram.BUFFERS"]
422+
//! static mut BUF: [u8; 1024] = [0u8; 1024];
423+
//! ```
424+
//!
390425
//! [attr-entry]: attr.entry.html
391426
//! [attr-exception]: attr.exception.html
392427
//! [attr-pre_init]: attr.pre_init.html

0 commit comments

Comments
 (0)