Hi,
I am using S32K322 mcu. I am running Application with Bootloader, my aim is to set a flag in Retention RAM inside the Hardfault Handler so that I can detect the Hardfault in Bootloader.
To achieve this I created a noinit section in SRAM.
/*Noinit section inside sharable region*/
.noinit (NOLOAD) :
{
__noinit_start = .;
*(.noinit) /* Variables explicitly placed in the .noinit section */
. = ALIGN(4);
__noinit_end = .;
} > int_sram_shareable
and then done changes in startup_cm7.s to stop reinitialization of noinit section
RamInit:
/* Initialize SRAM ECC */
ldr r0, =__RAM_INIT
cmp r0, 0
/* Skip if __RAM_INIT is not set */
beq SRAM_LOOP_END
ldr r0, =MCRGM_DES
ldr r1, [r0]
ldr r2, =MCRGM_DES_F_POR
and r1, r1, r2
cmp r1, 0
beq NO_INIT_STANDBY_REGION
ldr r1, =__INT_SRAM_START
ldr r2, =__NOINIT_SRAM_START // Exclude noinit memory region
//ldr r2, =__INT_SRAM_END
b ZERO_64B_RAM
NO_INIT_STANDBY_REGION:
#if defined(S32K310)||defined(S32M274)
ldr r1, =__BSS_SRAM_NC_START
#else
ldr r1, =__BSS_SRAM_START
#endif
ldr r2, =__NOINIT_SRAM_START /* Exclude .noinit */
//ldr r2, =__INT_SRAM_END
ZERO_64B_RAM:
subs r2, r1
subs r2, #1
ble SRAM_LOOP_END
movs r0, 0
movs r3, 0
SRAM_LOOP:
stm r1!, {r0,r3}
subs r2, 8
bge SRAM_LOOP
SRAM_LOOP_END:
Now I am trying to write Flag inside the HardFault handler
__attribute__((section(".noinit"))) volatile uint8_t hardFaultCounter;
void HardFault_Handler(void)
{
hardFaultCounter++;
__asm volatile("dsb 0xF":::"memory");
__asm volatile ("isb 0xF");
while(TRUE)
{
};
}
My problem is it is retaining the value only if I am putting the breakpoint to hardFaultCounter++; and stepping up but without breakpoint it is not retaining.
Please note that It is successfully writing the updated value to the retention RAM, I verified by reading back but It is not retaining the value after reset.
Is Memory Protection Unit is preventing to retain ?