AnsweredAssumed Answered

S32K144's Processor Expert project add 'printf()' function

Question asked by Bao Tingkai on Feb 26, 2018
Latest reply on Mar 16, 2018 by Razvan-nicolae Tilimpea

I am using a new example 'hello_world_s32k144' form 'S32K14x EAR SDK v0.8.6' and it can work normally.

But when I add debug HardFault's code to the project,the project will be reported follow error:

When I comment on the 'printf' function, no error occurs.What is the cause of the error,the code as follow:


* HardFault_Handler.c
* Created on: 2018_2_27
* Author: Ling
#include "S32K144.h"
#include "s32_core_cm4.h"


void HardFault_Handler(void)

__asm("TST LR , #4");
/* LR Register & 0b0100 and Update the value in CPSR */
__asm("ITE EQ");
/* If LR's 2th bit equal to 0 */
__asm("MRSEQ R0 , MSP");
__asm("MRSNE R0 , PSP");
__asm("MOV R1 , LR");
__asm("B HardFault_Handler_C");



void HardFault_Handler_C(unsigned long *hardfault_args,unsigned int lr_value)
unsigned long int stacked_r0;
unsigned long int stacked_r1;
unsigned long int stacked_r2;
unsigned long int stacked_r3;
unsigned long int stacked_r12;
unsigned long int stacked_lr;
unsigned long int stacked_pc;
unsigned long int stacked_psr;
unsigned long int cfsr;
unsigned long int bus_fault_address;
unsigned long int memmanage_fault_address;

bus_fault_address = S32_SCB->BFAR;
memmanage_fault_address = S32_SCB->MMFAR;
cfsr = S32_SCB->CFSR;

stacked_r0 = ((unsigned long) hardfault_args[0]);
stacked_r1 = ((unsigned long) hardfault_args[1]);
stacked_r2 = ((unsigned long) hardfault_args[2]);
stacked_r3 = ((unsigned long) hardfault_args[3]);
stacked_r12 = ((unsigned long) hardfault_args[4]);
stacked_lr = ((unsigned long) hardfault_args[5]);
stacked_pc = ((unsigned long) hardfault_args[6]);
stacked_psr = ((unsigned long) hardfault_args[7]);

printf("[HardFalt report]\r\n");
printf("- Stack frame:\r\n");
printf("R0 = 0x%lx\r\n",stacked_r0);
printf("R1 = 0x%lx\r\n",stacked_r1);
printf("R2 = 0x%lx\r\n",stacked_r2);
printf("R3 = 0x%lx\r\n",stacked_r3);
printf("R12 = 0x%lx\r\n",stacked_r12);
printf("LR = 0x%lx\r\n",stacked_lr);
printf("PC = 0x%lx\r\n",stacked_pc);
printf("PSR = 0x%lx\r\n",stacked_psr);
printf("- FSR/FAR:\r\n");
printf("CFSR = 0x%lx\r\n",cfsr);
printf("HFSR = 0x%lx\r\n",S32_SCB->HFSR);
printf("DFSR = 0x%lx\r\n",S32_SCB->DFSR);
printf("AFSR = 0x%lx\r\n",S32_SCB->AFSR);

if(cfsr & 0x0080)
printf("MMFAR = 0x%lx\r\n",memmanage_fault_address);
if(cfsr & 0x8000)
printf("BFAR = 0x%lx\r\n",bus_fault_address);
printf("- Misc\r\n");
printf("LR/EXC_RETURN = 0x%x\r\n",lr_value);