0:09
hello and welcome to controllers Tech in
0:12
the last two videos on w25 Q Series we
0:16
saw how to use the qbi mode and how to
0:19
create and use the external loader for
0:21
w25 Q Flash in qbi mode we also saw the
0:27
advantage of using the memory map mode
0:29
as it increases the flash memory of our
0:32
MCU this is generally useful when using
0:35
a graphic library for the UI design as
0:38
the images and fonts take a lot of space
0:42
memory while researching on the qbi I
0:45
found out that we can also make the
0:47
external loader using the normal SBI
0:50
mode so today's video will cover how to
0:53
create an external loader for the w25 Q
0:56
flash memory in the normal SBI mode this
1:00
is really useful for the low flash MCU
1:03
that do not support the qbi
1:06
peripheral although we cannot use the
1:08
memory maap mode we certainly can use
1:10
the cube programmer to load the data
1:13
into the external flash which we will
1:15
later read with the help of an external
1:18
loader I will continue with the f407 Z
1:22
MCU that I was using in the w25 Q
1:26
videos I have the required files here
1:28
for the project these are the files we
1:31
used in previous videos but they are all
1:34
modified a little I will explain the
1:37
modification as we proceed with the
1:39
video here is the last project we made
1:42
for the w25 Q flash using the SBI
1:46
mode I will create a new project using
1:49
the configuration from this one let's
1:52
start the cube ID and create a new
1:55
project using an existing configuration
1:58
file now browse the configuration file
2:02
from the SBI project and give some name
2:05
project we don't need to change any
2:08
configuration as the connection will
2:10
remain the same as we used
2:12
previously go to the project manager
2:15
code generator and check the separate
2:18
file generating option click save to
2:26
project let's copy the library files now
2:30
copy the source files into the source
2:32
directory header files into the include
2:35
directory and the Linker file in the
2:37
main project folder all right let's see
2:40
the w25 Q header file
2:44
first here I have Define the memory size
2:47
sector size Etc as they would be needed
2:50
by the loader you only need to change
2:53
the memory size and the rest of the data
2:56
Remains the Same for the w25 Q series
3:00
then I have defined the commands to be
3:02
used in the source file you can cross
3:05
check these commands with the data sheet
3:07
of your memory but I guess they remain
3:09
the same throughout the memory
3:11
series then we have the functions which
3:14
we have covered in the previous w25 Q
3:18
videos other than that I have defined
3:21
some new functions which will be used by
3:24
the loader file let's check the w25 Q
3:28
source file now now this file is mostly
3:32
the same as it was in the last tutorial
3:34
we covered I have added this weight for
3:37
right function which Waits until the
3:39
right operation in the flash memory is
3:42
complete here we will read the status
3:45
register one whose first bit is set if
3:48
the right operation is going on we will
3:51
keep reading the register until the bit
3:53
is zero which means the right operation
3:55
is over this function is called after
3:58
every right operation in the library
4:02
after that we have the same function we
4:04
defined in the previous
4:06
tutorials the flashrite memory will be
4:08
used by the loader to write the data
4:15
memory here in the loader source file
4:18
the right function calls the qbi write
4:21
memory to write the data to the memory
4:24
it takes the parameters as the address
4:25
to write the size of the data and the
4:30
this is why I used the same parameters
4:32
here for the flashight function we will
4:35
simply replace the qbi function with
4:38
ours this flashight function is similar
4:41
to the right clean function we defined
4:43
in part two of this series we just don't
4:47
need to erase the sector before writing
4:49
the data into it as the loader takes
4:51
care of it on its own also the right
4:54
clean function is written in terms of
4:56
page and offset so we will first extract
4:59
the same from the addressed data after
5:02
that the function is exactly the same in
5:06
the end we wait for the right operation
5:10
complete similarly in the flash read
5:13
memory we will first extract the page
5:15
and offset from the address data and
5:17
then call the fast read command to read
5:19
the required number of
5:21
bytes the sector erase function in the
5:24
loader file takes the parameters as the
5:26
address of the start sector and the end
5:30
this is why the flash sector arrays
5:32
function also has similar
5:35
parameters the sector arrays function we
5:37
wrote takes the sector number as the
5:39
parameter so we first calculate the
5:41
sector numbers first and then call the
5:45
function then the chip arrays and the
5:48
reset functions are called as it
5:53
is let's check the loader source file
5:56
now here we have the loader initialized
6:00
function let's compare it to the
6:03
original function in the
6:05
repository here in the loader
6:07
initialization they are initializing the
6:09
qbi and enabling the memory mapped mode
6:14
we will simply initialize the SBI and
6:18
device then we have the right
6:23
function here they are both the qbi and
6:26
then call the function to write qbi
6:30
we will simply call the flash memory
6:33
instead similarly call The Flash read
6:36
memory in the read function the sector
6:38
arrays in the arrays function and the
6:40
chip arrays in the mass arrays
6:43
function the check sum will remain the
6:46
same I have made changes in the verify
6:50
function in the original function they
6:53
enable the memory mapped mode and then
6:55
compare the memory data with the
6:57
original one but but since we don't have
7:00
the memory mapped mode we will read the
7:02
data from the memory and then compare it
7:05
to the original data that's it for the
7:07
loader file let's check the device info
7:15
now here we will set a name for the
7:21
loader I am leaving the memory start
7:23
address to default 90 million hex the
7:27
details like flash size page size and
7:30
sector size will be fetched from the w25
7:33
Q header file that is all we need to set
7:36
up let's build the project now we don't
7:40
have any errors but there are three
7:42
warnings Let's ignore them and now we
7:45
will set the Linker file in the project
7:48
properties let's also copy the post
7:51
build script open the project properties
7:55
go to C C++ build settings open the
8:00
build steps Tab and paste the post build
8:03
script here now open the Linker
8:06
configuration here we will set the
8:08
Linker file as the default Linker for
8:14
project make sure to uncheck the discard
8:17
unused section tab now click apply to
8:21
save the configuration and build the
8:23
project again the project builds
8:26
successfully and here you can see the T
8:29
ldr file now we will copy this file to
8:33
the cube programmer directory with the
8:39
loaders so open the cube programmer
8:42
folder then external loader and copy the
8:48
here all right now launch the cube
8:54
programmer let me deselect the previous
9:00
here is our loader with 2 megabyte
9:02
memory size let's select it and connect
9:06
the board now we can read the external
9:09
flash at the address 90 million hex this
9:13
data you see is from my tests so we can
9:16
read the memory address 90 million hex
9:19
with the external loader let's generate
9:22
a random bin file to flash to the memory
9:25
this is an online tool to generate the
9:27
bin file let's set the size to 2
9:31
kilobytes and I only want the digits in
9:33
the file let's save the
9:41
file now we will flash it to the
9:44
external memory open the cube programmer
9:47
go to the download tab browse the file
9:50
we just downloaded set the memory
9:52
location to 90 million hex make sure the
9:55
verify programming is checked the file
9:58
has has been downloaded and verified
10:01
successfully let's read the memory
10:04
again here you can see the new data in
10:07
the memory you can compare the beginning
10:10
and end of the data with the original
10:18
values so we can Flash the bin file to
10:21
the external flash just to make sure
10:24
that this works with the external loader
10:26
let's deselect the loader and try to
10:33
data we got nothing here so this only
10:36
works with the external loader since the
10:39
memory mapped mode is not available with
10:42
the SBI mode we cannot reallocate memory
10:44
like we did during the
10:46
qbi but we can use the cube programmer
10:49
to flash the data like images fonts or
10:52
videos to the external memory I will
10:55
make videos on how to do it for the lvgl
10:59
gfx this is it for today I hope you
11:03
understood how to create the external
11:05
loader using the S SPI mode you can
11:09
download the code from the link in the
11:11
description leave comments in case of
11:14
any doubt keep watching and have a nice