File tree Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Expand file tree Collapse file tree 3 files changed +25
-9
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ required-features = ["device"]
45
45
device = []
46
46
set-sp = []
47
47
set-vtor = []
48
+ zero-init-ram = []
48
49
49
50
[package .metadata .docs .rs ]
50
51
features = [" device" ]
Original file line number Diff line number Diff line change @@ -60,7 +60,9 @@ PROVIDE(__pre_init = DefaultPreInit);
60
60
/* # Sections */
61
61
SECTIONS
62
62
{
63
- PROVIDE(_stack_start = ORIGIN(RAM) + LENGTH(RAM));
63
+ PROVIDE(_ram_start = ORIGIN(RAM) + LENGTH(RAM));
64
+ PROVIDE(_ram_end = ORIGIN(RAM));
65
+ PROVIDE(_stack_start = _ram_start);
64
66
65
67
/* ## Sections in FLASH */
66
68
/* ### Vector table */
Original file line number Diff line number Diff line change @@ -514,6 +514,19 @@ cfg_global_asm! {
514
514
"ldr r0, =_stack_start
515
515
msr msp, r0" ,
516
516
517
+ // If enabled, initialize RAM with zeros. This is normally not necessary but might be required
518
+ // on custom hardware.
519
+ #[ cfg( feature = "zero-init-ram" ) ]
520
+ "ldr r0, =_ram_end
521
+ ldr r1, =_ram_start
522
+ movs r2, #0
523
+ 0:
524
+ cmp r1, r0
525
+ beq 1f
526
+ stm r0!, {{r2}}
527
+ b 0b
528
+ 1:" ,
529
+
517
530
// If enabled, initialise VTOR to the start of the vector table. This is normally initialised
518
531
// by a bootloader when the non-reset value is required, but some bootloaders do not set it,
519
532
// leading to frustrating issues where everything seems to work but interrupts are never
@@ -533,24 +546,24 @@ cfg_global_asm! {
533
546
"ldr r0, =__sbss
534
547
ldr r1, =__ebss
535
548
movs r2, #0
536
- 0 :
549
+ 2 :
537
550
cmp r1, r0
538
- beq 1f
551
+ beq 3f
539
552
stm r0!, {{r2}}
540
- b 0b
541
- 1 :" ,
553
+ b 2b
554
+ 3 :" ,
542
555
543
556
// Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
544
557
"ldr r0, =__sdata
545
558
ldr r1, =__edata
546
559
ldr r2, =__sidata
547
- 2 :
560
+ 4 :
548
561
cmp r1, r0
549
- beq 3f
562
+ beq 5f
550
563
ldm r2!, {{r3}}
551
564
stm r0!, {{r3}}
552
- b 2b
553
- 3 :" ,
565
+ b 4b
566
+ 5 :" ,
554
567
555
568
// Potentially enable an FPU.
556
569
// SCB.CPACR is 0xE000_ED88.
You can’t perform that action at this time.
0 commit comments