Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
LTDC
STM32F429
RT-Thread Studio
RT Thread Studio RGB屏幕之 LTDC 驱动篇
发布于 2022-05-10 21:32:07 浏览:1937
订阅该版
软 件:RT Thread Studio MCU: stm32f429bit6 sdram: W9812G2 16M 32位 SDRAM RGB屏幕:4.3寸屏幕,分辨率800*400 **原理图接口** ![image.png](https://oss-club.rt-thread.org/uploads/20220510/2a14b4743b74fb1700448aaa46fd67a7.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220510/ecda093d6e22b362082c34d701bc4338.png.webp) 步骤1:在RT-Thread Studio RGB屏幕之SDRAM配置程序的基础上进行修改 SDRAM的配置说明请参考这篇文章 [RT-Thread Studio SDRAM 配置说明](https://club.rt-thread.org/ask/article/47789c36753224f8.html) 使用 cubemx 配置 LTDC ![image.png](https://oss-club.rt-thread.org/uploads/20220510/df018b213cb2543a7fa4c013974523af.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220510/a9a1aaaa15409f71d33715ef56c68e9d.png.webp) ![image.png](https://oss-club.rt-thread.org/uploads/20220510/53250a479e17e16b6ce3f95fa6bc0474.png.webp) 根据RGB屏幕要求修改系统时钟 ![image.png](https://oss-club.rt-thread.org/uploads/20220510/2b94a6f2d2ef81f32cc2735fcb3b32e7.png.webp) 步骤2:复制 drv_lcd.c 到 driver 文件夹内 [drv_lcd.c 位置] "D:/RT-ThreadStudio/repo/Extract/RT-Thread_Source_Code/RT-Thread/4.1.0/bsp/stm32/libraries/HAL_Drivers" 步骤3:修改 drv_lcd.c 文件 - 3.1 在drv_lcd.c中添加头文件 ``` #include
#ifdef BSP_USING_LCD #include
#include
#include
#define DRV_DEBUG #define LOG_TAG "drv.lcd" #include
``` - 3.2 在drv_lcd.c中添加RGB屏幕的GPIO口初始化函数 打开“ cubemx/Src”文件夹内的ltdc.c,将 void HAL_LTDC_MspInit(LTDC_HandleTypeDef* ltdcHandle)函数复制到drv_lcd.c 文件内,并将函数名改为static void MX_LTDC_MspInit(void),修改后如下 ``` static void MX_LTDC_MspInit(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; /** Initializes the peripherals clock */ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC; PeriphClkInitStruct.PLLSAI.PLLSAIN = 150; PeriphClkInitStruct.PLLSAI.PLLSAIR = 3; PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2; HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); /* LTDC clock enable */ __HAL_RCC_LTDC_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOJ_CLK_ENABLE(); __HAL_RCC_GPIOK_CLK_ENABLE(); /**LTDC GPIO Configuration PI12 ------> LTDC_HSYNC PI13 ------> LTDC_VSYNC PI14 ------> LTDC_CLK PI15 ------> LTDC_R0 PJ0 ------> LTDC_R1 PJ1 ------> LTDC_R2 PJ2 ------> LTDC_R3 PJ3 ------> LTDC_R4 PJ4 ------> LTDC_R5 PJ5 ------> LTDC_R6 PJ6 ------> LTDC_R7 PJ7 ------> LTDC_G0 PJ8 ------> LTDC_G1 PJ9 ------> LTDC_G2 PJ10 ------> LTDC_G3 PJ11 ------> LTDC_G4 PK0 ------> LTDC_G5 PK1 ------> LTDC_G6 PK2 ------> LTDC_G7 PJ12 ------> LTDC_B0 PJ13 ------> LTDC_B1 PJ14 ------> LTDC_B2 PJ15 ------> LTDC_B3 PK3 ------> LTDC_B4 PK4 ------> LTDC_B5 PK5 ------> LTDC_B6 PK6 ------> LTDC_B7 PK7 ------> LTDC_DE */ GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOI, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 |GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOK, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF14_LTDC; HAL_GPIO_Init(GPIOJ, &GPIO_InitStruct); } ``` - 3.3 将static void MX_LTDC_MspInit(void)函数添加到drv_lcd.c内的 rt_err_t stm32_lcd_init(struct drv_lcd_device *lcd)函数中 ``` rt_err_t stm32_lcd_init(struct drv_lcd_device *lcd) { LTDC_LayerCfgTypeDef pLayerCfg = {0}; /* LTDC GPIO Initialization -------------------------------------------------------*/ MX_LTDC_MspInit(); //RGB屏幕GPIO初始化,并启用时钟 /* LTDC Initialization -------------------------------------------------------*/ /* Polarity configuration */ /* Initialize the horizontal synchronization polarity as active low */ LtdcHandle.Init.HSPolarity = LTDC_HSPOLARITY_AL; /* Initialize the vertical synchronization polarity as active low */ LtdcHandle.Init.VSPolarity = LTDC_VSPOLARITY_AL; /* Initialize the data enable polarity as active low */ LtdcHandle.Init.DEPolarity = LTDC_DEPOLARITY_AL; /* Initialize the pixel clock polarity as input pixel clock */ LtdcHandle.Init.PCPolarity = LTDC_PCPOLARITY_IPC; /* Timing configuration */ /* Horizontal synchronization width = Hsync - 1 */ LtdcHandle.Init.HorizontalSync = LCD_HSYNC_WIDTH - 1; /* Vertical synchronization height = Vsync - 1 */ LtdcHandle.Init.VerticalSync = LCD_VSYNC_HEIGHT - 1; /* Accumulated horizontal back porch = Hsync + HBP - 1 */ LtdcHandle.Init.AccumulatedHBP = LCD_HSYNC_WIDTH + LCD_HBP - 1; /* Accumulated vertical back porch = Vsync + VBP - 1 */ LtdcHandle.Init.AccumulatedVBP = LCD_VSYNC_HEIGHT + LCD_VBP - 1; /* Accumulated active width = Hsync + HBP + Active Width - 1 */ LtdcHandle.Init.AccumulatedActiveW = LCD_HSYNC_WIDTH + LCD_HBP + lcd->lcd_info.width - 1 ; /* Accumulated active height = Vsync + VBP + Active Heigh - 1 */ LtdcHandle.Init.AccumulatedActiveH = LCD_VSYNC_HEIGHT + LCD_VBP + lcd->lcd_info.height - 1; /* Total height = Vsync + VBP + Active Heigh + VFP - 1 */ LtdcHandle.Init.TotalHeigh = LtdcHandle.Init.AccumulatedActiveH + LCD_VFP; /* Total width = Hsync + HBP + Active Width + HFP - 1 */ LtdcHandle.Init.TotalWidth = LtdcHandle.Init.AccumulatedActiveW + LCD_HFP; /* Configure R,G,B component values for LCD background color */ LtdcHandle.Init.Backcolor.Blue = 0; LtdcHandle.Init.Backcolor.Green = 0; LtdcHandle.Init.Backcolor.Red = 0; LtdcHandle.Instance = LTDC; /* Layer1 Configuration ------------------------------------------------------*/ /* Windowing configuration */ pLayerCfg.WindowX0 = 0; pLayerCfg.WindowX1 = lcd->lcd_info.width; pLayerCfg.WindowY0 = 0; pLayerCfg.WindowY1 = lcd->lcd_info.height; /* Pixel Format configuration*/ if (lcd->lcd_info.pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB565) { pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565; } else if (lcd->lcd_info.pixel_format == RTGRAPHIC_PIXEL_FORMAT_ARGB888) { pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_ARGB8888; } else if (lcd->lcd_info.pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB888) { pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888; } else if (lcd->lcd_info.pixel_format == RTGRAPHIC_PIXEL_FORMAT_RGB888) { pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB888; } else { LOG_E("unsupported pixel format"); return -RT_ERROR; } /* Start Address configuration : frame buffer is located at FLASH memory */ pLayerCfg.FBStartAdress = (uint32_t)lcd->front_buf; // pLayerCfg.FBStartAdress = 0xD0000000; /* Alpha constant (255 totally opaque) */ pLayerCfg.Alpha = 255; /* Default Color configuration (configure A,R,G,B component values) */ pLayerCfg.Alpha0 = 0; pLayerCfg.Backcolor.Blue = 0; pLayerCfg.Backcolor.Green = 0; pLayerCfg.Backcolor.Red = 0; /* Configure blending factors */ /* Constant Alpha value: pLayerCfg.Alpha / 255 C: Current Layer Color Cs: Background color BC = Constant Alpha x C + (1 - Constant Alpha ) x Cs */ /* BlendingFactor1: Pixel Alpha x Constant Alpha */ pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA; /* BlendingFactor2: 1 - (Pixel Alpha x Constant Alpha) */ pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA; /* Configure the number of lines and number of pixels per line */ pLayerCfg.ImageWidth = lcd->lcd_info.width; pLayerCfg.ImageHeight = lcd->lcd_info.height; /* Configure the LTDC */ if (HAL_LTDC_Init(&LtdcHandle) != HAL_OK) { LOG_E("LTDC init failed"); return -RT_ERROR; } /* Configure the Background Layer*/ if (HAL_LTDC_ConfigLayer(&LtdcHandle, &pLayerCfg, 0) != HAL_OK) { LOG_E("LTDC layer init failed"); return -RT_ERROR; } else { /* enable LTDC interrupt */ HAL_NVIC_SetPriority(LTDC_IRQn, 1, 0); HAL_NVIC_EnableIRQ(LTDC_IRQn); LOG_D("LTDC init success"); return RT_EOK; } } ``` 步骤4:复制 lcd_port.h 到 driver/include 文件夹内 [lcd_port.h 位置] "D:/RT-ThreadStudio/repo/Extract/RT-Thread_Source_Code/RT-Thread/4.1.0/bsp/stm32/stm32f429-fire-challenger/board/ports" 步骤5:根据RGB屏幕规格进行参数配置,屏幕为反客科技的4.3寸屏幕, 本屏幕的背光引脚为PD13,依据具体屏幕修改即可 ``` #ifndef __LCD_PORT_H__ #define __LCD_PORT_H__ /* FanKe 4.3 inch screen, 800 * 480 */ #define LCD_WIDTH 800 #define LCD_HEIGHT 480 #define LCD_BITS_PER_PIXEL 16 #define LCD_BUF_SIZE (LCD_WIDTH * LCD_HEIGHT * LCD_BITS_PER_PIXEL / 8) #define LCD_PIXEL_FORMAT RTGRAPHIC_PIXEL_FORMAT_RGB565 #define LCD_HSYNC_WIDTH 1 #define LCD_VSYNC_HEIGHT 1 #define LCD_HBP 80 #define LCD_VBP 40 #define LCD_HFP 200 #define LCD_VFP 22 /* 屏幕背光引脚 */ #define LCD_BACKLIGHT_USING_GPIO #define LCD_BL_GPIO_NUM GET_PIN(D, 13) /* FanKe 4.3 inch screen, 800 * 480 */ #endif /* __LCD_PORT_H__ */ ``` 步骤6:配置 RT-Thread Setting,内核 -> 内存管理 ![image.png](https://oss-club.rt-thread.org/uploads/20220510/3998423158e2c764e99b71365699a478.png.webp) 注意:使能动态内存根据需要进行修改,否则会有[E/drv.lcd] init frame buffer failed!”错误 步骤7:下载,运行,输入 lcd_test 屏幕按照红、绿、蓝闪烁 ![image.png](https://oss-club.rt-thread.org/uploads/20220510/00f2ca2cf364dad3d470f058b577cf8c.png) Enjoy it!
10
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
boluoc
这家伙很懒,什么也没写!
文章
2
回答
0
被采纳
0
关注TA
发私信
相关文章
1
rt_thread studio 啥时候能用呢
2
RT_Thread使用反馈帖子
3
RTT studio 下的 AT指令问题。
4
什么时候RTT Sdudio支持Ubuntu,Deepin和UOS操作系统
5
rt thread Studio 关于J-LINK下载问题
6
RT-Thread studio 调试设置问题
7
RTT-Studio 如何设置调试配置参数?
8
rt_thread studio 软件包配置
9
RT-Studio目前只能开发STM32的项目吗?
10
rtt studio 生成hex名字修改
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
PWM
cubemx
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
6
次点赞
YZRD
1
篇文章
2
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部