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
