2012-12-02 09:42 PM
hi:
after receiving DCMI data i am writing it to USB. after writing some files Hard fault handler occurs... why is it so? Firstly I capture the DCMI data to buffer, after one frame capture I stop the DCMI and start to transmit data over serial. I repeat this in while(1) loop. e.g while(1) { frame_capture(); //when frame is capture Send_usart(Buffer); } // it works fine it keep on running secondly, I capture a single frame, then write it on USB mass storage device, repeatedly. e.g like this frame_capture(); while(1) { fopen(......); fwrite(buffer); fclose(....); } // it works also fine. it keep on running but whne I combine both codes , Hard fault Handler occurs. like this while(1) { frame_capture(); fopen(......); fwrite(buffer); fclose(....); } // i get error after random file write after at 15, at 90 at 110 etc // some time i even go 400 write file but then fault handler occurs. why is this happening? I also have set interrupt priority differently. but no effect !! thanks #usb-mass-storage #hard-falt-hanlder #dcmi2012-12-20 05:21 AM
Please go look at some books and manuals on the M3 core.
Joseph Yiu has a good book on the core, and has posted proper Hard Fault handlers (ie not a while(1) loop), which decode core registers, and dig back through the stacked state. You need to look at the faulting PC, and LR. Look at the instructions around these addresses to know where and what subroutine the fault occurred in. Use the registers to understand what the instructions were doing/accessing. R0..R15 are processor registers, R13 (SP) is the stack pointer by convention, R14 (LR), R15 (PC) In Keil startup.sHardFault_Handler PROC
; Determine correct stack
TST lr, #4
ITE EQ
MRSEQ R0, MSP ; Read MSP (Main)
MRSNE R0, PSP ; Read PSP (Process)
EXTERN hard_fault_handler_c
B hard_fault_handler_c
ENDP
In app.c
void hard_fault_handler_c(unsigned int * hardfault_args)
{
printf (''[Hard Fault]
'');
printf (''r0 = %08X, r1 = %08X, r2 = %08X, r3 = %08
X'',
hardfault_args[0], hardfault_args[1], hardfault_args[2], hardfault_args[3]);
printf (''r12= %08X, lr = %08X, pc = %08X, psr= %08
X'',
hardfault_args[4], hardfault_args[5], hardfault_args[6], hardfault_args[7]);
printf (''bfar=%08X, cfsr=%08X, hfsr=%08X, dfsr=%08X, afsr=%08
X'',
*((volatile unsigned long *)(0xE000ED38)),
*((volatile unsigned long *)(0xE000ED28)),
*((volatile unsigned long *)(0xE000ED2C)),
*((volatile unsigned long *)(0xE000ED30)),
*((volatile unsigned long *)(0xE000ED3C)) );
while(1);
return;
}
2012-12-25 08:15 PM
thanks clive
I have resolved the issue by replacing the frame_capture() function by its definition. So i am not calling the frame_capture() any more, I just put the code where i call this function. while(1) { fopen(); // code of frame capture ... ... ... fwrite(); fclose(); } But i am still interested why the error was occurring at the first place. I will do the steps u told, and update the status. thanks.2012-12-28 05:52 AM