cancel
Showing results for 
Search instead for 
Did you mean: 

Hard fault from full screen jpg images with STM32F746 Discovery

LMI2
Lead

Smaller images work now but when I try full screen images, I get a hard fault. I have changed dimension in main.h.

I have used code from repository/application with small modifications

FATFS SDFatFs;  /* File system object for SD card logical drive */
FIL MyFile;     /* File object */
char SDPath[4]; /* SD card logical drive path */
RGB_typedef *RGB_matrix;  
uint8_t   _aucLine[2048];
//uint8_t   _aucLine[4048];
uint32_t  offset = 0;
//uint32_t line_counter = 239;
uint32_t line_counter = 271;
/* Private function prototypes -----------------------------------------------*/
static void SystemClock_Config(void);
static void LCD_Config(void);
static uint8_t Jpeg_CallbackFunction(uint8_t* Row, uint32_t DataLength);
static void CPU_CACHE_Enable(void);
 
/* Private functions ---------------------------------------------------------*/
 
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
 
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();
  
  /* Configure the system clock to 200 MHz */
  SystemClock_Config();
  
  /*##-1- LCD Configuration ##################################################*/   
  LCD_Config();
//offset = 0;
//line_counter = 271;
  if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
  {
 
    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
    {
 while (1)
{
       if(f_open(&MyFile, "leif.jpg", FA_READ) == FR_OK)
       {
       }
			   jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
			 	HAL_Delay(2000);
  offset = 0;
line_counter = 271;
			       if(f_open(&MyFile, "61.jpg", FA_READ) == FR_OK)
       {
       }
			 		jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
			 	HAL_Delay(2000);
			 offset = 0;
line_counter = 271;
     }
	 }
   }
		   f_close(&MyFile);
}

3 REPLIES 3
Bob S
Principal

As is the answer to most all questions about "why does my code hard fault" - Add code or otherwise set a breakpint in your hard fault handler. Then look at the fault registers to see what triggered the fault. It should lead you to a program counter value or memory address value. That have been several threads on this forum about this.

LMI2
Lead

Is it even possible to show full screen jpg images with STM32F746 Discovery.

By the way, does the code in the code window really look this bad. Lines wrap randomly and not much formatting left.

I would expect the decoder to be pipelined, and be able to accept and output smaller pieces.

Perhaps use a Hard Fault Handler and pin down what code specifically is faulting.

Make sure the buffers are sufficiently large, and whether the faulting code is bad, or if it has been given data/variables/pointers corrupted by a decode operation.

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          ; Registers R4-R6
                MOV     R2, R5
                MOV     R3, R6          ; sourcer32@gmail.com
 
                EXTERN  hard_fault_handler_c
                B       hard_fault_handler_c
 
                ENDP ; HardFault_Handler
 
 
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);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..