Skip to main content
LMI2
Senior III
June 6, 2018
Question

Hard fault after first JPG with 746D

  • June 6, 2018
  • 2 replies
  • 1557 views
Posted on June 06, 2018 at 21:40

I am building code to show all jpeg images in SD card and print their names. I use the STM32F746 Discovery. The jpeg decoder crashes after the first image. The Jpg decoder stays at hard fault loop. If I comment the jpeg_decode(&viili, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction); line, code works but of course no images are shown.

Main.c looks like this

/* Includes ------------------------------------------------------------------*/ #include 'main.h'  FATFS SDFatFs; /* File system object for SD card logical drive */ FIL viili; /* File object */ FRESULT res; DIR dir; static FILINFO fno;  char SDPath[4]; /* SD card logical drive path */  RGB_typedef *RGB_matrix;  uint8_t _aucLine[2048]; uint32_t offset = 0; uint32_t line_counter = 239;  /* 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();   HAL_Init();    /* Configure the system clock to 200 MHz */  SystemClock_Config();    /*##-1- LCD Configuration ##################################################*/   LCD_Config();   /*##-2- Link the micro SD disk I/O driver ##################################*/  if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)  {  /*##-3- Register the file system object to the FatFs module ##############*/  if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)  {  res = f_findfirst(&dir, &fno, '', 'ima*.jpg'); /* Start to search for photo files */ res = f_open(&viili,&fno.fname[0] , FA_READ);  while (res == FR_OK && fno.fname[0])  { /* Repeat while an item is found */  /*##-5- Decode the jpg image file ##########################################*/ jpeg_decode(&viili, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);  /*##-4- Close the JPG image ################################################*/  f_close(&viili);  BSP_LCD_DisplayStringAtLine(2, (uint8_t*)fno.fname); HAL_Delay(2000);  res = f_findnext(&dir, &fno); /* Search for next item */ }  f_close(&viili);  }  }  /* Infinite loop */  while (1)  {  } } �?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    2 replies

    AvaTar
    Senior III
    June 7, 2018
    Posted on June 07, 2018 at 07:44

    I think you will need to look into the jpeg_decode() function and the SCB fault registers, not much to see on the top-level code.

    But my guess would be a stack overflow.

    LMI2
    LMI2Author
    Senior III
    June 7, 2018
    200806CGIL2
    AvaTar
    Senior III
    June 7, 2018
    Posted on June 07, 2018 at 13:01

    You mean I should increase stack space. How do you do it with Keil?

    I don't know if it's a stack overflow. But the jpeg format is based upon spectral data, and decoding involves a conversion to pixel data. You bet this process involves some memory for intermediary buffers.

    I suggest to investigate/debug it first, and confirm the cause.

    For how to set a project's stack size, please consult the Keil help/tutorials. I don't use uVision.

    For the jpeg_decode(), I would check the documentation, and examples provided.

    Does the call ever enter your provided callback function ?

    I am not sure if my f_open is in the correct place or if I should open each image separately.

    I strongly suspect the latter. Otherwise the file object pointer is dangling for following image files.

    LMI2
    LMI2Author
    Senior III
    June 10, 2018
    Posted on June 10, 2018 at 23:59

    The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6vS&d=%2Fa%2F0X0000000by5%2FDWFTwy79_ODAAqH345WJaoW5GFDLk.5dAEh7yc2cqmo&asPdf=false