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-03 06:39 AM
Examine the stacked state, registers, core, and then look at the faulting instruction(s).
Use a Hard Fault Handler that displays/decodes the failing state. At a guess I'd say your stack size is insufficient.2012-12-03 09:36 PM
2012-12-03 10:47 PM
From Joseph Yiu's book and forum postings
http://blog.frankvh.com/2011/12/07/cortex-m3-m4-hard-fault-handler/
For the stack, start by seeing how big it currently is, and what your code is allocating. If you have several 512 byte buffers as local/automatic variables, and only a 1K stack allocation things will clearly go pear shaped. Understand your code. Fill the stack with a suitable marker character, and see how much is used when it faults by looking at a memory view in the debugger. You can also write code to quantify this.2012-12-13 10:37 PM
I am getting Hard Fault in my program occasionally.
=>could the Clock provided to image sensor be the problem , i.e. some thing like synchronization between Pclk or Vsync etc. => could be the function or variable Scope be the problem? if any of above statement can be the problem then why the error occurs at random time? After debugging I came across the function during which hard fault occurs i.e frame_capture() . in this function I am just enabling DCMI and wait for a frame to be received , now the Hard Fault occurs always when I was leaving the frame_capture() function . like this .... while(1) { fopen(......); frame_capture(); // Hard Fault occurs when I am leaving from this function Usart_send(usart2,'J'); fwrite(buffer); fclose(....); } and void frame_capture() { .... .... .... .... Usart_send(Usart2,'L'); } i receive L on the hyper terminal just before Hard fault handler, but not J. and when ever Hard fault handler occurs this happens always. and the Core register values at the time of hard fault are R0 0x40004400 R1 0x00000040 R2 0xffffffbf R3 0x000000c0 R4 0x83177217 R5 0x86177316 R6 0x82127316 R7 0x20000a6c R8 0x00000000 R9 0x200005bc R10 0x00000000 R11 0x00000000 R12 0x50003000 R13(sp) 0x20014ba8 R14(LR) 0x080028eb R15(PC) 0x080028ec I get this values during debugging session. when hard fault occurs i stop the program and these values apears. I do it several times and one thing i noticed is R2 every time = 0xffffffbf..... any help? Regards haris2012-12-13 11:27 PM
I am getting Hard Fault in my program occasionally.
...
if any of above statement can be the problem then why the error occurs at random time?
That sounds suspiciously like stack overflow. As interrupt handlers involve stack operations, the 'overflow' is driven by such events. And in case of external communication (like USB, ETH, UART), it appears to be random.
2012-12-14 06:39 AM
Look at the assembler code at/around the faulting instructions.
Look at the stack, and if it is in a region it should be. Make sure you capture code isn't overwriting critical code or data. DMA can write all over things very easily.2012-12-18 09:03 PM
actually I want a character array of length 5, that will increment like integer e.g
00001 will be equal to 0x30 0x30 0x30 0x30 0x31 and 00002 will be equal to 0x30 0x30 0x30 0x30 0x32 etc name=['0','0','0','0','0'] I want this because file open function requires a string, a character array like this if ((HCD_IsDeviceConnected(&USB_OTG_Core) != 1) || (f_open(&file, name, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)) is there any problem with that? where name is global character array initialize with '0's. void name_rec() { name[4]=name[4]+1; if(name[4]>'9') { name[4]='0'; name[3]=name[3]+1; if(name[3]>'9') { name[3]='0'; name[2]=name[2]+1; if(name[2]>'9') { name[2]='0'; name[1]=name[1]+1; if(name[1]>'9') { name[1]='0'; name[0]=name[0]+1; if(name[0]>'9') { name[0]='0'; } } } } } } i am calling this function after every file write.I got Hard fault Occasionally when I use name in f_open function. it might be that hard fault occurring due to some other reason (as previous in this thread but somehow i manage to get rid of it). but on contrary, when I change character array name[] with ''haris'' my program runs well and no error occurs even after 1500 write, as below if ((HCD_IsDeviceConnected(&USB_OTG_Core) != 1) || (f_open(&file, ''haris'', FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)) where as I am still calling the function name_rec() in my routine. (only change the string in f_open()). what can be the problem?2012-12-19 06:21 AM
what can be the problem?
NUL termination of the string in C?2012-12-19 11:11 PM
sorry I didnt mention in my last post. I am already doing that with null character . like name[6]={'0','0','0','0','0','\0'}
if i use ''haris'' for file name it works fine, but with variable incrementing character array the fault comes. but the fault is occurring on the same point as i describe in my second last post. while(1) { fopen(......); frame_capture(); // Hard Fault occurs when I am leaving from this function Usart_send(usart2,'J'); fwrite(buffer); fclose(....); } and void frame_capture() { .... .... .... .... Usart_send(Usart2,'L'); }i receive L on the hyper terminal just before Hard fault handler, but not J. and when ever Hard fault handler occurs this happens always.
1-are the registers r0 r1...r12 are stack register? if so, then I have put marker addresses in these registers and at the time of fault occurring some of the stack registers are not changed.(is this mean that i have no problem of stack over flow?) 2- how can i came to know faulting instruction? after the hardfault occurs my program goes into infinite while, if i stops the debugger and see my pointer in dissasembler it correspond to pointer in C file at while(1), now if i go up in dissasembler the cursor in ISR code of ----_it.c goes up with it on one to one correspondence. I want to ask that if I goes up further in dissassembler then does it mean that the instruction above the ISR will be the instruction from where this interrupt generated? 3-the link about hardfault(the from frank wespage) , i tried it, but I can not manage to incorporate it with stm32Fxxx.s i got error about opcoeds like handler_args is not defines etc how can i use that function in keil? 4- how can I detect the faulting insrtuction? 5-my capture code is not overwriting,as i use DMA in circular mode, and I verifies it with checking memory afetr 32768 bytes ,it remain preserve from which I had initilaize with. finally i want to make clear things that i got error every time when frame_capture()is called, although the occuring of fault is at random,but when ever it occurs I am in frame_capture() or u can say leaving from it as u can see in my second last post. thanks for ur support