Some processors start without RAM enabled. That's the case for the NXP LPC546XX family. Their solution is to add inline assembly to enable the ram on startup:
// Enable SRAM clock used by Stack
__asm volatile ("LDR R0, =0x40000220\n\t"
"MOV R1, #56\n\t"
"STR R1, [R0]");
I tried to do the same in the pre_init stub:
#[inline(always)]
#[pre_init]
unsafe fn pre_init() {
asm!("ldr r0, =0x40000220");
asm!("mov r1, #56");
asm!("str r1, [r0]");
}
Using the __pre_init decorator does not allow for this kind of run-time setup since a push instruction is/might be generated inside the __pre_init stub, accessing the stack when RAM is not available. #[inline(always)] does not inline the function in the reset stub:
00000180 <__pre_init>:
180: b580 push {r7, lr} <- this cannot happen at this point in execution since sp points to a non-enable address space
182: 466f mov r7, sp
184: 4803 ldr r0, [pc, #12] ; (194 <__pre_init+0x14>)
186: e7ff b.n 188 <__pre_init+0x8>
188: f04f 0138 mov.w r1, #56 ; 0x38
18c: e7ff b.n 18e <__pre_init+0xe>
18e: 6001 str r1, [r0, #0]
190: e7ff b.n 192 <__pre_init+0x12>
192: bd80 pop {r7, pc}
194: 40000220 andmi r0, r0, r0, lsr #4
Maybe there can be a possibility to include an asm stub, similarely to what is done with the memory.x file