0:09
hello and welcome to controllers Tech
0:12
this is yet another video on the lvgl
0:14
series on SDM 32 and today we will run
0:18
the entire lvgl application from the
0:21
external flash 3 weeks ago I covered a
0:24
video in the lvgl series covering how to
0:27
store the Assets in the external flash
0:29
and how to load them in the
0:31
runtime the method works fine if you
0:34
have low flash storage on your MCU and
0:37
you want to have a lot of images or
0:40
project there are some mcus which have
0:43
even lower flash storage such that even
0:45
the basic lvgl cannot fit in it the MCU
0:49
I am using has 128 kiloby of internal
0:53
flash memory which is not enough to load
0:57
lvgl I can still load it by heavily
0:59
modif in the configuration file but why
1:02
compromise when we have another option
1:04
of loading the lvgl from external
1:07
flash in the previous videos I covered
1:09
how to deal with w25 Q flash using the
1:13
quad SBI mode on ah7 based
1:16
MCU we saw how to interface the memory
1:19
using quad SBI mode how to create an
1:22
external loader and how to run the
1:24
application from external
1:26
flash I am assuming you have seen these
1:29
videos as I will not cover that part in
1:33
today I am using this custom board based
1:38
MCU these boards are available on the
1:41
controller's tech store so the Indian
1:44
audience can purchase them from there
1:47
there are other stm32 boards available
1:50
as well they all are tested before we
1:52
ship them let's start the cube ID and
1:57
project in the meantime let's download
2:02
library here I am going to download the
2:10
Branch all right I am using h750 vbt 6
2:15
MCU give some name to the project and
2:20
finish let's start with the clock setup
2:23
first here I am selecting the external
2:26
Crystal to provide the clock the board
2:30
has 25 MHz Crystal on it and I am
2:33
running the system at 400 MHz
2:36
clock now we will set up the
2:39
LCD the board has a separate header for
2:42
connecting the LCD or old displays and
2:45
here you can see pins allotted for this
2:47
header the header has the SBI pins
2:50
allotted for the display so better use
2:52
the SBI based LCD or old
2:55
display here you can see the header pins
2:58
on the board and here here you can see
3:00
the pin labeling at the back these pins
3:03
are ordered in such a way that you will
3:05
not be able to directly connect any
3:07
standard SBI display with it instead you
3:11
need to buy the displays manufactured by
3:13
the MCU Dev or directly from the dev
3:17
box but obviously you can use wires to
3:20
connect any other available display that
3:27
128x 128 pixels TFT display made by the
3:32
MCU Dev the pin ordering on this display
3:36
matches with the header pins available
3:39
board you can see the pins are in the
3:42
same order as they are on the board but
3:45
instead of this serial data out pin we
3:48
have the reset pin on the display this
3:51
is fine as we don't really need this pin
3:54
we are not expecting anything in return
3:56
from the display other than this reset
3:59
pin every other pin is ordered exactly
4:02
so I have connected this display
4:04
directly to the board header let's
4:06
continue with the cube MX
4:09
configuration enable the SBI 2 in the
4:11
half duplex Master mode this is because
4:14
I am not using the serial data out pin
4:17
we have some ISU in the clock
4:19
configuration for SBI so let's set the
4:22
source to peripheral clock now I am
4:25
setting the prescaler to reduce the SBI
4:27
clock to 8 megabits per second
4:30
set the SBI data size to 8 Bits clock
4:34
polarity should be low and clock phase
4:37
should be 1 Edge now let's configure the
4:40
pins the mossy and clock pins are PB 15
4:45
respectively let's set these pins for
4:48
the SBI 2 the pin pb12 is the Cs pin so
4:53
let's set it as output and name it as CS
4:57
the pin pb14 is the Miso pin which is
5:00
actually connected to the reset on the
5:02
LCD so let's set this pin as output and
5:05
name it as reset next we have the data
5:08
command pin as pb1 and backlight control
5:12
as PB 0 set both these pins to output
5:16
and name them accordingly all right all
5:19
our pins are configured now let's open
5:21
the gpio settings select both the pins
5:25
and set their output speed to maximum we
5:28
would also need the dma in this project
5:31
so enable it for the SBI TX mode the dma
5:35
mode is normal and set the data width to
5:38
half word I know the SBI is configured
5:41
with 8 bit size and the dma is
5:43
configured with 16 bits you will
5:47
understand it in a while now go to the
5:50
gpio settings select all the pins and
5:53
set their output speed to maximum the
5:56
pin pb0 is the backlight pin so set its
6:00
default output to high otherwise the
6:03
display will remain dark without the
6:05
backlight since we will be running this
6:08
project from the external flash we also
6:11
need to configure the
6:12
mpu I have already explained in the
6:15
previous video running the application
6:17
from external flash let's enable both
6:20
the cache the mpu should be in the
6:25
configuration set the first region as
6:27
the quad SBI Base address with the
6:29
region size same as the memory size 8
6:32
MB all access should be permitted
6:35
instruction access should be disabled
6:37
along with the sharability permission
6:39
but enable the cachable and buffable
6:42
permissions now create another region
6:45
with the same address but the memory
6:48
megab all access should be permitted in
6:51
this region as well instruction access
6:54
should be enabled disable the
6:55
sharability permission but enable the
6:58
cachable and buffable permission
7:00
s that is all we need to configure click
7:05
project let's unzip the lvgl file we
7:08
downloaded and rename the folder to
7:11
lvgl inside the driver's folder in the
7:14
project create another folder named
7:17
lvgl now copy the lvgl directory inside
7:21
this folder creating the lvgl folder is
7:25
necessary as a lot of inclusion will
7:27
follow this pattern otherwise you you
7:29
would need to manually change the
7:31
inclusion in each file now copy this
7:34
configuration template and paste it in
7:39
folder rename the file to LV
7:43
configuration now open the file and set
7:46
this to one so to enable the
7:49
configuration we need to include the
7:51
lvgl folder to our path so open the
7:54
project properties go to cc++ build
7:57
settings compiler include
8:00
paths click adds to add a new path now
8:05
at the main lvgl folder here open the
8:08
main file and include the lvgl header
8:11
file here inside the main function call
8:15
the function LV in it to initialize the
8:18
library in the while loop call the
8:21
function LV timer Handler every 5
8:25
milliseconds everything I am doing here
8:27
has already been explained in the first
8:32
series now open the interrupt source
8:35
file and include the lvgl header file
8:39
inside the cystic Handler call the
8:41
function LV tick Incorporated and pass
8:44
parameter 1 I have not initialized the
8:47
display yet it's just the lvgl
8:51
library let's build the
8:53
project we have got the
8:56
errors if you scroll the console to the
8:58
side here you can see the error region
9:02
flash has been overflowed by around 51
9:06
kiloby basically our internal flash is
9:09
not enough to store the lvgl into it
9:13
this is why we need to load this entire
9:15
application from the external flash to
9:19
do that we will modify the flash script
9:22
first here change the flash address to
9:25
quad SBI address and the size should be
9:31
now open the system file scroll down to
9:33
system init function and add the
9:36
following first reset the configuration
9:39
register and then relocate the vector
9:41
table offset to quad SBI Base
9:44
address that is all we need let's build
9:47
the project again now the project builds
9:51
fine and you can see the updated flash
9:55
analyzer we need to configure the
9:59
let's create a new source file lcdc
10:02
controller. c and a new header file lcdc
10:06
controller. H we will write our LCD
10:11
files the display template can be found
10:14
inside the lvgl examples porting
10:18
folder here we have the LV Port display
10:21
template but there is another template
10:23
dedicated for SDM 32
10:26
devices this is an example implemented
10:29
ation of the LCD drivers for SDM 32
10:33
devices actually with this new library
10:36
the lvgl provides the LCD drivers for
10:42
displays you can see the drivers inside
10:44
the source drivers display
10:47
folder here are the drivers for I
10:57
96 if your display user is either of
11:00
these controllers you can use the
11:02
library directly from here otherwise
11:05
switch to the first video of the lvgl
11:07
series to know how to manually connect
11:10
the library to the driver the display I
11:14
st7735 controller so I will use it from
11:18
here let's copy this code into our LCD
11:21
controller source file we need to modify
11:25
it a little but first let's copy the
11:27
code from the header file into our l CD
11:32
file now open the lvgl configuration
11:35
file and scroll to the bottom here you
11:39
will see the configuration for the LCD
11:42
devices enable the device you are using
11:46
let's build the project once all right
11:49
let's modify the LCD controller file
11:52
include the LCD controller header file
11:55
here I am using st7735
11:59
so include the driver for the same next
12:02
Define the LCD resolution the display
12:11
pixels next is the display
12:13
initialization function here we will use
12:18
7735 create to create the display object
12:22
let's set the rotation to zero next is
12:26
the lcdi iio initialization
12:29
the LCD uses the SBI which is already
12:32
initialized in the main file this
12:35
function is used to register the SBI
12:37
call back which is called when the SBI
12:40
has finished transferring the data to
12:42
the display it is set to call the
12:45
transfer ready call back but we will use
12:47
the SBI transfer complete call back
12:49
instead so let's comment it out the
12:52
default driver uses different pin names
12:55
so we need to change them to what we
12:57
defined in the cubm X here it uses LCD
13:02
reset whereas we defined only
13:05
reset similarly change the LCD CS to CS
13:10
change the LCD dcx to DC also change the
13:14
SBI 1 to SBI 2 all right we have changed
13:19
all the required names if you see the
13:23
st7735 create function here two
13:26
functions are passed as parameters the
13:29
LCD send command is used to send the
13:32
command to the display and LCD send
13:35
color is used to send the data to the
13:37
display before sending the color data to
13:40
the display the SBI is switched to 16bit
13:43
mode and then the dma is called to
13:46
transfer the data this is why we set the
13:49
dma data withth as 16bit whereas the SBI
13:52
was set as 8 bit now once the dma data
13:56
transfer is finished the transfer
13:58
complet call back is called let's copy
14:01
this function and we will replace the
14:03
color transfer ready call back with it
14:06
basically inside this function we are
14:08
informing the lvgl that the display has
14:11
been flushed with the color data and it
14:13
can send another set of data now the
14:16
function in the header file is a little
14:18
different so let's change it here also
14:22
all right let's build the project now we
14:25
have a lot of errors and that is because
14:27
we did not Define the SBI handle typ
14:33
def let's copy it from the main file and
14:36
Define it here as the external variable
14:39
also include the main header file for
14:49
inclusions there are no errors now so
14:52
let's continue with the main file
14:55
include the LCD controller header file
14:58
and let's include the the example header
15:00
file also now after initializing the
15:03
lvgl initialize the display driver also
15:07
you can see the available examples
15:11
directory I am going to use the getting
15:14
started example one this one sets a
15:17
background color and then prints hell
15:19
low World on top of it just to make sure
15:22
the colors are fine I am changing the
15:25
background color to Blue in the heximal
15:28
color system the two bites are dedicated
15:30
for red the next two are for green and
15:33
these two are for blue here I am setting
15:36
all the blue bits to one so the
15:39
background should be blue the hello
15:41
world text color is in white let's copy
15:45
this function and paste it after the
15:50
initialized we don't have any errors so
15:53
we are good to load it to the board
15:56
since we want to run this application
15:58
from an external flash we need to make
16:00
sure that our main flash contains the
16:03
code which makes the jump to the
16:06
flash I explained it in the previous
16:08
video and here is the project which we
16:11
created to make the jump we will first
16:14
flash this project to make sure that our
16:16
internal flash has the code to make the
16:18
jump to the external
16:20
flash all right let's Flash the lvgl
16:24
project now since we are loading it to
16:27
the external flash we need to add the
16:30
external loader to the debug
16:32
configuration here I have the loader
16:35
created in the previous
16:37
videos let's copy it to our main project
16:40
folder then create a new debug or run
16:43
configuration and add the loader to the
16:50
configuration all right let's Flash the
16:53
project to the board now
17:01
you can see the display has been turned
17:03
on but the background color and the text
17:07
expected well this is happening because
17:10
we have enabled the data cache and the
17:12
library uses the dma to send the data if
17:16
you have seen my videos on mpu
17:18
configuration you know what is wrong
17:20
here otherwise I must advise you to
17:22
watch the mpu configuration series if
17:25
you are working with cortex M7 based
17:29
in short dma has coherency suus with
17:33
cash so the first and not recommended
17:35
solution is that we disable the cache
17:39
permanently let's see if we get it
17:46
time you can see now the display has the
17:49
background color and the text on top of
17:52
it if you remember I set the background
17:55
color to Blue but here we are seeing it
17:57
as red we will deal with this issue
18:01
also as I said disabling the cache is an
18:06
recommended let's leave them enabled and
18:09
instead we will clean the data cache
18:11
before transmitting the data the
18:14
function SCB clean dcache by address
18:17
does exactly this the address is the
18:20
parameter here and the address size is
18:23
the size of the parameter I have already
18:26
explained this in another video covering
18:28
the MP U configuration in cortex M7
18:31
processors all right let's build and
18:37
again you can see the display is showing
18:40
the data as it was showing earlier when
18:43
we disabled the cache so we can leave
18:46
the cache enabled and instead clear the
18:48
data cache before transmitting the data
18:50
to the peripheral now let's deal with
18:53
the color issue so in the example
18:56
configuration I set the color blue but I
18:59
got the red color on the display this
19:02
can happen in some displays when the red
19:04
and blue color bites are switched the
19:07
lvgl display Library we are using has a
19:10
solution to this this
19:13
st7735 create function has a flag in its
19:17
parameter let's see what this parameter
19:20
is about we need to navigate to the
19:24
st7735 header file here you can see the
19:28
flag is used used for Mirror
19:29
configuration RGB ordering
19:34
Etc the exact flag can be found inside
19:37
the LCD generic header file here you can
19:41
see the different flags available we
19:44
want to switch the colors from RGB to
19:46
BGR so here is the flag for the same
19:49
let's copy it and paste it in the
19:52
display create function all right let's
19:55
build the project again and Flash it to
19:57
the board reset the board now you can
20:01
see the background color has now been
20:03
changed to Blue so we got the display
20:06
working with the latest lvgl drivers we
20:10
are also able to successfully run the
20:12
lvgl application from the external flash
20:17
this is it for the video I hope you
20:19
understood everything about the lvgl and
20:22
the external flash you can download the
20:25
project from the link in the description
20:28
leave comments in case of any doubt keep
20:32
watching and have a nice day ahead