1 Star 5 Fork 4

zeruns/基于STM32F407的LVGL工程模板(MSP3526屏幕)

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
LGPL-3.0

STM32F407-Based LVGL Project Template for MSP3526 Screen (FreeRTOS and Bare Metal Editions)

I have successfully ported the LVGL graphics library to the STM32F407 and it is compatible with the MSP3526 LCD screen. If you need to switch to a different screen, you can modify the LCD driver accordingly. The project includes both FreeRTOS and bare metal editions and utilizes SPI+DMA for driving the screen.

This LCD screen has a resolution of 320x480, a size of 3.5 inches, an LCD driver chip of ST7796, and a capacitive touch screen driver chip of FT6336U.

The MCU can achieve a frame rate of about 9FPS for full screen refresh and over 30FPS for partial refresh after overclocking, which is considered acceptable for SPI.

Screenshots

Demo Video:https://www.bilibili.com/video/BV1Ni421S7ta/

Introduction to LVGL

LVGL (Light and Versatile Graphics Library) is a free and open-source graphics library that provides everything needed to create embedded GUIs, with easy-to-use graphical elements, beautiful visual effects, and low memory usage.

Key Features:

  • Rich and powerful modular graphical components: buttons, charts, lists, sliders, images, etc.
  • Advanced graphical engine: animations, anti-aliasing, transparency, smooth scrolling, layer blending, etc.
  • Support for multiple input devices: touch screen, keyboard, encoder, buttons, etc.
  • Support for multiple display devices
  • Not dependent on specific hardware platforms, can run on any display
  • Configurable and scalable (minimum resource usage: 64KB flash, 16KB RAM)
  • Multi-language support based on UTF-8, such as Chinese, Japanese, Korean, Arabic, etc.
  • Design and layout graphical interfaces using CSS-like methods (e.g., Flexbox, Grid)
  • Support for operating systems, external memory, and hardware acceleration (LVGL has built-in support for STM32 DMA2D, NXP PXP, and VGLite)
  • Ensure smooth rendering even with a single frame buffer
  • Entirely written in C and supports C++ calling
  • Support for MicroPython programming, see: LVGL API in MicroPython
  • Support for simulator simulation, can develop without hardware
  • Abundant example programs
  • Detailed documentation and API reference, available online or downloadable as PDF
  • Free and open source under the MIT license

Configuration Requirements:

Basically, any modern controller that can drive a display is suitable for running LVGL. The minimum requirements are:

  • 16-bit, 32-bit or 64-bit microcontroller or processor
  • Recommended clock speed of >16 MHz
  • Flash/ROM: >64 KB for essential components (>180 KB recommended)
  • RAM:
    • Static RAM usage: ~2 KB, depending on used features and object types
    • Heap: >2 KB (>8 KB recommended)
    • Dynamic data (heap): >2 KB (>16 KB recommended if using multiple objects). Configure LV_MEM_SIZE in lv_conf.h to take effect.
    • Display buffer: > "horizontal resolution" pixels (recommended >10 × 10×"horizontal resolution")
    • One frame buffer in MCU or external display controller
  • C99 or newer compiler

LVGL official website: https://lvgl.io/

Wiring Instructions

LCD Screen MCU/Development Board Function Description
GND GND LCD screen power ground
VCC 5V or 3.3V LCD screen power positive
LCD_CS PE6 LCD screen SPI chip select
LCD_RST PC1 LCD screen reset
LCD_RS PC0 LCD screen command/data select
SDI(MOSI) PB5 LCD screen SPI data line, host output to slave input
SCK PB3 LCD screen SPI clock line
LED 3.3V Backlight LED (can connect to IO port for software control)
SDO(MISO) PB4 LCD screen SPI data line, host input from slave output
CTP_SCL PB8 Capacitive touch screen controller I2C clock line
CTP_RST PB7 Capacitive touch screen controller reset
CTP_SDA PB9 Capacitive touch screen controller I2C data line
CTP_INT PB6 Capacitive touch screen controller interrupt signal

Note that the PB4 pin on the development board I used for the screenshots is not on the pins on both sides but is on the JTAG interface above.

Download Resources and Programs

Online documentation for the screen: https://url.zeruns.tech/68x3Y

Download address 1 for screen resources: https://www.123pan.com/s/2Y9Djv-rZevH.html

Download address 2 for screen resources: https://url.zeruns.tech/gzBO4

Download address 1 for STM32F407+LVGL bare metal project: https://url.zeruns.tech/X242k

Download address 2 for STM32F407+LVGL bare metal project: https://pan.baidu.com/s/1vAhHijYd_aWvRr3_c1_WtA?pwd=ry4g

FreeRTOS版STM32F407+LVGL工程下载地址1:https://www.123pan.com/s/2Y9Djv-CzevH.html

FreeRTOS版STM32F407+LVGL工程下载地址2:https://url.zeruns.tech/0iOHF

Latest version of the program with FreeRTOS is in the Gitee and GitHub open source addresses, and the bare metal version is in the release version, version number 0.1.3.

I ported it according to the tutorial of Zhengdian Yuanzi.

Zhengdian Yuanzi's LVGL usage and porting video tutorial download address 1: https://www.123pan.com/s/2Y9Djv-0ZevH.html

Zhengdian Yuanzi's LVGL usage and porting video tutorial download address 2: https://www.alipan.com/s/Pd6TDfT2rBL

Usage Instructions

Download the code and compile and download it directly to use it.

If you need to turn off the frame rate and memory usage display, change the 1 to 0 for the following two macro definitions in the lv_conf.h file:

/*1: Show CPU usage and FPS count*/
#define LV_USE_PERF_MONITOR 1
#if LV_USE_PERF_MONITOR
    #define LV_USE_PERF_MONITOR_POS LV_ALIGN_BOTTOM_RIGHT
#endif
/*1: Show the used memory and the memory fragmentation
 * Requires LV_MEM_CUSTOM = 0*/
#define LV_USE_MEM_MONITOR 1
#if LV_USE_MEM_MONITOR
    #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT
#endif

If you are using the FreeRTOS version, write the code in the freertos.c file. You can use STM32CubeMX software to create threads and semaphores, and then generate the code. The code is written in a specified location according to the specifications, and regenerating will not affect the code you wrote. For the bare metal version, just write the code in the main.c file.

If you need to turn off the Demo program, just comment out the code in the image below.

Component Purchase Links

Main Code Snippet

The main code is located in the disp_flush function in the lv_port_disp.c file, where the LCD is filled using the following function. The LCD driver is based on the example code provided by the screen manufacturer.

/**
 * @brief 填充LCD屏幕指定矩形区域
 * 使用LVGL库的颜色值填充LCD指定区域。
 * @param sx 起始X坐标
 * @param sy 起始Y坐标
 * @param ex 结束X坐标
 * @param ey 结束Y坐标
 * @param color_p 指向要填充的颜色的指针
 */
void LCD_Fill_LVGL(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, lv_color_t *color_p)
{
    uint32_t i, j;
    uint16_t width = ex - sx + 1;     // 计算填充区域的宽度
    uint16_t height = ey - sy + 1;     // 计算填充区域的高度
    uint32_t Pixel = width * height; // 计算填充区域像素个数
    LCD_SetWindows(sx, sy, ex, ey);     // 设置LCD的显示窗口为指定的区域

//    for (i = 0; i < height; i++)
//    {
//        for (j = 0; j < width; j++){
//            Lcd_WriteData_16Bit(color_p->full); // 写入数据
//        }
//    }

// 数据分割值, 用于分批发送数据
#define data_split 3000

    uint8_t data[Pixel * 2]; // 创建一个数组用于存储颜色数据

    for (i = 0; i < Pixel; i++)
    {
        // 将颜色数据从16位转换为两个8位的数据
        data[i * 2] = (color_p->full) >> 8;            // 获取高8位数据
        data[i * 2 + 1] = (uint8_t)(color_p->full); // 获取低8位数据
        color_p++;                                    // 指向下一个颜色值

        // 判断数据量是否大于10000,如果大于则分批发送数据
        if (Pixel > 10000)
        {
            if ((i + 1) % data_split == 0)
            {
                if ((i + 1) == data_split)
                {
                    Lcd_WriteData_DMA(data, data_split * 2); // 以DMA方式发送数据
                }
                else
                {
                    while (HAL_SPI_GetState(LCD_SPI) != HAL_SPI_STATE_READY);                        // 等待SPI总线空闲
                    uint8_t *temp = &data[((uint16_t)((i + 1) / data_split) - 1) * data_split * 2]; // 获取剩余数据
                    Lcd_WriteData_DMA(temp, data_split * 2);                                        // 以DMA方式发送数据
                }
            }
            else if (((i + 1) % data_split > 0) && ((i + 1) > data_split) && (i == (Pixel - 1)))
            {
                if ((uint16_t)((i + 1) / data_split) == 1)
                {
                    while (HAL_SPI_GetState(LCD_SPI) != HAL_SPI_STATE_READY)
                        ;                                                 // 等待SPI总线空闲
                    uint8_t *temp = &data[data_split * 2];                 // 获取剩余数据
                    Lcd_WriteData_DMA(temp, ((i + 1) % data_split) * 2); // 以DMA方式发送数据
                }
                else
                {
                    while (HAL_SPI_GetState(LCD_SPI) != HAL_SPI_STATE_READY)
                        ;                                                                      // 等待SPI总线空闲
                    uint8_t *temp = &data[(uint16_t)((i + 1) / data_split) * data_split * 2]; // 获取剩余数据
                    Lcd_WriteData_DMA(temp, ((i + 1) % data_split) * 2);
                }
            }
        }
    }

    if (Pixel <= 10000)
    {
        // 要发送的数据小于10000*2字节时一次全部发送
        Lcd_WriteData_DMA(data, Pixel * 2);
    }

    LCD_SetWindows(0, 0, lcddev.width - 1, lcddev.height - 1); // 恢复窗口设置为全屏
}

Other Open Source Project Recommendations

Recommended Reading

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

About

基于STM32F407的LVGL工程模板(3.5寸ST7796触屏LCD) expand collapse
LGPL-3.0
Cancel

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/zeruns/STM32F407_LVGL_Template_MSP3526.git
git@gitee.com:zeruns/STM32F407_LVGL_Template_MSP3526.git
zeruns
STM32F407_LVGL_Template_MSP3526
基于STM32F407的LVGL工程模板(MSP3526屏幕)
master

Search

344bd9b3 5694891 D2dac590 5694891