5 years, 6 months ago.

Problem to display a bmp image using a STM32F413.

Hello everyone I have a question related to STM32F413. I want to show an image using your LCD but the system shows the image with a distortion and I tried a different method with no results. Can you you help me with this?.

/media/uploads/jarain78/rsz_20181025_122913.jpg

This is my code:

main

#include "mbed.h"
#include "stm32f413h_discovery.h"
#include "stm32f413h_discovery_ts.h"
#include "stm32f413h_discovery_lcd.h"
//#include "stm32f413h_discovery_sd.h"
#include "tensor.hpp"
#include "image.h"
#include "models/deep_mlp.hpp"

#include "FATFileSystem.h"
#include "F413ZH_SD_BlockDevice.h"

Serial pc(USBTX, USBRX, 115200);

F413ZH_SD_BlockDevice bd;
FATFileSystem fs("fs");

void init_lcd();
void show_message();
void list_files(DIR* dir);


//--------------------------------------------------------------
// Read BMP File
void drawImage(char * name, uint8_t x, uint8_t y){
    int fileSize;
    char * buffer;
    FILE *Image = fopen(name, "r+");  // open the bmp file
  
    //obtain file size:
    fseek (Image , 0 , SEEK_END);
    fileSize = ftell (Image);
    rewind (Image);
    
    // allocate memory to contain the whole file:
    buffer = (char*) malloc (sizeof(char)*fileSize);
    
    // copy the file into the buffer:
    fseek (Image, 0 , SEEK_SET );  
    // set SD file data start position    
    fread (buffer,1,fileSize,Image);


    //Draw image
    //BSP_LCD_DrawBitmap(0, 0, (uint8_t *)buffer);
    BSP_LCD_DrawBitmap(0, 0, (uint8_t *)buffer);
    fclose (Image);

    //Free allocated memory
    free (buffer);     
}


int main()
{

    printf("--------------------------------------------------------------\n");
    char * file_to_open = "/fs/smile.bmp";

    //ON_ERR(bd.init(), "SDBlockDevice init ");
    //ON_ERR(fs.mount(&bd), "Mounting the filesystem on \"/fs\". ");

    bd.init();
    printf("SDBlockDevice init \n");
    fs.mount(&bd);
    printf("Mounting the filesystem on \"/fs\". \n");

    init_lcd();  

    FILE* fd = fopen(file_to_open, "rb");
    DIR* dir = opendir("/fs/");

    list_files(dir);

    drawImage("/fs/smile.bmp", 0, 0);
}


void init_lcd(){

    BSP_LCD_Init();

    /* Touchscreen initialization */
    if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) {
        printf("BSP_TS_Init error\n");
    }
 BSP_LCD_Clear(LCD_COLOR_WHITE);
}

void show_message(){
        /* Clear the LCD */
    BSP_LCD_Clear(LCD_COLOR_WHITE);

    /* Set Touchscreen Demo1 description */
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40);
    BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
    BSP_LCD_SetBackColor(LCD_COLOR_GREEN);
    BSP_LCD_SetFont(&Font16);
    BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Emotion Class Demo", CENTER_MODE);
}

1 Answer

5 years, 5 months ago.

Have you seen this question? Make sure the bitmap format for the file on the SD card is supported by the library.

Accepted Answer