AnsweredAssumed Answered

STM32F7 DISCO : Load Multiple Buffers with .bmp after drawing Problem

Question asked by Noto.Federico on Jan 12, 2016
Latest reply on Dec 14, 2017 by mich.lei
Hello, I was trying to load multiple buffers with extension .bmp images, but when charging finished and prepared to begin the sample calling each image buffer for each content, I found that nothing happened.
I tried to reduce the number of images displayed to two, using the same methodology. Load the picture 1 Buffer A adress in the image memory 1. After Image 2 on Buffer B  in the memory adress 2. And last show stored content in the Buffer A, which showed me the image 1, but somewhat corrupt. If on the contrary had shown the contents of Buffer B, it shows the image accordingly.

PD: If I keep the picture 1 in buffer A and immediately show its content, it works. But, underlining what I said earlier, if I load many buffers, and decided to show the content of any buffer other than the last loaded, or does not show me anything, or displays corrupt image ..


/**
  ******************************************************************************
  * @file    Display/LTDC_PicturesFromSDCard/Src/main.c
  * @author  MCD Application Team
  * @version V1.0.2
  * @date    18-November-2015
  * @brief   This file provides main program functions
  ******************************************************************************
  * @attention
  *
  * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
 
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/** @addtogroup STM32F7xx_HAL_Applications
  * @{
  */
 
/** @addtogroup LTDC_PicturesFromSDCard
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
FATFS SD_FatFs;  /* File system object for SD card logical drive */
char SD_Path[4]; /* SD card logical drive path */
char* pDirectoryFiles[MAX_BMP_FILES];
uint8_t  ubNumberOfFiles = 0;
uint32_t uwBmplen = 0;
 
/* Internal Buffer defined in SDRAM memory */
uint8_t *uwInternelBuffer;
uint8_t *uwInternelBuffe;
/* Private function prototypes -----------------------------------------------*/
static void LCD_Config(void);
static void SystemClock_Config(void);
static void Error_Handler(void);
static void CPU_CACHE_Enable(void);
 
/* Private functions ---------------------------------------------------------*/
 
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t counter = 0, transparency = 0;
  uint8_t str[30];
  uwInternelBuffer  = (uint8_t *)0xC026CFC0;
  uwInternelBuffe =   (uint8_t *)0xC0260000;
 
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();
 
  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
   
  /* Configure the system clock to 200 MHz */
  SystemClock_Config();
   
  /* Configure LED1 */
  BSP_LED_Init(LED1);
   
  /*##-1- Configure LCD ######################################################*/
  LCD_Config();
   
  /* Configure TAMPER Button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);  
 
  BSP_SD_Init();
 
  while(BSP_SD_IsDetected() != SD_PRESENT)
  {
        BSP_LCD_SetTextColor(LCD_COLOR_RED);
        BSP_LCD_DisplayStringAtLine(8, (uint8_t*)"  Please insert SD Card                  ");
  }
   
  BSP_LCD_Clear(LCD_COLOR_BLUE);
   
  /*##-2- Link the SD Card disk I/O driver ###################################*/
  if(FATFS_LinkDriver(&SD_Driver, SD_Path) == 0)
  {
    /*##-3- Initialize the Directory Files pointers (heap) ###################*/
    for (counter = 0; counter < MAX_BMP_FILES; counter++)
    {
      pDirectoryFiles[counter] = malloc(MAX_BMP_FILE_NAME);
      if(pDirectoryFiles[counter] == NULL)
      {
        /* Set the Text Color */
        BSP_LCD_SetTextColor(LCD_COLOR_RED);
         
        BSP_LCD_DisplayStringAtLine(8, (uint8_t*)"  Cannot allocate memory ");
         
        while(1)
        {
        }      
      }
    }
     
    /* Get the BMP file names on root directory */
    ubNumberOfFiles = Storage_GetDirectoryBitmapFiles("/Movie", pDirectoryFiles);
     
    if (ubNumberOfFiles == 0)
    {
      for (counter = 0; counter < MAX_BMP_FILES; counter++)
      {
        free(pDirectoryFiles[counter]);
      }
      BSP_LCD_DisplayStringAtLine(8, (uint8_t*)"  No Bitmap files...      ");
      while(1)
      {
      }
    }
  }
  else
  {
    /* FatFs Initialization Error */
    Error_Handler();   
  }
  while(1)
  {    
    counter = 7;
     
    while ((counter) < ubNumberOfFiles)
    {
      /* Step1 : Display on Foreground layer -------------------------------*/
      /* Format the string */
      sprintf ((char*)str, "Movie/%-14.14s", pDirectoryFiles[counter]);
       
      if (Storage_CheckBitmapFile((const char*)str, &uwBmplen) == 0)
      
        /* Format the string */       
        sprintf ((char*)str, "Movie/%-14.14s", pDirectoryFiles[counter]);
         
        /* Set LCD foreground Layer */
        BSP_LCD_SelectLayer(1);
         
        /* Open a file and copy its content to an internal buffer */
        Storage_OpenReadFile(uwInternelBuffe, (const char*)str);
         
 
                ///////////////////////////////////////////////
        counter ++;
                 
                if (Storage_CheckBitmapFile((const char*)str, &uwBmplen) == 0)
      
        /* Format the string */       
        sprintf ((char*)str, "Movie/%-13.13s", pDirectoryFiles[counter]);
         
        /* Set LCD foreground Layer */
        BSP_LCD_SelectLayer(1);
         
        /* Open a file and copy its content to an internal buffer */
        Storage_OpenReadFile(uwInternelBuffer, (const char*)str);
            };
                 
                             
            ////////////////////////////////////////////////////// 
                 
                 
 
                /* Write bmp file on LCD frame buffer */
        BSP_LCD_DrawBitmap(0, 0, uwInternelBuffe); 
         
                 
                 
                 
                 
                 
                 
                 
                 
                 
                 
        /* Configure the transparency for background layer : Increase the transparency */
        for (transparency = 0; transparency < 255; (transparency++))
        {       
          BSP_LCD_SetTransparency(1, transparency);
           
          /* Insert a delay of display */
          HAL_Delay(2);
        }
         
        /* Wait for tamper button pressed */
        while (BSP_PB_GetState(BUTTON_TAMPER) == RESET)
        {
        }
         
        /* Configure the transparency for foreground layer : decrease the transparency */
        for (transparency = 255; transparency > 0; transparency--)
        {       
          BSP_LCD_SetTransparency(1, transparency);
           
          /* Insert a delay of display */
          HAL_Delay(2);
        }
 
        /* Clear the Foreground Layer */
        BSP_LCD_Clear(LCD_COLOR_BLACK);
         
        /* Jump to the next image */ 
        counter++;
         
        /* Step2 : Display on Background layer -----------------------------*/
        /* Format the string */ 
        sprintf ((char*)str, "Movie/%-13.13s", pDirectoryFiles[counter]);
         
        if ((Storage_CheckBitmapFile((const char*)str, &uwBmplen) == 0) || (counter < (ubNumberOfFiles)))
        {        
          /* Connect the Output Buffer to LCD Background Layer  */
          BSP_LCD_SelectLayer(0);
           
          /* Format the string */ 
          sprintf ((char*)str, "Movie/%-13.13s", pDirectoryFiles[counter]);
           
          /* Open a file and copy its content to an internal buffer */
          Storage_OpenReadFile(uwInternelBuffer, (const char*)str);
           
          /* Write bmp file on LCD frame buffer */
          BSP_LCD_DrawBitmap(0, 0, uwInternelBuffer);
           
          /* Configure the transparency for background layer : decrease the transparency */ 
          for (transparency = 0; transparency < 255; (transparency++))
          {       
            BSP_LCD_SetTransparency(0, transparency);
             
            /* Insert a delay of display */
            HAL_Delay(2);
          }
           
          /* wait for tamper button pressed */
          while (BSP_PB_GetState(BUTTON_TAMPER) == RESET)
          {
          }
           
          /* Step3 : -------------------------------------------------------*/             
          /* Configure the transparency for background layer : Increase the transparency */
          for (transparency = 255; transparency > 0; transparency--)
          {       
            BSP_LCD_SetTransparency(0, transparency);
             
            /* Insert a delay of display */
            HAL_Delay(2);
          }
 
          /* Clear the Background Layer */
          BSP_LCD_Clear(LCD_COLOR_BLACK);
 
          counter++;  
        }
        else if (Storage_CheckBitmapFile((const char*)str, &uwBmplen) == 0)
        {
          /* Set the Text Color */
          BSP_LCD_SetTextColor(LCD_COLOR_RED);
           
          BSP_LCD_DisplayStringAtLine(7, (uint8_t *) str);       
          BSP_LCD_DisplayStringAtLine(8, (uint8_t*)"    File type not supported. ");
          while(1)
          {
          }     
        }       
      
    }     
  }
}
 
/**
  * @brief  LCD configuration
  * @param  None
  * @retval None
  */
static void LCD_Config(void)
{
  /* LCD Initialization */
  BSP_LCD_Init();
 
  /* LCD Initialization */
  BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
  BSP_LCD_LayerDefaultInit(1, LCD_FB_START_ADDRESS+(BSP_LCD_GetXSize()*BSP_LCD_GetYSize()*4));
 
  /* Enable the LCD */
  BSP_LCD_DisplayOn();
   
  /* Select the LCD Background Layer  */
  BSP_LCD_SelectLayer(0);
 
  /* Clear the Background Layer */
  BSP_LCD_Clear(LCD_COLOR_BLACK); 
   
  /* Select the LCD Foreground Layer  */
  BSP_LCD_SelectLayer(1);
 
  /* Clear the Foreground Layer */
  BSP_LCD_Clear(LCD_COLOR_BLACK);
   
  /* Configure the transparency for foreground and background :
     Increase the transparency */
  BSP_LCD_SetTransparency(0, 0);
  BSP_LCD_SetTransparency(1, 100);
}
 
/**
  * @brief  This function is executed in case of error occurrence.
  * @param  None
  * @retval None
  */
static void Error_Handler(void)
{
  /* Turn LED1 on */
  BSP_LED_On(LED1);
  while(1)
  {
  }
}
 
/**
  * @brief  System Clock Configuration
  *         The system Clock is configured as follow :
  *            System Clock source            = PLL (HSE)
  *            SYSCLK(Hz)                     = 200000000
  *            HCLK(Hz)                       = 200000000
  *            AHB Prescaler                  = 1
  *            APB1 Prescaler                 = 4
  *            APB2 Prescaler                 = 2
  *            HSE Frequency(Hz)              = 25000000
  *            PLL_M                          = 25
  *            PLL_N                          = 400
  *            PLL_P                          = 2
  *            PLL_Q                          = 8
  *            VDD(V)                         = 3.3
  *            Main regulator output voltage  = Scale1 mode
  *            Flash Latency(WS)              = 6
  * @param  None
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
  RCC_OscInitTypeDef RCC_OscInitStruct;
  HAL_StatusTypeDef ret = HAL_OK;
 
  /* Enable HSE Oscillator and activate PLL with HSE as source */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 25;
  RCC_OscInitStruct.PLL.PLLN = 400; 
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 8;
 
  ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
  if(ret != HAL_OK)
  {
    while(1) { ; }
  }
 
  /* Activate the OverDrive to reach the 200 MHz Frequency */
  ret = HAL_PWREx_EnableOverDrive();
  if(ret != HAL_OK)
  {
    while(1) { ; }
  }
   
  /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */
  RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; 
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
 
  ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
  if(ret != HAL_OK)
  {
    while(1) { ; }
  }
}
 
/**
  * @brief  CPU L1-Cache enable.
  * @param  None
  * @retval None
  */
static void CPU_CACHE_Enable(void)
{
  /* Enable I-Cache */
  SCB_EnableICache();
 
  /* Enable D-Cache */
  SCB_EnableDCache();
}
 
#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
  /* Infinite loop */
  while (1)
  {
  }
}
#endif
 
/**
  * @}
  */
 
/**
  * @}
  */
   
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Outcomes