AnsweredAssumed Answered

TJpgDec and FatFs

Question asked by chuev.vladimir on Oct 26, 2015
Latest reply on Oct 29, 2015 by chuev.vladimir
I checked the code, it works when picture is in memory. But I can't make it work with MicroCD.
I rewrote the code for work with FatFs, but STM32 freezes on f_lseek() function.
There is my code, I purposely deleted all unnecessary for easy reading.

FATFS MicroSD_FAT;
char MicroSD_Path[4];
 
BYTE jdwork[3100];
typedef struct{
    void *pData;
} IODEV;
 
 
 
UINT input_func(JDEC *jd, BYTE *buff, UINT ndata){
    IODEV *dev = (IODEV *)jd->device;
    UINT rb;
    FIL *fil;
     
    if(buff){
        fil = (FIL *)dev->pData;
        f_read(fil, buff, ndata, &rb);
        return rb;
    }
     
    return (f_lseek(fil, f_tell(fil) + ndata) == FR_OK) ? ndata : 0; // Here freezes
}
 
 
// It works
UINT output_func(JDEC *jd, void *bitmap, JRECT *rect){
  uint16_t *bmp = (uint16_t *)bitmap;
  uint16_t x, y, i = 0;
  for(y = rect->top; y <= rect->bottom; y++) {
        for(x = rect->left; x <= rect->right; x++) {
         *(__IO uint16_t *)(LCD_FRAME_BUFFER + (x * 2) + (y * IMAGE_WIDTH * 2)) = (uint16_t)(bmp[i++]);
        
    }
    return 1;
}
 
 
 
int main(void){
    CPU_CACHE_Enable();
    HAL_Init();
    SystemClock_Config();
    LCD_Config();
 
    JDEC jd;
    IODEV iodev;   
    JRESULT rc;
    FIL JpegEncFile;
     
    BSP_LCD_Clear(LCD_COLOR_WHITE); // Start
   
    if(FATFS_LinkDriver(&SD_Driver, MicroSD_Path) != 0){
        while(1);
    }
    if(f_mount(&MicroSD_FAT, (TCHAR const*)MicroSD_Path, 0) != FR_OK){
        while(1);
    }
    if(f_open(&JpegEncFile, IMAGE_NAME, FA_READ) != FR_OK){
        while(1);
    }
 
 
    iodev.pData = (void *)&JpegEncFile;
   
    rc = jd_prepare(&jd, input_func, jdwork, sizeof(jdwork), &iodev);      
    if(rc){
        BSP_LCD_Clear(LCD_COLOR_LIGHTBLUE); // jd_prepare() error
        while(1);
    }
 
    rc = jd_decomp(&jd, output_func, 2);
    if(rc){
        BSP_LCD_Clear(LCD_COLOR_RED); // jd_decomp() error
        while(1);
    }
 
    while(1);
}

Outcomes