File tree 3 files changed +25
-9
lines changed 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 @@ -515,6 +515,19 @@ cfg_global_asm! {
515
515
"ldr r0, =_stack_start
516
516
msr msp, r0" ,
517
517
518
+ // If enabled, initialize RAM with zeros. This is normally not necessary but might be required
519
+ // on custom hardware.
520
+ #[ cfg( feature = "zero-init-ram" ) ]
521
+ "ldr r0, =_ram_end
522
+ ldr r1, =_ram_start
523
+ movs r2, #0
524
+ 0:
525
+ cmp r1, r0
526
+ beq 1f
527
+ stm r0!, {{r2}}
528
+ b 0b
529
+ 1:" ,
530
+
518
531
// If enabled, initialise VTOR to the start of the vector table. This is normally initialised
519
532
// by a bootloader when the non-reset value is required, but some bootloaders do not set it,
520
533
// leading to frustrating issues where everything seems to work but interrupts are never
@@ -536,24 +549,24 @@ cfg_global_asm! {
536
549
"ldr r0, =__sbss
537
550
ldr r1, =__ebss
538
551
movs r2, #0
539
- 0 :
552
+ 2 :
540
553
cmp r1, r0
541
- beq 1f
554
+ beq 3f
542
555
stm r0!, {{r2}}
543
- b 0b
544
- 1 :" ,
556
+ b 2b
557
+ 3 :" ,
545
558
546
559
// Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
547
560
"ldr r0, =__sdata
548
561
ldr r1, =__edata
549
562
ldr r2, =__sidata
550
- 2 :
563
+ 4 :
551
564
cmp r1, r0
552
- beq 3f
565
+ beq 5f
553
566
ldm r2!, {{r3}}
554
567
stm r0!, {{r3}}
555
- b 2b
556
- 3 :" ,
568
+ b 4b
569
+ 5 :" ,
557
570
558
571
// Potentially enable an FPU.
559
572
// SCB.CPACR is 0xE000_ED88.
You can’t perform that action at this time.
0 commit comments