cancel
Showing results for 
Search instead for 
Did you mean: 

Usb mass storage Hard fault Handler?

its
Associate II
Posted on December 03, 2012 at 06:42

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 #dcmi
12 REPLIES 12
Posted on December 20, 2012 at 14:21

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.s

HardFault_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;
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
its
Associate II
Posted on December 26, 2012 at 05:15

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.

sangilipandian
Associate II
Posted on December 28, 2012 at 14:52

Hi  tech.haris,

         I'm newbie to STM32. I need your help. I'm also developing a project that is similar to your's. So i need a help for how did you initialize/deinitialize the camera and captured a frame from it?. So please could you share your code ?.. It would be more helpful for me. 

Thanks in Advance.