0:09
hello and welcome to controllers Tech
0:12
this is yet another video covering the
0:14
w25 qor flash memory in the qsbr mode in
0:19
the previous video we saw how to connect
0:21
the flash memory to the MCU and how to
0:24
initialize write read and enable the
0:27
memory mapped mode as mentioned in the
0:30
previous video today we will see how to
0:33
create an external loader for a specific
0:35
flash memory and controller combo and
0:38
how to use the external loader to
0:39
program and debug the external flash
0:43
memory here I have created a new project
0:46
with a new name but it is basically a
0:48
replica of the previous
0:50
project everything is the same as where
0:53
we left in the previous
0:55
tutorial I have given a new name to it
0:58
so that it must be clear that this this
1:00
is the project for external
1:02
loader let's debug it once to see if
1:05
everything is working fine I am setting
1:08
a breakpoint at the while loop like I
1:10
set the last time all right we have hit
1:13
the break point and the read buffer
1:16
contains the data from the
1:18
memory this means everything is fine and
1:20
we can proceed with this
1:22
project we will use the guide provided
1:25
by the SD to create a new external
1:28
loader you can see SD's repository is
1:31
dedicated to it you should download this
1:35
entire directory as we need to copy
1:37
certain files from it the files in this
1:40
directory work well with the qsba code
1:43
structure provided by the
1:45
street this is why our functions in the
1:48
quad SBI source and header files are the
1:52
code before you proceed to make an
1:54
external loader you should also check
1:57
their main branch of the repo it
2:00
contains some loader projects for the
2:02
combination of the flash memory and the
2:05
microcontroller so if you have any of
2:07
these combinations you can directly use
2:09
them instead of creating a new
2:12
loader Unfortunately they don't have the
2:14
combination of the w25 Q32 with the L
2:18
496 nucleo board so I am creating one
2:22
here I have already downloaded the
2:24
directory so let's open it go to the qbi
2:28
testing folder and open the main test
2:30
source file before proceeding with the
2:33
loader we will perform a final test for
2:35
the memory so let's copy the contents
2:38
from this main file and paste it in our
2:43
project here by default 100 sectors are
2:47
testing each sector is 4 kiloby in size
2:51
so this will test the first 400 kiloby
2:55
memory all right let's debug the project
2:58
now set the break points at each of
3:01
these while Loops to see if something
3:03
has gone wrong let's run the debugger
3:09
now we have hit the final break point
3:12
that means everything was fine during
3:13
the test the qbi memory passed the test
3:18
successfully and we can proceed with the
3:20
loader this code actually first writes
3:23
the data to the different sectors and
3:25
then compares the sector's data with the
3:27
memory to verify if the data is
3:30
correct the code works fine means the
3:33
qbi is responding well now go to the
3:36
directory we downloaded and open the
3:39
loader files folder if you have ah7
3:42
based device you need to copy these
3:45
files otherwise open the other folder we
3:48
need to copy these files in our project
3:52
copy the source files into the source
3:54
directory head a file into the include
3:56
directory and the Linker file in the
4:08
folder the loader source file contains
4:10
the code for initialization of the
4:12
loader along with other functions like
4:14
write arrays and verify the data it uses
4:19
the same qbi functions that we used in
4:28
project the device info file contains
4:31
the information about the
4:33
loader here you can give a name to the
4:35
loader which makes it easier to identify
4:39
MCU it fetches the memory flash size the
4:43
sector size and the page size
4:45
information from the Quad SBI header
4:47
file which we declared in the previous
4:50
tutorial also set the qbi start address
4:54
as per your MCU as I explained in the
4:58
tutorial let's open the Linker file this
5:02
is not being used right now as the
5:04
project is still using the default flash
5:07
file before we make this a default file
5:11
make sure the Ram size is correct for
5:14
controller for my case this is 320
5:19
Koby although the origin has some offset
5:22
here so the actual size will be a little
5:24
less than 320 Koby but that's fine now
5:29
we have to make this Linker file as the
5:31
default Linker so open the project
5:33
properties go to cc++ build
5:37
settings under the Linker click on
5:40
General here we have the path to the
5:43
current Linker file so we will change it
5:47
dold uncheck the discard unused section
5:50
click apply to save the
5:54
configuration now build the project to
5:57
generate the loader file
6:05
here you can see the new Linker file is
6:08
being used for the project now under the
6:11
debug folder you can see the project.
6:15
file this is the file we can use as the
6:18
loader to do so we will open the project
6:22
folder and rename this file to the
6:25
SLDR we have the loader file ready to be
6:28
used now now although there is one more
6:32
way to generate the file
6:38
automatically we can use the post build
6:40
script to automatically copy and rename
6:43
the file go to cc++ build settings
6:50
again under the build steps tab paste
6:54
the command in the post build
6:56
command now rebuild the project
7:00
now we have the loader file generated in
7:02
the main project folder
7:04
itself so we were able to successfully
7:07
generate the external loader
7:12
file now we will copy this file with the
7:15
other loader files inside the cube
7:18
directory in my case it is located in
7:21
program files SD folder SDM 32 Cube Cube
7:26
programmer Vin external loader
7:33
now let's see how to use the loader file
7:35
in Cube programmer open the cube
7:39
programmer click on the external loader
7:42
to see the available loaders here you
7:45
can see our loader in the list this is
7:48
the same name that we set in the device
7:50
info source file the board is L 496
7:54
start address is 90 million hex memory
7:57
size is 4 megabytes and the page size is
8:01
256 bytes select the loader and connect
8:05
the board now go to the memory Tab and
8:09
read the address 90 million hex here you
8:12
see we got the data stored in the qsb
8:15
memory this data was stored during our
8:18
previous test and we did not erase the
8:21
memory after that we can load the data
8:24
into the memory and to test it there is
8:27
a 1 mbte bin file provided in the
8:32
directory let's go to the download tab
8:36
browse the file set the address 90
8:38
million hex make sure the verify
8:41
programming is checked so that it can
8:43
read the entire memory and verify if the
8:57
successful you can see the right and the
8:59
red both were successful if we check the
9:03
data in the memory we can see the
9:07
data so we were able to successfully
9:10
program the data into the qbi memory
9:12
with the help of the cube programmer now
9:15
let's see how to use the external loader
9:18
in a practical application in the cube
9:23
ID I am going to use the previous
9:31
here we have a right buffer which is
9:33
defined somewhere in the ram suppose
9:36
this buffer contains the image data or
9:39
the video data then we can't afford it
9:41
in the RAM and hence an external flash
9:44
memory is a better storing option for it
9:47
to push it to the external flash memory
9:50
let's give it a section attribute and
9:51
point it to the X flash
9:54
location now we need to define the
9:56
section in the Linker script so open the
10:00
flash Linker file and let's define the
10:04
first this will be a readon memory the
10:08
origin address is 90 million hex with
10:15
megab now inside the section we will add
10:18
a new section for the external
10:20
flash here Define the section we used
10:23
for the right buffer and point the
10:25
external flash section to The qbi Flash
10:29
memory this is it let's build the
10:35
now you can see that the qsb a flash has
10:38
been added to our memory regions and 22
10:41
bytes are occupied in it you can also
10:44
check it in the memory details tab here
10:47
you can see the right buffer is located
10:49
at the address 90 million hex and it
10:52
occupies 22 bytes in the memory we are
10:55
not going to erase the memory or write
10:58
any data to the meory memory now just
11:00
initialize the qsp and enable the memory
11:04
map mode to test it better let's copy
11:07
the data from the right buffer into the
11:09
read buffer we also need to enable the
11:12
external loader but let me first debug
11:15
without it this will clarify your doubt
11:18
about why we need the external loader in
11:23
place let's set a breako at the mem copy
11:27
function you can see the right buffer is
11:30
located at the address 90 million hex
11:33
let's also enable the memory viewer for
11:39
region all right we have hit the break
11:42
point the memory mapped mode was
11:45
successful so we can see the memory data
11:48
in the debugger you can see the memory
11:50
still contains the old data although the
11:54
right buffer has been allocated to this
11:56
location but the data inside the right
11:58
buffer is is still not present here
12:01
instead the right buffer now points to
12:03
the data which was already present in
12:05
the flash memory this is not something
12:08
we want we want the right buffer data to
12:10
move to the external flash memory but we
12:14
couldn't achieve it because we did not
12:15
use the external loader so let's go to
12:19
the debug configuration the debugger Tab
12:22
and add the external loader the loader
12:25
should not be present in the list here
12:27
so we have to manually at
12:30
it I am allocating it from another
12:36
folder click apply to save the
12:38
configuration and debug the project
12:45
now let's run the debugger now we have
12:49
hit the break point and you can see the
12:51
external memory has been updated with
12:53
the new data this is the same data which
12:56
was stored in the right buffer
12:59
also note that we are not using any
13:01
right function here the data is stored
13:04
here because we pointed the right buffer
13:06
to this address the way it works is it
13:09
erases one sector at a time and copies
13:11
the required data into the memory
13:14
without us manually performing the right
13:16
operation this is exactly what the
13:19
loader is needed for if we copy the data
13:22
from the right buffer we get the exact
13:24
data that we stored in it imagine if you
13:27
have the large image data you can point
13:30
it to the external flash memory and then
13:32
later send it to the display when needed
13:35
this is what we will be using the
13:37
external flash memory 4 if you want to
13:40
execute the application from the
13:42
external flash check out another video
13:45
about the qbi xip in the qbi playlist in
13:49
the upcoming videos I will cover how to
13:52
use the external flash to store the
13:54
image data for the lvgl and touch
13:57
gfx this this is it for this video I
14:01
hope you understood how to deal with the
14:03
external flash memories using qbi and
14:06
how to create an external loader you can
14:09
download the code from the link in the
14:12
description leave comments in case of
14:14
any doubt keep watching and have a nice