OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4939|回复: 2

STM32F429 discovery开发板LTDC显示花屏

[复制链接]

5

主题

7

帖子

0

精华

新手上路

积分
33
金钱
33
注册时间
2022-6-17
在线时间
8 小时
发表于 2022-7-9 01:37:14 | 显示全部楼层 |阅读模式
15金钱
想学STM32Cube里的例程建立一个新的LTDC显示的程序,开发板是ST官方的f429 disc1,目的是只在屏幕上显示一张图片(图放在my_img.h里)。在例程里更改就没有问题,显示正常,但是在自己新建的项目写一摸一样的代码显示花屏,现象是屏幕几条横线,然后背景花屏,看了几天不知道错在哪里。代码全部抄例程的(STM32Cube_FW_F4_V1.27.0\Projects\STM32F429I-Discovery\Examples\LTDC\LTDC_Display_2Layers)。
main.c代码如下
#include "main.h"
#include "my_img.h"

static void SystemClock_Config(void);
static void LCD_Config(uint32_t iWidth, uint32_t iLength);
static void Error_Handler(void);

LTDC_HandleTypeDef LtdcHandle;

int main()
{
        HAL_Init();
       
        /* Configure the system clock to 180 MHz */
        SystemClock_Config();
       
        /* Configure LED3 and LED4 */
        BSP_LED_Init(LED3);
        BSP_LED_Init(LED4);

        /*##-4*- LCD Configuration ##################################################*/
        LCD_Config(targetHeight, targetWidth);
       
        /* Infinite loop */
        while(1);
}

static void SystemClock_Config(void)
{
        RCC_ClkInitTypeDef RCC_ClkInitStruct;
        RCC_OscInitTypeDef RCC_OscInitStruct;
        RCC_PeriphCLKInitTypeDef  PeriphClkInitStruct;

        /* Enable Power Control clock */
        __HAL_RCC_PWR_CLK_ENABLE();

        /* The voltage scaling allows optimizing the power consumption when the device is
         clocked below the maximum system frequency, to update the voltage scaling value
         regarding system frequency refer to product datasheet.  */
        __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

        /*##-1- System Clock Configuration #########################################*/  
        /* 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 = 8;
        RCC_OscInitStruct.PLL.PLLN = 360;
        RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
        RCC_OscInitStruct.PLL.PLLQ = 7;
        HAL_RCC_OscConfig(&RCC_OscInitStruct);

        /* Activate the Over-Drive mode */
        HAL_PWREx_EnableOverDrive();

        /* 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;  
        HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5);

        /*##-2- LTDC Clock Configuration ###########################################*/  
        /* LCD clock configuration */
        /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 MHz */
        /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN = 192 MHz */
        /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAIR = 192/4 = 48 MHz */
        /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDIVR_8 = 48/8 = 6 MHz */
        PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
        PeriphClkInitStruct.PLLSAI.PLLSAIN = 192;
        PeriphClkInitStruct.PLLSAI.PLLSAIR = 4;
        PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_8;
        HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
}

static void LCD_Config(uint32_t iWidth, uint32_t iLength)
{  
        LTDC_LayerCfgTypeDef pLayerCfg;

        /* Initialization of ILI9341 component*/
        ili9341_Init();

/* 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  (Typical configuration from ILI9341 datasheet)
          HSYNC=10 (9+1)
          HBP=20 (29-10+1)
          ActiveW=240 (269-20-10+1)
          HFP=10 (279-240-20-10+1)

          VSYNC=2 (1+1)
          VBP=2 (3-2+1)
          ActiveH=320 (323-2-2+1)
          VFP=4 (327-320-2-2+1)
        */  

        /* Timing configuration */
        /* Horizontal synchronization width = Hsync - 1 */  
        LtdcHandle.Init.HorizontalSync = 9;
        /* Vertical synchronization height = Vsync - 1 */
        LtdcHandle.Init.VerticalSync = 1;
        /* Accumulated horizontal back porch = Hsync + HBP - 1 */
        LtdcHandle.Init.AccumulatedHBP = 29;
        /* Accumulated vertical back porch = Vsync + VBP - 1 */
        LtdcHandle.Init.AccumulatedVBP = 3;
        /* Accumulated active width = Hsync + HBP + Active Width - 1 */
        LtdcHandle.Init.AccumulatedActiveH = 323;
        /* Accumulated active height = Vsync + VBP + Active Height - 1 */
        LtdcHandle.Init.AccumulatedActiveW = 269;
        /* Total height = Vsync + VBP + Active Height + VFP - 1 */
        LtdcHandle.Init.TotalHeigh = 327;
        /* Total width = Hsync + HBP + Active Width + HFP - 1 */
        LtdcHandle.Init.TotalWidth = 279;

        /* 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 = iWidth;
        pLayerCfg.WindowY0 = 0;
        pLayerCfg.WindowY1 = iLength;

        /* Pixel Format configuration*/
        pLayerCfg.PixelFormat = LTDC_PIXEL_FORMAT_RGB565;

        /* Start Address configuration : frame buffer is located at FLASH memory */
        pLayerCfg.FBStartAdress = (uint32_t)&MY_IMG_RGB565;

        /* 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 */
        pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_PAxCA;
        pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_PAxCA;

        /* Configure the number of lines and number of pixels per line */
        pLayerCfg.ImageWidth = iWidth;
        pLayerCfg.ImageHeight = iLength;
       
        /* Configure the LTDC */  
        if(HAL_LTDC_Init(&LtdcHandle) != HAL_OK)
        {
                /* Initialization Error */
                Error_Handler();
        }

        /* Configure the Background Layer*/
        if(HAL_LTDC_ConfigLayer(&LtdcHandle, &pLayerCfg, 0) != HAL_OK)
        {
                /* Initialization Error */
                Error_Handler();
        }
}

3.JPG
2.JPG
1.JPG
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

5

主题

7

帖子

0

精华

新手上路

积分
33
金钱
33
注册时间
2022-6-17
在线时间
8 小时
 楼主| 发表于 2022-7-9 01:38:21 | 显示全部楼层
三张图顺序倒过来,先是白屏中间有条线,然后背景花屏
回复

使用道具 举报

1

主题

385

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1023
金钱
1023
注册时间
2019-9-21
在线时间
269 小时
发表于 2022-7-9 09:51:29 | 显示全部楼层
帮顶一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 12:04

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表