2018-08-05 06:16 AM
2018-08-05 06:49 AM
Start by having a proper Hard Fault handler so you can identify the code that is faulting, and the register/stack content.
Make sure you have a sufficiently large stack, and you understand how much of it is being used.
2018-08-05 06:57 AM
HI THANK YOU I'M DOUBLE THE STACK AND IT DID NOT PREVENT FROM HAPPENING -i using the iar workbench so I TRIED TO CATCH WITH IAR
Can you suggest to me what function to write in hard fault?
2018-08-05 07:01 AM
and it seemed to happen when I'm using the printf or STRCAT function-I not sure
2018-08-05 07:13 AM
For strings make sure you understand the lengths, and that there is NUL termination.
In Keil we do this, changing startup_stm32xxxx.s to have calling code
HardFault_Handler\
PROC
EXPORT HardFault_Handler
; Determine correct stack
TST lr, #4
ITE EQ
MRSEQ R0, MSP ; Read MSP (Main)
MRSNE R0, PSP ; Read PSP (Process)
MOV R1, R4
MOV R2, R5
MOV R3, R6
EXTERN hard_fault_handler_c
B hard_fault_handler_c
ENDP
//****************************************************************************
void hard_fault_handler_c(unsigned int * hardfault_args, unsigned int r4, unsigned int r5, unsigned int r6)
{
printf ("\n[Hard Fault]\n"); // After Joseph Yiu
printf ("r0 = %08X, r1 = %08X, r2 = %08X, r3 = %08X\n",
hardfault_args[0], hardfault_args[1], hardfault_args[2], hardfault_args[3]);
printf ("r4 = %08X, r5 = %08X, r6 = %08X, sp = %08X\n",
r4, r5, r6, (unsigned int)&hardfault_args[8]);
printf ("r12= %08X, lr = %08X, pc = %08X, psr= %08X\n",
hardfault_args[4], hardfault_args[5], hardfault_args[6], hardfault_args[7]);
printf ("bfar=%08X, cfsr=%08X, hfsr=%08X, dfsr=%08X, afsr=%08X\n",
*((volatile unsigned int *)(0xE000ED38)),
*((volatile unsigned int *)(0xE000ED28)),
*((volatile unsigned int *)(0xE000ED2C)),
*((volatile unsigned int *)(0xE000ED30)),
*((volatile unsigned int *)(0xE000ED3C)) );
while(1);
}
//****************************************************************************
2018-08-05 08:10 AM
Thank you ,Is there something that is concern on stm32f103zd ?
2018-08-05 08:19 AM
The causes a fairly constrained, and not specific to the STM32F103ZD
Make sure you don't have any errant pointers, or overflow buffers or local variables. Add sanity checking on pointer.
2018-08-05 08:25 AM
Thank for answering me on sunday-What register suppose to show me the problems?
2018-08-05 08:34 AM
You're going to be interested in the PC, the instructions there and immediately before and the registers those instructions are acting upon. They will provide the context of the failure/fault.