Chip: S32K146 OS:FreeRtos
Hi,
first, I would try to find the source of hard fault. This application note could be useful:
https://www.nxp.com/docs/en/application-note/AN12201.pdf
There's obviously something what is not de-initialized before jump. This is always a risk when jumping from one application to another without reset. Especially, I would check all interrupts - if interrupt flags, local enable bits in peripherals, interrupt priorities are reverted back to default state.
Regards,
Lukas
void BusFault_Handler(void)
{
BFSR = (S32_SCB->CFSR & 0x0000FF00);
/* BusFault Status Register (BFSR) CFSR[15:8] indicates the cause of BusFault
* [15] BFARVALID = 1 BFAR holds a valid fault address
* [13] LSPERR = 1 Bus fault occurred during floating-point lazy state preservation
* [12] STKERR = 1 Stacking for an exception entry has caused BusFault, BFAR address is not valid
* [11] UNSTKERR = 1 Unstack for an exception return has caused BusFault, BFAR address is not valid
* [10] IMPRECISERR = 1 Imprecise data bus error, BFAR address is not valid
* [9] PRECISERR = 1 Precise data bus error, BFAR address is valid
* [8] IBUSERR = 1 error on prefetching an instruction, BFAR address is invalid
* */
if(BFSR & S32_SCB_CFSR_BFARVALID_MASK){ // If the address in BFAR register is valid
BFAR = S32_SCB->BFAR; // BFAR holds the address of the location that generated the BusFault
}
if(BFSR & S32_SCB_CFSR_PRECISERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_IMPRECISERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_LSPERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_STKERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_UNSTKERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_IBUSERR_MASK) asm("BKPT");
asm("MOVS R0, #4");
asm("MOV R1, LR");
asm("TST R0, R1");
asm("BEQ __MSP");
asm("MRS R0, PSP");
asm("B getStackFrame");
asm("__MSP:");
asm("MRS R0, MSP");
asm("B getStackFrame");
}
Each time it is stuck in the following error :BFSR = 0x8200
BusFault_Handler(): if(BFSR & S32_SCB_CFSR_PRECISERR_MASK) asm("BKPT");
BFAR point to __isr_vector
void BusFault_Handler(void)
{BFSR = (S32_SCB->CFSR & 0x0000FF00);
/* BusFault Status Register (BFSR) CFSR[15:8] indicates the cause of BusFault
* [15] BFARVALID = 1 BFAR holds a valid fault address
* [13] LSPERR = 1 Bus fault occurred during floating-point lazy state preservation
* [12] STKERR = 1 Stacking for an exception entry has caused BusFault, BFAR address is not valid
* [11] UNSTKERR = 1 Unstack for an exception return has caused BusFault, BFAR address is not valid
* [10] IMPRECISERR = 1 Imprecise data bus error, BFAR address is not valid
* [9] PRECISERR = 1 Precise data bus error, BFAR address is valid
* [8] IBUSERR = 1 error on prefetching an instruction, BFAR address is invalid
* */
if(BFSR & S32_SCB_CFSR_BFARVALID_MASK){ // If the address in BFAR register is valid
BFAR = S32_SCB->BFAR; // BFAR holds applinked apk address of the location that generated the BusFault
}
if(BFSR & S32_SCB_CFSR_PRECISERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_IMPRECISERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_LSPERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_STKERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_UNSTKERR_MASK) asm("BKPT");
if(BFSR & S32_SCB_CFSR_IBUSERR_MASK) asm("BKPT");asm("MOVS R0, #4");
asm("MOV R1, LR");
asm("TST R0, R1");
asm("BEQ __MSP");
asm("MRS R0, PSP");
asm("B getStackFrame");
asm("__MSP:");
asm("MRS R0, MSP");
asm("B getStackFrame");
}
Each time it is stuck in the following error :BFSR = 0x8200
BusFault_Handler(): if(BFSR & S32_SCB_CFSR_PRECISERR_MASK) asm("BKPT");
BFAR point to __isr_vector
I am facing the same issue.