Statement of originality:

This original tutorial was created by ALINX Electronic Technology (Shanghai) Co., Ltd. (ALINX), and the copyright belongs to the company. If you want to reprint, you need to authorize and indicate the source.

Applicable board models:


The vivado project directory is “ps_hello/vivado”

The vitis project directory is “ps_sd/vitis”

This chapter introduces the use of the FatFs file system module to read the BMP pictures of the SD card and display them through DP.

1. Introduction to FatFs

FatFs is a general-purpose file system module for implementing FAT file systems in small embedded systems. The writing of FatFs follows ANSI C, so it does not depend on the hardware platform. It can be embedded into cheap microcontrollers such as 8051, PIC, AVR, SH, Z80, H8, ARM, etc. without any modification.

The application program calls the FatFs system module through the API function to control the storage devices such as the SD card.

The FatFs system provides many API functions, and we list the API functions that will be used in the following routines below.

f_mount – register/unregister a work area (Work Area)

f_open – open/create a file

f_close – close a file

f_read – read a file

f_write – write to a file

For the introduction and description of API functions, you can refer to the following website for further understanding.

Instructions and examples for each API function are given.

2. Vitis program development

1) Open the Vitis software, we have generated a sd_bmp project for everyone. Here you need to configure the properties of the BSP support package, select the xilffs item in the Board Support Package Settings, and enable the project to support the xilffs file system.

About the xilffs library is a FAT file system support package provided by Xilinx. Users can call the API functions in the library to realize the

Operation of SD/eMMC and other devices. The xilffs library mainly includes FAT file system (File System Files) and driver layer files (Glue Layer Files).

2) For the introduction and application of the xilffs library, you can refer to the following Xilinx official website link:

3) Next, let’s look at the engineering code of sd_bmp. In the project code, we need to read out the image data in bmp format stored in the SD card, remove the image header and put it in the display buffer of DP, and then realize the display of the image on the DP display.

4) In the bmp.c file, we added a bmp_read function. In this function, first use the f_open function to open a bmp image file in the SD card. Then read the first 54 bytes of this file, because the first 54 bytes of the BMP image file are image header files, which contain the pixel size information of the image. Then read the image data line by line and store them in the frame display buffer of DP.

Since the storage of BMP is upside down, the order is adjusted in the bmp_read function and stored in the frame buffer.

5) At the same time, we have also prepared the BMP file header structure and image header settings for some common resolutions, which are placed in the bmp.h file.

6) Combined with the previous display of the kitten picture, save the kitten picture in bmp format and save it to the SD card. In the bmp_write function, combine the bmp header and bmp data and save it to the SD card.

7) In the main function, call the bmp_read function to read an image from the SD card to the DP display buffer for storage. The file name 1.bmp of the BMP image here needs to be the same as the file name stored in the SD card. Use bmp_write to write the kitten picture to the SD card.

3. On-Board Verification

1) First, you need to save a 1920*1080 pixel, 24bit BMP file to the SD card. The file name is 1.bmp (the file is in the project directory). When the development board is powered off, insert the SD card into the deck .

2) Connect the development board to the DP display, and then power on. After the downloaded program runs, we can display the image of the 1.bmp file stored in the SD card on the DP display.

3) After that, you can power off the development board, insert the SD card into the computer, and you can see more CAT.BMP

Leave a Reply

Your email address will not be published.