liveBook · Manning

Memory.x

As explained in Embedded Software with Rust

memory.x is a conventional linker-script fragment that declares embedded memory regions for a Rust firmware build.

memory.x is a linker-script fragment that declares the FLASH and RAM regions available to embedded firmware. Runtime crates such as cortex-m-rt and riscv-rt generate a link.x that includes it; projects using these runtimes typically place memory.x at the crate root. Its values must match the specific microcontroller. section 3.2.1

MEMORY
 {
   /* NOTE K = KiBi = 1024 bytes */
   FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 64K
   RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 20K
 }
 _stack_start = ORIGIN(RAM) + LENGTH(RAM);

For the STM32F103C8T6 on the Blue Pill, MEMORY declares each region’s origin, length, and access permissions: FLASH is readable and executable; RAM is readable, writable, and executable. The final line sets the stack start to the end of RAM. K means 1,024 bytes. section 2.6.4 section 3.2.1

The linker uses these declarations to place program sections such as .text and .data, as well as stack regions, at appropriate addresses. Check the device data sheet or technical reference manual rather than assuming a project template matches different hardware. Incorrect values can cause firmware update failures or runtime faults, including immediate core lock-up. section 2.4.3 section 3.2.1

The memory map is separate from the target triple configured in .cargo/config.toml: the target selects the processor family, while memory.x describes the device’s memory. For non-standard firmware layouts, a project can supply its own linker script or memory.x to control region and section placement. section 2.4.3 section 1.3.3

How Embedded Software with Rust covers it

How deep it goes
Explains region origins, lengths, permissions, and placement failures, while deferring advanced linker customization and troubleshooting.
Examples
Uses an STM32F103C8T6 Blue Pill memory map with an explicit stack start.
What you can do after
Operate/configure a device-specific memory map by checking region values against the microcontroller documentation.
How it connects
Connects linker scripts with runtime crates, program sections, and stack placement.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.