0:09
hello and welcome to controller Tech a
0:12
lot of you guys requested this so today
0:15
we will finally cover one of the
0:16
benefits of using the fsmc peripheral of
0:19
SDM 32 the fsmc stands for flexible
0:24
static memory controller it is an
0:26
embedded external memory controller that
0:28
allows the SDM 32 microcontroller to
0:31
interface with a wide range of memories
0:34
including SRAM nor flash Nan Flash and
0:39
modules as I mentioned we will use one
0:42
of its benefits and that would be using
0:44
the fsmc to interface the LCD module
0:48
MCU we can use the fsmc to interface the
0:51
LCD in the parallel mode be it with
0:54
eight data pins or 16 data
0:57
pins it gives us an advantage that
1:00
instead of Performing the normal gpio
1:02
operations to push the data to the LCD
1:05
we can simply assign the data to the
1:07
fsmc memory and let the peripheral do
1:10
the pushing I will cover this topic in
1:14
parts today we will see the connection
1:17
the pin requirements how to implement
1:19
the fsmc with the display library and
1:22
finally we will turn on the display and
1:24
run something on it in the next part we
1:28
will add the touch interface of along
1:32
project this will make it easier for us
1:35
to add complicated things to the
1:37
project I am going to use the SDM 32f
1:41
412g Discovery board for this
1:44
project the reason is simple it has the
1:47
LCD connected to it using the
1:50
fsmc I don't have any LCD device with me
1:53
that uses the parallel mode so I decided
1:56
to use this board we will check out the
2:00
pin details later in the
2:02
video here we have the schematics of the
2:06
board this is how the LCD is connected
2:10
fsmc the display uses 16 data pins along
2:14
with the other pins required by the fsmc
2:17
peripheral as well now before we go on
2:20
with the project I want to share an
2:23
detail a lot of popular display
2:26
libraries are already available in the
2:30
you can access them by browsing the SDM
2:33
32 Cube folder on your
2:35
computer open the repository folder and
2:39
here you can see the firmware packs for
2:42
series now open the firmware pack and
2:45
look inside drivers bsp
2:48
components here you can get the library
2:51
of different components used in SDM 32
2:55
boards for example we have the library
2:58
for the LCD controller 8347 d i
3:07
s735 as well all these libraries use the
3:11
same structure so if you get familiar
3:13
with one of them you will be able to
3:15
interface other displays as well now if
3:18
we look inside the F4 firmware pack and
3:21
again open the bsp components folder you
3:24
can see other libraries
3:26
also here we have the popular i93
3:30
41 now the display I have on the board
3:33
uses the st7789 H2 controller so let me
3:38
copy the library files to the desktop
3:40
first all these display libraries have
3:43
the same structure let's take a look at
3:48
Library here we have a function to
3:50
initialize the display another function
3:53
to set the display orientation functions
3:56
to turn the display on and off Etc the
3:59
the functions contain the command and
4:01
data to perform the respective operation
4:04
but they do not send the command to the
4:06
display instead we have the LCD IO
4:09
functions to do this job these IO
4:13
functions connect the library to the
4:16
display you can see we have the io
4:18
function for initialization and another
4:22
delay we also have the function to write
4:27
register basically we just need to
4:29
Define these IO functions in a separate
4:31
file and use the appropriate method to
4:34
send the command and data to the
4:36
display the method depends on how the
4:39
LCD is connected to the
4:41
MCU we can use the normal GP iio
4:45
operation the fsmc SBI or i2c however
4:51
connected I will demonstrate this in a
4:54
while let's create a new project in the
4:58
ID I am using the SDM 32f 412g Discovery
5:04
board give some name to the project and
5:08
finish let me clear the pinouts first
5:12
all right let's start with the clock
5:14
setup the board has an 8 MHz Crystal on
5:18
it and I am running the system at a
5:22
clock go to CIS debug and enable serial
5:27
wire now let's configure the FSM C
5:30
peripheral we need to select the chip
5:34
first let's check the pin details in the
5:39
sheet the chip select pin of the LCD is
5:42
connected to the FMC ne1 which is the
5:47
MCU you can see the pin details in the
5:50
schematics Also let's set the chip
5:55
ne1 here you can see the pin pd7 got
6:01
ne1 the memory type is the LCD
6:04
interface set the register select to
6:08
a0 this is as per the connection shown
6:12
schematics the register select is used
6:15
to tell the LCD whether we are going to
6:17
send an instruction or a piece of data
6:21
if you are using an external LCD you can
6:23
choose other values of the register
6:25
select as well depending on how you are
6:30
but in my case the LCD is already
6:33
connected to the board and the RS pin is
6:35
connected to a z the LCD uses 16 data
6:40
pins so select it here now we will
6:46
pins I am going to configure the data
7:00
all right all the data pins have been
7:03
configured the initial part of the
7:05
configuration is kept to default but we
7:08
need to configure the timings here you
7:11
can get more information about the
7:13
timings in the application note a n
7:17
2784 this application note actually
7:19
applies to the SDM 32 F1 series MCU but
7:24
we will just take the important points
7:26
from it here we will look in the nor
7:30
section as shown here if the main AHB
7:33
clock is 72 mahz we need to calculate
7:37
the AHB Cox cycle which will be 13.88
7:41
nond in our case the main clock is 100
7:45
MHz and hence the clock cycle will be 10
7:48
NS make sure you calculate everything in
7:51
Nan as we would do the calculation in
7:54
the same unit we need to calculate the
7:57
address setup time data setup time and
8:00
the bus turnaround time out of these
8:04
there is no formula to calculate the bus
8:06
turnaround time but we can calculate the
8:09
other two here you can see the
8:12
conditions these parameters must
8:14
satisfy and here we have the formulas to
8:17
calculate them the address setup formula
8:20
requires the data setup value so we will
8:23
start with the data setup first we need
8:26
to know the two values to calculate the
8:29
data set up this here is the main clock
8:32
cycle and the wp timing is basically the
8:35
time required for WR enable High to
8:37
write enable low you can find the
8:40
timings in the data sheet of your
8:42
LCD here I have the data sheet of the
8:48
H2 just search for the term
8:54
timing we should look under the timing
8:57
characteristics for the parallel
9:00
here we have all sorts of timings
9:02
required to interface this LCD but I
9:05
don't see the same for the right enable
9:07
High to right enable low on the other
9:09
hand we do have the control pulse high
9:13
durations I will just take the average
9:16
of these two values and use it as the wp
9:19
timing in the formula so we have the wp
9:23
timing at 15 NS with the clock cycle at
9:27
NS the data set set up time will come
9:31
1.5 I will set it to two next we have
9:35
the formula for the address setup we
9:38
will first calculate this much part by
9:40
using the WC timing and the clock
9:45
cycle the right cycle timing as per the
9:52
NS if we divide it from the clock cycle
9:57
6.6 now we will subtract this part from
10:00
the result the data setup value is two
10:03
so we will subtract three from the
10:06
result to calculate the address set up
10:09
we will finally subtract one from the
10:11
result we got the value 2.6 so I will
10:15
use three in the setup there is no
10:18
formula to calculate the bus turnaround
10:20
time so I will just set it to two that
10:24
is all the configuration we need for the
10:27
FMC if the display does not work with
10:29
this configuration we will change it a
10:32
little other than data pins we need to
10:35
configure a few more pins for the
10:38
fsmc the LCD tearing effect pin sends an
10:41
interrupt to the SDM 32 and this is
10:44
connected to the pin
10:45
pg4 so let's enable an external
10:48
interrupt for the pin
10:50
pg4 the read pin of the LCD is connected
10:53
to the FMC n OE which is the pin
10:57
pd4 the n o o e is already enabled but
11:01
we will map it to the pin
11:06
pd4 then we have the right pin connected
11:09
to the FMC nwe which is the pin
11:16
pd5 the pins are s and CS have already
11:20
been configured the reset pin is
11:24
pd11 let's set this pin in as output and
11:27
we will rename it as l CD reset all
11:31
right that is all the configuration we
11:33
need click save to generate the project
11:36
now first of all we will copy the LCD
11:39
Library files to our project so copy the
11:43
C file to the source directory and the
11:45
header file to the include directory
11:48
let's take a look at the source file now
11:51
this LCD driver structure is common to
11:54
all the LCD libraries created by the SDM
11:57
32 but I am not going to use it so let's
12:00
comment it out let's remove this
12:03
inclusion from here as I mentioned we
12:06
need to define a few lcdo functions so
12:10
to connect the library to the
12:12
MCU here are all the functions we need
12:15
to Define in a separate file let's
12:18
create a new header file in the include
12:20
directory and we will call it LCD
12:23
controller inside this file Define all
12:26
the lcdo functions but not as the
12:29
external variables let's include the
12:32
main header file for the necessary
12:34
inclusions in the display header file
12:37
include the LCD controller so that it
12:40
can fetch the LCD IO functions from
12:45
there now create a new source file in
12:47
the source directory and name it LCD
12:50
controller. C here we will write the
12:53
code for all the lcdo
12:56
functions the content in this will vary
12:59
based on if you are using SBI i2c FMC or
13:03
any other method to interface the LCD
13:06
the FMC memory region is defined in the
13:09
MCU itself and it is common for most of
13:13
mcus but I would advise that you still
13:15
check it once before proceeding further
13:18
it can be found in the memory overview
13:20
section of the reference Manual of your
13:23
MCU here you can see the FMC memory
13:26
starts from 60 million hex
13:29
just like we have different methods to
13:31
send the data and command to the LCD
13:33
using different interfaces we also have
13:36
a method to do the same using
13:39
fsmc the memory addresses for the
13:41
command and data need to be different
13:43
here we will first Define a memory
13:46
location for the command and I am
13:48
calling it FMC register
13:51
bank here I am setting the memory
13:53
location at the start of the fsmc
13:56
address the register select is respons
13:59
responsible for selecting the register
14:02
commands if you remember the register
14:05
select is set to a z in this
14:08
case and therefore the memory location
14:11
for the data will start at an offset of
14:14
start this is something you need to
14:18
detail there is not much explained about
14:22
manual here you can see for 16bit memory
14:25
width the internal AHB address line cons
14:29
ERS the address from bit 1 to bit 25
14:32
which is then shifted to the right by
14:33
one place let's understand this in
14:38
detail here I have the picture
14:40
explaining what happens inside the AHB
14:43
address line this here is the 32bit AHB
14:47
address line for 16bit memory width the
14:51
Bit Zero is not considered at all the
14:54
addressing starts from bit one and we
14:57
have a total of 25 five bits starting
15:03
25 so if I use the register select as a
15:06
z this is actually seen as the bit one
15:10
now to send the command this bit should
15:12
be zero and to send the data it must be
15:15
one this setup will make our least
15:18
significant 4bit nibble as 2 hex while
15:20
sending the data and it will remain zero
15:23
for the command the higher four bits of
15:26
this 32bit address are used to select
15:29
the fsmc bank we are using bank one for
15:33
the nor flash so this data will be fixed
15:35
to six hex you can see the details in
15:39
the image shown the bits 27 and 26 are
15:43
used according to the chip select pin
15:47
for one particular Bank the combination
15:49
of these bits selects different CS pins
15:53
then the rest of the 26 bits are
15:55
configured based on which register
15:57
select signal is being used
15:59
all these 32 bits together makes the
16:02
address for the command and data assume
16:05
that I have selected the A4 signal for
16:08
the register select for the 16bit memory
16:11
width the bit five of the address line
16:14
will be configured this will make the
16:16
data address offset as 20 hex the logic
16:20
discussed so far does not work if the
16:23
8bit memory width is used for the 8bit
16:26
width all the 26 bits of the address
16:29
line are used and hence the counting
16:31
starts from zero you can see it being
16:34
mentioned in the reference manual also
16:38
so if you are using eight data lines for
16:40
the LCD and you have selected A4 as the
16:43
register select the bit four will be
16:45
configured for the register
16:47
select this will set our data address at
16:50
an offset of 10 hex so I hope you
16:53
understood how the register select works
16:56
here we now have the addresses for the
16:58
command and data so let's start writing
17:02
functions first we have the
17:06
function many LCDs might not need this
17:09
but just to keep things perfect we will
17:11
write one for this one here we will just
17:17
reset so first reset the pin wait for a
17:20
few milliseconds set the pin and wait
17:24
again this will complete the LCD reset
17:27
the reset of the initialized ation will
17:29
be handled by the LCD
17:31
library next we will write the function
17:34
to send the register
17:36
address here we will just copy the
17:38
register address to the register
17:40
location in the fsmc
17:42
memory then the function to write the
17:45
data here we will copy the data to the
17:48
data location in the memory to read the
17:52
data we will simply return the value
17:56
memory now we have the function to write
18:00
data here we will call the function to
18:02
write the data as many times as the size
18:07
parameter each time we will pass a new
18:10
data value from the given pointer
18:13
location at last we have the delay
18:16
function here we will just call the
18:18
whole delay and pass the parameter delay
18:21
to it let's write the main function now
18:25
we will include the LCD Library file
18:29
now in the main function we will
18:31
initialize the display first let's build
18:35
the project to see if there are any
18:37
errors everything is fine so we are good
18:40
to go here you can see all the functions
18:44
available for the display to check the
18:47
simple working I just want to fill the
18:49
display with some colors but here we
18:52
don't have any function to fill the
18:54
entire display with a color we have a
18:57
function to draw the horizontal Al line
18:59
so we will simply draw the line
19:01
throughout the display let's write a
19:04
function in the main file whose
19:06
parameters will be similar to this line
19:08
drawing function now inside this
19:11
function we will keep drawing the
19:13
horizontal line of the given width for
19:21
height in the main function call the
19:24
function LCD fill let's give some random
19:28
color code here the drawing starts from
19:30
the position 0 0 and it shall draw for
19:33
240 pixel wide and 240 pixel height
19:38
let's give a delay of 1 second and fill
19:41
in another color here I am displaying
19:44
four different colors at an interval of
19:47
second all right let's build and Flash
19:53
board there seems to be some error and
19:56
the display is not turning on actually I
19:59
missed the configuration of the LCD
20:03
control it was not there in the main
20:05
image so I might have missed it here you
20:09
can see the LCD backlight control is
20:11
connected to the pin
20:13
pf5 let's open the cube MX and set the
20:19
output we need to set this pin as high
20:22
which we can do in the code or we can
20:24
also do it here let's generate the
20:27
project again build and Flash it to the
20:39
board you can see the LCDs getting
20:42
filled with different
20:44
colors the colors are switching every 1
20:47
second and our code is working fine so
20:50
far let's try to display some known
20:54
values search for the 16bit color codes
20:59
here I will display the pure red pure
21:01
green pure blue and the yellow
21:07
color let's build and Flash it
21:17
again you can see the LCD is displaying
21:22
colors so we got the LCD working using
21:25
the fsmc mode in stdm 32 you can connect
21:29
any parallel display to the MCU using
21:32
the fsmc given that the MCU supports the
21:36
fsmc this is it for the
21:39
video I hope you understood how to
21:41
configure the fsmc and how to interface
21:44
the display with the MCU using it you
21:47
can read the details explained in this
21:50
video from the link in the
21:52
description the project can also be
21:55
downloaded from the same link this is it
21:59
today keep watching and have a nice day