sdk: 2.5.1
cpu: nrf5340
I have a bootloader which have a big ram block for upgrade purpose (around 250kb) in bss section (I will move it in noinit, but it is not the point here).
I have an app, that poweroff unused ram with VMC register.
Sometimes, the app will enter in poweroff (using REGULATORS register), and will be awakened by vbus or nfc.
When the cpu is awakened, the bss section and idle stacks are in a part of the ram that is powered off, and this is a unrecoverable crash.
I found a solution with powering ram at early startup, but I would like to check with you if it is correct.
The solution may also be about powering up ram before entering poweroff, but I would like may bootloader to be robust.
I wrapped the method z_arm_reset (with linker argument --wrap), and wrote this method:
extern void __real_z_arm_reset();
__attribute__((naked))
void __wrap_z_arm_reset(void)
{
NRF_VMC->RAM[0].POWERSET = 0xFFFF;
NRF_VMC->RAM[1].POWERSET = 0xFFFF;
NRF_VMC->RAM[2].POWERSET = 0xFFFF;
NRF_VMC->RAM[3].POWERSET = 0xFFFF;
NRF_VMC->RAM[4].POWERSET = 0xFFFF;
NRF_VMC->RAM[5].POWERSET = 0xFFFF;
NRF_VMC->RAM[6].POWERSET = 0xFFFF;
NRF_VMC->RAM[7].POWERSET = 0xFFFF;
__asm__ volatile ("b __real_z_arm_reset");
}
I checked the generated code, and no stack seem to be used:
00002a28 <__wrap_z_arm_reset>:
2a28: f64f 72ff movw r2, #65535 ; 0xffff
2a2c: 4b09 ldr r3, [pc, #36] ; (2a54 <__wrap_z_arm_reset+0x2c>)
2a2e: f8c3 2604 str.w r2, [r3, #1540] ; 0x604
2a32: f8c3 2614 str.w r2, [r3, #1556] ; 0x614
2a36: f8c3 2624 str.w r2, [r3, #1572] ; 0x624
2a3a: f8c3 2634 str.w r2, [r3, #1588] ; 0x634
2a3e: f8c3 2644 str.w r2, [r3, #1604] ; 0x644
2a42: f8c3 2654 str.w r2, [r3, #1620] ; 0x654
2a46: f8c3 2664 str.w r2, [r3, #1636] ; 0x664
2a4a: f8c3 2674 str.w r2, [r3, #1652] ; 0x674
2a4e: f00a b9e7 b.w ce20 <z_arm_reset>
2a52: bf00 nop
2a54: 50081000 .word 0x50081000
Waiting for your answer.
Regards,