2019-03-24 09:25 AM
I am using ..\Applications\LibJPEG\LibJPEG_Decoding example and it opens a single jpg-file as it should, but how to modify the code to show several files (one after another). All I get is the first picture.
Repository\STM32Cube_FW_F7_V1.15.0\Projects\STM32746G-Discovery\Applications\LibJPEG\LibJPEG_Decoding\MDK-ARM
As a last hope I tried this test code. Both files work when I try them separately but not in the same code like this.
/* Includes ------------------------------------------------------------------*/
#include "main.h"
//480x272
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
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];
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();
/* 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();
while (1)
{
//FATFS_UnLinkDriver(SDPath);
/*##-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)
{
/*##-4- Open the JPG image with read access ############################*/
if(f_open(&MyFile, "test1.jpg", FA_READ) == FR_OK)
{
}
}
}
/*##-5- Decode the jpg image file ##########################################*/
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
/*##-4- Close the JPG image ################################################*/
f_close(&MyFile);
FATFS_UnLinkDriver(SDPath);
HAL_Delay(5000);
/*##-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)
{
/*##-4- Open the JPG image with read access ############################*/
if(f_open(&MyFile, "test2.jpg", FA_READ) == FR_OK)
{
}
}
}
/*##-5- Decode the jpg image file ##########################################*/
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
/*##-4- Close the JPG image ################################################*/
f_close(&MyFile);
FATFS_UnLinkDriver(SDPath);
HAL_Delay(5000);
}
}
Solved! Go to Solution.
2019-03-25 12:27 PM
That example is not very good. It is not clear what is needed to use several files. But here is what I did and it seems to work.
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[3048];
uint32_t offset = 0;
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, "test1.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, "test2.jpg", FA_READ) == FR_OK)
{
}
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
HAL_Delay(2000);
offset = 0;
line_counter = 271;
}
}
}
f_close(&MyFile);
}
2019-03-24 10:41 PM
You can open and close files multiple times WITHOUT repeatedly Linking the driver and mounting the volume.
Any issue you have need to be addressed in the jpeg_decode and callback side, especially any global variables they have dependencies on. The best move would be to have all that stuff in an object that you can readily reinitialize.
2019-03-25 02:58 AM
I have tried all kinds of code I could think of, and none of them work. Opening and closing seems to work, but I can see only the first image.
This is my latest again
while (1)
{
if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
{
if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK)
{
if(f_open(&MyFile, "test1.jpg", FA_READ) == FR_OK)
{
}
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
HAL_Delay(2000);
// f_close(&MyFile);
if(f_open(&MyFile, "test2.jpg", FA_READ) == FR_OK)
{
}
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
}
}
HAL_Delay(2000);
f_close(&MyFile);
}
2019-03-25 12:27 PM
That example is not very good. It is not clear what is needed to use several files. But here is what I did and it seems to work.
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[3048];
uint32_t offset = 0;
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, "test1.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, "test2.jpg", FA_READ) == FR_OK)
{
}
jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);
HAL_Delay(2000);
offset = 0;
line_counter = 271;
}
}
}
f_close(&MyFile);
}