aboutsummaryrefslogtreecommitdiff
path: root/cortex-m-rt/src/lib.rs
diff options
context:
space:
mode:
authorGravatar Norbert Fabritius <norbert.fabritius@esrlabs.com> 2022-12-15 11:41:19 +0100
committerGravatar Adam Greig <adam@adamgreig.com> 2023-02-17 18:20:44 +0000
commit71187f65f49bf1b4fa764215dc1b73e7e980742a (patch)
tree8fcd85f93ca9d6842e666a5cb517a291b5e773bf /cortex-m-rt/src/lib.rs
parent8e4b18741d77a57eb0ae4d9a011611d1428a478d (diff)
downloadcortex-m-71187f65f49bf1b4fa764215dc1b73e7e980742a.tar.gz
cortex-m-71187f65f49bf1b4fa764215dc1b73e7e980742a.tar.zst
cortex-m-71187f65f49bf1b4fa764215dc1b73e7e980742a.zip
Add zero-init-ram feature
Add the 'zero-init-ram' feature that initializes the RAM with zeros during startup. This is normally not necessary but might be required on custom hardware. If this step is skipped on such hardware, reading from memory that was never written to will cause a hard-fault.
Diffstat (limited to 'cortex-m-rt/src/lib.rs')
-rw-r--r--cortex-m-rt/src/lib.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/cortex-m-rt/src/lib.rs b/cortex-m-rt/src/lib.rs
index 2070efa..96d89dd 100644
--- a/cortex-m-rt/src/lib.rs
+++ b/cortex-m-rt/src/lib.rs
@@ -514,6 +514,19 @@ cfg_global_asm! {
"ldr r0, =_stack_start
msr msp, r0",
+ // If enabled, initialize RAM with zeros. This is normally not necessary but might be required
+ // on custom hardware.
+ #[cfg(feature = "zero-init-ram")]
+ "ldr r0, =_ram_end
+ ldr r1, =_ram_start
+ movs r2, #0
+ 0:
+ cmp r1, r0
+ beq 1f
+ stm r0!, {{r2}}
+ b 0b
+ 1:",
+
// If enabled, initialise VTOR to the start of the vector table. This is normally initialised
// by a bootloader when the non-reset value is required, but some bootloaders do not set it,
// leading to frustrating issues where everything seems to work but interrupts are never
@@ -533,24 +546,24 @@ cfg_global_asm! {
"ldr r0, =__sbss
ldr r1, =__ebss
movs r2, #0
- 0:
+ 2:
cmp r1, r0
- beq 1f
+ beq 3f
stm r0!, {{r2}}
- b 0b
- 1:",
+ b 2b
+ 3:",
// Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
"ldr r0, =__sdata
ldr r1, =__edata
ldr r2, =__sidata
- 2:
+ 4:
cmp r1, r0
- beq 3f
+ beq 5f
ldm r2!, {{r3}}
stm r0!, {{r3}}
- b 2b
- 3:",
+ b 4b
+ 5:",
// Potentially enable an FPU.
// SCB.CPACR is 0xE000_ED88.