EmbeddedGraphics(MCU3) Slides
EmbeddedGraphics(MCU3) Slides
com
License
This power point presentation by BHARATI SOFTWARE is licensed under
CC BY-SA 4.0
To view a copy of this license, visit
https://creativecommons.org/licenses/by-sa/4.0
Important Links
• For the full video course please visit
• https://www.udemy.com/course/mastering-microcontroller-stm32-ltdc-lcd-tft-lvgl/
• Course repository
• https://github.com/niekiran/EmbeddedGraphicsLVGL-MCU3
• Explore all FastBit EBA courses
• http://fastbitlab.com/course1/
• For suggestions and feedback
• [email protected]
Social media
• Join our Facebook private group for technical discussion
• https://www.facebook.com/groups/fastbiteba/
• Linkedin
• https://www.linkedin.com/company/fastbiteba/
• Facebook
• https://www.facebook.com/fastbiteba/
• YouTube
• https://www.youtube.com/channel/UCa1REBV9hyrzGp2mjJCagBg
• Twitter
• https://twitter.com/fastbiteba
Graphics application
A microcontroller based interactive application which may involve any of the below components to
display on the display device
• Colours
o Color of the text • Graphical effects(scrolling, sliding, swipe, press,
o Background color / layer color release)
• Widgets(simple button, radio button, check box)
• Shapes
• Videos
o Box
• 3D rendering
o Circle • Gaming
o Arrows
o Lines
• Images
• Texts
RAM ▪ LCD
Interface o TFT
CPU Display o IPS
▪ LED
FLASH ▪ Plasma
▪ CRT
▪ OLED
RAM Interface
CPU
FLASH Rendering of
image data
Frame buffer ➔ A memory area which holds the pixel values of the frame to be
updated on the display
Option 3:
STM32F7508-DK
Discovery kit with STM32F750N8 MCU
SPI
SPI
STM32F7508-DK STM32F750N8 Cortex-M7 340 64KiB Yes Yes Yes Yes Yes
128Mbit 128Mbit 480x272
NUCLEO-F4x ?? Cortex-M4 ?? ?? No No No No No
https://www.st.com/en/evaluation-tools/stm32-mcu-mpu-eval-tools.html
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
Runs on,
SPI
STM32F407 DISC-1
Control signals
5V
PC2 SD0(MISO)
SPI2
PB13
PB15 SCK
SDI(MOSI)
STM32F407 DISC-1 DC_RS
PD9 RESET
CS
GND
PD10
PD11 VCC
GND
5V
SRAM
Display signals
22 Pin LCD
Display driver RGB display
Arm
Controller SPI 2 chip
Cortex
(LTDC)
M4 LCD Driver chip
programming interface
FLASH
4
Control signals
240x320
LCD-TFT Display module
SRAM
LCD
Display
40 Pin driver RGB display
Arm Controller
chip
Cortex M7 (LTDC)
FLASH 480x272
LCD-TFT Display module
Glass
Driver IC
Interface
40 pins
A pixel
270
lines
Pixel grid
A color image
Grid of pixels
A pixel
A Pixel of the image : The smallest information(color information) of the image stored
in computer memory
How much memory does one pixel consume in compute memory ? (Pixel depth/color
depth/bit depth)
Depends on pixel format
measured in bpp(bits per pixel)
GRAY8
0
Gray intensity
255
Grayscale B&W
True Color
L8 format
Represents the colors of the image by clor look up table(CLUT)
In L8 format 8bit index value is used to look for the color value in the
predefined color look up table.
1-inch
Display size
Vertical resolution
Horizonal resolution
Resolution
Image resolution:
Number of pixels used to represent an image arranged in standard graphics display width and height
dimensions
An image of 1600x900(HD+ resolution) will portray more details about the image than 1280x720(HD
resolution) image
Display resolution:
Number of pixels available in a given size of the display arranged in standard graphics display width
and height dimensions
Refer the below wiki page for different graphic display resolution available
https://en.wikipedia.org/wiki/Graphics_display_resolution
BMP(Bitmap) images
1. An BMP image file contains uncompressed pixel data, hence consumes more space on the disk
2. You can directly read the pixel values and display them on the display module
ARGB values of
the first pixel
You cannot directly read and display the .jpg file contents on the
display module
Bitmap
ARGB values
data
JPEG Decoder of the first
pixel
SRAM
(340KB)
LCD
Display
40 Pin driver Display Glass
Arm Controller
chip
Cortex M7 (LTDC)
FLASH
480x272
(1MB)
LCD-TFT Display module
Frames
.png
RGB565
• 1 pixel consumes 2 bytes
• Total flash consumed for 3 frames = ( 320x240x2 ) * 3 = 450KiB
RGB888
• 1 pixel consumes 3 bytes
• Total flash space consumed for 3 frames =
( 480x270x3 ) * 3 = 1139KiB
http://www.lcdwiki.com/2.4inch_SPI_Module_ILI9341_SKU:MSP2402
32F429IDISCOVERY
32F746GDISCOVERY 32F407DISCOVERY + SPI
based LCD module
SPI
STM32F407 DISC-1
Control signals
5V
PC2 SD0(MISO)
PB13
PB15 SCK
SDI(MOSI)
STM32F407 DISC-1 DC_RS
PD9 RESET
CS
GND
PD10
PD11 VCC
GND
5V
SRAM
(340KB)
LCD
Display
RGB interface driver Display Glass
Arm Controller
chip
Cortex M7 (LTDC)
FLASH
480x272
(1MB) Backlight signals LCD-TFT Display module
VDD
SRAM
LCD
SPI interface driver Display Glass
Arm chip
Cortex M7
FLASH
320X240
(Frame buffer)
Control signals LCD-TFT Display module
Some math
• Converted ARGB8888 pixel format image to RGB565 pixel format ‘C’ array
• Pixel depth = 16bpp( 2 bytes)
• Array size/frame = 480x270x2 ➔ 253.125 KiB
• Array size of 3 frames ➔ 759.375KiB
• 759.375KiB of flash is used up to hold just 3 frames .
• Let's check the .map file of the project to verify the memory consumption
MIPI DPI
• This is also called as RGB interface
• Applies to display interface which uses 16/18/24-bit data lines and control signals
• The MIPI DPI specification standardizes the data and controls signals to be used by manufacturers
of mobile device processors, cameras, and display
• The DPI interface is typically used when the display module doesn’t support the frame buffer
(GRAM). The Host controller must stream the data in real-time to the display
Display module
Figure shows a display module connected to the Host(Microcontroller) using MIPI DPI interface
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
LTD
er
C MIPI DPI
Power
Backlight control
Display module
Using Type A/B/C interface , MCU first sends commands to the LCD driver, configures some
important LCD parameters, and then writes data to the integrated GRAM to display it
MCU(Host) SCL
DC/RS
SPI CS Driver
Frame
SDI buffer
SDO
A pixel
270
lines
Pixel grid
A color image
Wvsync
Valid data Valid data Valid data Valid data
Wvsync
Valid data Valid data Valid data Valid data
240
320
34
34
34
240 34
34
34
36
Steps
1) Create a new project for your microcontroller or board using stm32cubeide
2) Setup the main system clock
3) Setup AHB and APB clocks
4) Setup pixel clock (DOTCLOCK) (Not required for STM32F407x-DISC1 board with external LCD )
5) Configure the SPI peripheral (Not required for STM32F746-DISC board )
6) Setup framebuffer in RAM
7) Initialize the LCD module by sending LCD commands over SPI (Not required for STM32F746-
DISC board )
8) Configure and enable the LTDC peripheral (Not required for STM32F407x-DISC1)
9) Send frame buffer contents to LCD over SPI (Only in the case of STM32F407x-DISC1 )
10) Make sure that all error interrupts enabled and ISRs implemented
32F429IDISCOVERY 32F407DISCOVERY
32F746GDISCOVERY
180MHz 216MHz
168MHz
APB1
Max:180MHz (APB1 bus clock) (PCLK1)
HCLK Max: 45MHz
(AHB bus clock)
SYSCLK AHB prescaler APB1 prescaler
APB2 prescaler
APB2
(APB2 bus clock) (PCLK2)
Max: 90MHz
PWR_CR
VOS ➔ 0X11
Enable Over drive (ODEN)
Enable ODSWEN bit to switch to
Over drive mode
Configuring SPI
• The SPI interface is used to send commands to the display module,
which is based on the ILI9341 LCD driver chip
• For STM32F407x + external display setup, this interface is also used to
transmit the RGB data
GPIOs
SPI
RGB interface
Data interface
STM32F429 DISC ILI9341
PA7 RESX
PD13 WRX_D/CX
PF9 SDI/SDA
SPI5
PF7 D/CX_SCL ILI9341
STM32F429 DISC
GPIOs
SPI
PD10 RESX
PB15 SDI(PICO)
PB13 SCL
STM32F407 DISC-1
Controller Peripheral
MOSI MOSI POCI
POCI
Master Slave
MISO MISO
SDO SDI
Controller Peripheral
SDI SDO
ILI9341 commands
Refer to the files attached with this lecture
Steps
1) Create a new project for your microcontroller or board using stm32cubeide
2) Setup the main system clock
3) Setup AHB and APB clocks
4) Setup pixel clock (DOTCLOCK) (Not required for STM32F407x-DISC1 board with external LCD )
5) Configure the SPI peripheral (Not required for STM32F746-DISC board )
6) Setup framebuffer in RAM
7) Initialize the LCD module by sending LCD commands over SPI (Not required for STM32F746-
DISC board )
8) Configure and enable the LTDC peripheral (Not required for STM32F407x-DISC1)
9) Send frame buffer contents to LCD over SPI (Only in the case of STM32F407x-DISC1 )
10) Make sure that all error interrupts enabled and ISRs implemented
LTDC configuration
1) LTDC pin initialization (Check the schematic of your board to know which pins are used as LTDC
signals )
2) LTDC peripheral initialization
3) LTDC layers initialization ( layer 1 or layer 2 or both)
STM32F429 DISC
• This board uses 18bit display connected as shown below
R7
R
R0
G7
G 18bit
LTDC Display
G0
B7
B0
STM32F746ng DISC
• This board uses 24bit display connected as shown below
R7
R
R0
G7
G 24bit
LTDC Display
G0
B7
B0
R7
R3
R0
G7
16bit
LTDC G2 Display
G0
B7
B3
B0
ILI9341
Some math
Total Width(TW) = AW+HSW+HBP+HFP pixels
Total time required to send one line(Tline ) = (TW * TDOTCLK ) sec
Total Lines(TL) = AH+VSW+VBP+VFP lines
Total time required to send 1 frame(Tframe) = (TL * Tline) sec
DOTCLK = 6.25MHz
TDOTCLK = 0.16 micro sec
TW = AW+HSW+HBP+HFP = 320 + 10 + 20+ 10 ➔ 360 pixels
TL = AH+VSW+VBP+VFP = 240+2+2+4 ➔ 248 lines
Tline = = (TW * TDOTCLK ) = 360 * 0.16 ➔ 57.6 μs
Tframe = (TL * Tline ) = 248 * 57.6 ➔ 14.3 ms
Task
Configure the LTDC peripheral to produce the background color RED.
LTDC Layers
• LTDC supports 2 layers
• You can activate either of the layers or all layers as per your application need
• Programmable default color settings for each layer
• Programmable frame buffer address settings for each layer
• Flexible blending options (Constant and pixel alpha blending )
• Programmable window positioning for each layer
• Most LTDC layer registers are shadow registers, and you need to activate loading shadow values
to real registers explicitly.
Layer-1 Layer-2
Display module
Layer-1 activated with windowing Layer-2 activated with
and dedicated framebuffer holding windowing
yellow color and dedicated framebuffer
holding black color
Layer windowing
34
34
34
240 34
34
34
34
Layer width
V_start
H_stop
MX = 0 , MY = 1, MV = 1
MX = 0 , MY = 0, MV = 0
MX = 1 , MY = 1, MV = 0 MX = 1 , MY = 1, MV = 0
Portrait-1 Portrait-2
240px
This configuration can be E
used for Portrait
B
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
X
www.fastbitlab.com
240px MV=0, MY=1. MX =1 (Portrait)
E
320px
GRAM filling up as pixel bytes are written to LCD for every HSYNC strobe
GRAM to display mapping for every HSYNC strobe
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
MV MX MY MCU Frame buffer write GRAM(memory inside ILI9341)
240px
This configuration can be E
used for Landscape
B
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
X
www.fastbitlab.com
240px MV=1, MY=1. MX =0 (Landscape)
320px
GRAM filling up as pixel bytes are written to LCD for every HSYNC strobe
GRAM to display mapping for every HSYNC strobe
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
Y
240
320
Display
GRAM(Frame memory) of LCD
X
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
Pixel buffer
• In the case of STM32F407x + external LCD, you cannot use a screen-
sized frame buffer like in the case of STM32F429 disc board.
▪ On chip RAM of STM32F407x (168KB) < ( 320 x 240 x 2) Bytes (150KB)
• bsp_lcd.c uses non screen sized buffer of 10KB (Draw buffer)
Draw buffer(10KB)
240 px
16px
Y1
Y2
Draw buffer(10KB)
LCD WRITE
240 px
16px
Y1
Y2
Draw buffer(10KB) Y1
LCD WRITE
240 px
Y2
Draw buffer(10KB)
LCD WRITE
240 px
Dual buffering
Display device with GRAM
Draw buffer-1(10KB)
Draw buffer-2(10KB)
Dual buffering
Update next pixel data Display device with GRAM
Draw buffer-1(10KB)
Draw buffer-2(10KB)
32F746GDISCOVERY
(51)
(16)
200 px
100 Y1
40 px
139 Y2
LVGL
About LVGL
LVGL Simulator
https://lvgl.io/developers
Draw buffer_1
LVGL object
• In LVGL, the basic building blocks of a user interface are the objects, also called
Widgets
• For example, a Button, Label, Image, List, Chart or Text area or just a base object
• All objects are referenced using a lv_obj_t pointer as a handle
• This pointer can later be used to set or get the object's attributes.
• For example, button and label both are lvgl objects of type lv_obj_t, but button
objects may carry some unique attributes that label objects may not have.
• 'Base object' is also a lvgl object or a widget that doesn't carry any special
attributes.
A screen object
• When you register a display driver with lvgl, lvgl creates a ‘screen’ object of type lv_obj_t .
• This screen object is a parent object to which you can add your application-specific child objects.
• The screen object is associated with the display object of type lv_disp_t
• There will be one display object for each physical display. For example, if you are using 2 physical
displays, there may be 2 display objects. Lvgl provides dedicated APIs to change the properties of
the display
• lv_disp_set_rotation()
• lv_disp_set_default()
• lv_disp_get_default() and many
• Each display can have many screen objects, and current active one is accessed by the field act_scr
of the display object
• You can manipulate screen objects by these APIs
• Get the active screen lv_scr_act()
• Load screen lv_scr_load(scr1)
Widgets
• All widgets are lvgl objects of type lv_obj_t .
• A base object is also a widget which only has basic
properties such as
• coordinates
• parent object
• children
• contains the styles
• attributes like Clickable, Scrollable, etc
Y+
I2C3
X+ screen I2C Microcontroller
X-
controller
STMPE811
Y-
Capacitive
I2C3
Touch Touch Panel I2C Microcontroller
Panel Controller INT
RST
FT5336GQQ
GPIO PA15 CS
STM32F407 DISC-1
Y+
SPI1
X+ screen SPI Microcontroller
X-
controller
XPT2046
Y-
STM32F407x DISC board
Analog 4 wire resistive touch panel
Button
(lv_btn)
Label
(lv_label)
Label
(lv_label)
About info
List (lv_list)
Message box
(lv_msgbox)
APIs used
glvgl_widget.c
Settings page
Settings page
Menu heading screen Widgets of the menu page
Menu (lv_menu)
Date setting
Calendar (lv_calendar)
Button (lv_btn)
With animation
Time setting
Roller(lv_roller)
Checkbox(lv_checkbox)
Switch(lv_switch)
Alarm setting
Sound setting
Brightness setting
Alarm notification
Gif image
lv_refr.c
Logging
Display STM32F7x
module MCU
LCD_VSYNC PI9 GPIOG,GPIOI,GPIOJ,GPIOK
LCD_HSYNC Pi10
LCD_PCLK PI14
LCD_DE PK7
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
• Program the new number of wait states to the LATENCY bits in the FLASH_ACR register
• Check that the new number of wait states is taken into account to access the Flash memory by reading the
FLASH_ACR register
• Select the required AHB and APB prescalers
• Configure PPRE2=2, PPRE1=4
• Configure HPRE = 0xxx: system clock not divider
• Configure PLLM = 000010: PLLM = 2, PLLN = 216 , PLLP = 8
• Configure RCC_PLLCFGR register and set PLLON bit of RCC_CR register.
• Wait for PLL lock.
• : Main PLL (PLL) clock ready flag
• Switch the system clock to the PLL.
• SW: System clock switch
• Wait for status
• SWS: System clock switch status
• Check that the new CPU clock source or/and the new CPU clock prescaler value is/are taken into account by
reading the clock source status (SWS bits) or/and the AHB prescaler value (HPRE bits), respectively, in the
RCC_CFGR register.
BHARATI SOFTWARE , CC BY-SA 4.0 , 2021
www.fastbitlab.com
Alpha:
Layer1 = 255
Layer2 = 127
Initialization status