STM32F429 LTDC driver diagram, stm32f429ltdc Diagram
This article is based on the official ST demo Board STM32F429 Discovery hardware platform and explains the main parameter configuration of LTDC in the form of a picture. The Code mentioned in this article is taken from another article, "LTDC code template of STM32F429". The LCD hardware is 240x320, and the driver IC is ili9341. The purpose of this article is to allow you to master the configuration essentials of the STM32F429 LTDC controller through several images, and to free you from the dry text for easy memory. Of course, this article only explains some common LTDC settings. For more details, see the official datasheet of ST.
1. For the clock configuration of the LTDC peripherals, you only need to remember the figure below (the picture is from the STM32CubeMX RCC Clock Tree ):
The code for this figure is as follows:
/* Configure PLLSAI prescalers for LCD */ /* PLLSAI_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */ /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAI_N = 192 Mhz */ /* PLLLCDCLK = PLLSAI_VCO Output/PLLSAI_R = 192/3 = 64 Mhz */ /* LTDC clock frequency = PLLLCDCLK / RCC_PLLSAIDivR = 64/8 = 8 Mhz */ RCC_PLLSAIConfig(192, 7, 3); RCC_LTDCCLKDivConfig(RCC_PLLSAIDivR_Div8); /* Enable PLLSAI Clock */ RCC_PLLSAICmd(ENABLE); /* Wait for PLLSAI activation */ while(RCC_GetFlagStatus(RCC_FLAG_PLLSAIRDY) == RESET) { }
2. for LCD signal timing parameters, just remember the following figure:
Note: This part must be strictly configured according to the LCD Datasheet requirements.
The code corresponding to the chart change is as follows:
/* Initialize the horizontal synchronization polarity as active low*/ LTDC_InitStruct.LTDC_HSPolarity = LTDC_HSPolarity_AL; /* Initialize the vertical synchronization polarity as active low */ LTDC_InitStruct.LTDC_VSPolarity = LTDC_VSPolarity_AL; /* Initialize the data enable polarity as active low */ LTDC_InitStruct.LTDC_DEPolarity = LTDC_DEPolarity_AL; /* Initialize the pixel clock polarity as input pixel clock */ LTDC_InitStruct.LTDC_PCPolarity = LTDC_PCPolarity_IPC; /* Timing configuration */ /* Configure horizontal synchronization width */ LTDC_InitStruct.LTDC_HorizontalSync = 9; /* Configure vertical synchronization height */ LTDC_InitStruct.LTDC_VerticalSync = 1; /* Configure accumulated horizontal back porch */ LTDC_InitStruct.LTDC_AccumulatedHBP = 29; /* Configure accumulated vertical back porch */ LTDC_InitStruct.LTDC_AccumulatedVBP = 3; /* Configure accumulated active width */ LTDC_InitStruct.LTDC_AccumulatedActiveW = 269; /* Configure accumulated active height */ LTDC_InitStruct.LTDC_AccumulatedActiveH = 323; /* Configure total width */ LTDC_InitStruct.LTDC_TotalWidth = 279; /* Configure total height */ LTDC_InitStruct.LTDC_TotalHeigh = 327;
Iii. Layer of LTDC
The layer concept includes the following:
1. STM32F429 has three layers: Background, Layer1, and Layer2. At any time, the LCD displays the final result after the layer is superimposed;
2. The Background layer is valid at any time, while Layer1 and Layer2 can be enabled or disabled through software configuration;
3. The space sequence of the three layers is Background, Layer1, and Layer2 from the bottom up, so the order of superposition is as follows:
Each Layer supports Window operations. The so-called Window means that the image of this Layer is valid only in the Window area, while the DefaultColor of this Layer is used outside the Window area. For example:
For the configuration of the position and size of the Layer Window display, remember the following figure:
The code for this figure is as follows:
/* Windowing configuration */ /* In this case all the active display area is used to display a picture then: Horizontal start = horizontal synchronization + Horizontal back porch = 30 Horizontal stop = Horizontal start + window width -1 = 30 + 240 -1 Vertical start = vertical synchronization + vertical back porch = 4 Vertical stop = Vertical start + window height -1 = 4 + 320 -1 */ LTDC_Layer_InitStruct.LTDC_HorizontalStart = 30; LTDC_Layer_InitStruct.LTDC_HorizontalStop = (240 + 30 - 1); LTDC_Layer_InitStruct.LTDC_VerticalStart = 4; LTDC_Layer_InitStruct.LTDC_VerticalStop = 320 + 4 -1;
Each Layer is associated with a display buffer FrameBuffer. As Background can only be filled with monochrome, it does not have FrameBuffer. FrameBuffer has several parameters: Pixel Format, Buffer Address, Line Length, Number of lines, and Buffer Pitch. These parameters are for Layer windows and their meanings are as follows:
Pixel Format: not to mention RGB565, ARGB8888, and ARGB1555;
Buffer Address: displays the starting Address of the Buffer;
Line Length: the buffer width + 3 corresponding to the window, in bytes;
Number of Lines: the buffer height corresponding to the window, in bytes;
Buffer Pitch: the number of bytes from the beginning of the row to the start of the next row. To put it bluntly, it is a row pointer increment (or the width of the entire image, in bytes );
Assume that the FrameBuffer of Layer1 is as follows (RGB565 ):
Set the image to be displayed in the window to the pink part:
Combined with the position of the previously set Window, the final displayed image is shown as follows (Layer2 and transparent color are not considered ):
We can see that:
Start Address and Buffer Pitch determine the Start position of each row in the window display;
Line Length and Line Number determine the size of the window in the video memory.
The code for this part is as follows:
/* Input Address configuration */ LTDC_Layer_InitStruct.LTDC_CFBStartAdress = (u32)FrameBuffer; /* the length of one line of pixels in bytes + 3 then : Line Lenth = Active high width x number of bytes per pixel + 3 Active high width = 240 number of bytes per pixel = 2 (pixel_format : RGB565) */ LTDC_Layer_InitStruct.LTDC_CFBLineLength = ((240 * 2) + 3); /* the pitch is the increment from the start of one line of pixels to the start of the next line in bytes, then : Pitch = Active high width x number of bytes per pixel */ LTDC_Layer_InitStruct.LTDC_CFBPitch = (240 * 2); /* configure the number of lines */ LTDC_Layer_InitStruct.LTDC_CFBLineNumber = 320;
It should be noted that, to ensure that the image can be correctly displayed, make sure that the size of the image in the video memory is consistent with that displayed in the window, that is, Line Length and Line Number must be consistent with (HStop-HStart), (VStop-VStart) are consistent, otherwise the display will be incorrect.
Finally, do not forget to call LTDC_LayerCmd () after setting the registers of all layers. You must call the LTDC_ReloadConfig (ENABLE) function to make the settings of all layers take effect.