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"]
4545device = []
4646set-sp = []
4747set-vtor = []
48+ zero-init-ram = []
4849
4950[package .metadata .docs .rs ]
5051features = [" device" ]
Original file line number Diff line number Diff line change @@ -60,7 +60,9 @@ PROVIDE(__pre_init = DefaultPreInit);
6060/* # Sections */
6161SECTIONS
6262{
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);
6466
6567 /* ## Sections in FLASH */
6668 /* ### Vector table */
Original file line number Diff line number Diff line change @@ -514,6 +514,19 @@ cfg_global_asm! {
514514 "ldr r0, =_stack_start
515515 msr msp, r0" ,
516516
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+
517530 // If enabled, initialise VTOR to the start of the vector table. This is normally initialised
518531 // by a bootloader when the non-reset value is required, but some bootloaders do not set it,
519532 // leading to frustrating issues where everything seems to work but interrupts are never
@@ -533,24 +546,24 @@ cfg_global_asm! {
533546 "ldr r0, =__sbss
534547 ldr r1, =__ebss
535548 movs r2, #0
536- 0 :
549+ 2 :
537550 cmp r1, r0
538- beq 1f
551+ beq 3f
539552 stm r0!, {{r2}}
540- b 0b
541- 1 :" ,
553+ b 2b
554+ 3 :" ,
542555
543556 // Initialise .data memory. `__sdata`, `__sidata`, and `__edata` come from the linker script.
544557 "ldr r0, =__sdata
545558 ldr r1, =__edata
546559 ldr r2, =__sidata
547- 2 :
560+ 4 :
548561 cmp r1, r0
549- beq 3f
562+ beq 5f
550563 ldm r2!, {{r3}}
551564 stm r0!, {{r3}}
552- b 2b
553- 3 :" ,
565+ b 4b
566+ 5 :" ,
554567
555568 // Potentially enable an FPU.
556569 // SCB.CPACR is 0xE000_ED88.
You can’t perform that action at this time.
0 commit comments