0:11
welcome to controllers tech
0:13
this is another video in the qsbi series
0:16
and today we will see the memory mapped
0:20
we will also see how to use the external
0:22
flash memory as the internal and how to
0:25
run the application from the external
0:28
this is called execute in place xip
0:32
watch the previous qsbo video if you
0:35
haven't watched it yet
0:37
i am going to start with the same
0:39
project that i created last time
0:42
so let's open the cube id
0:44
and import the previous project
0:57
here you can see i have the same code
1:00
that was present last time
1:02
here we will not perform the read from
1:05
qsbi but instead we will enable the
1:15
once the memory is mapped we can treat
1:17
it as just like the internal memory
1:20
and in order to read the data now i am
1:23
simply using the mem copy function
1:34
let's build and test it
1:40
let's put a break point in the while
1:47
we hit the break point that means all
1:49
the functions were executed properly
1:52
if we check the buffer here you can see
1:54
the data that we wrote in the flash
2:03
the fact that we can use the mem copy
2:05
function means that the external flash
2:07
is an internal memory now and we can
2:10
also view it in the memory window
2:20
here you can see the data
2:37
just to verify this whole process i will
2:40
not enable the memory mapped mode and
2:42
let's see what happens now
2:53
so we got the hard fault and it is
2:55
caused by the mem copy function
2:58
this is because we are trying to access
3:00
the internal memory at a location which
3:08
if you try to browse the memory region
3:10
you can see we can't access it
3:16
so we need to enable the memory mapped
3:22
let me change this data a bit here
3:47
and this time we got the data into the
3:58
also we can access the memory in the
4:02
but remember one thing the memory map
4:05
mode is for read only
4:07
once the memory mapped mode is enabled
4:10
you cannot write the data to the flash
4:13
we will be using this mode to either run
4:15
the application from the external flash
4:18
or to increase the internal flash memory
4:22
let's see how to use it
4:25
first of all we will disable these
4:29
make sure you disable the chip arrays
4:33
this is because when we will load the
4:35
application into the external flash
4:37
first this code will run and then it
4:40
will make a jump to the application
4:43
so if the chip arrays is enabled every
4:45
time this code will run it will erase
4:48
the application code from the external
4:52
so make sure that chip erase it
4:54
commented out all right here we are
4:57
defining a function that will make the
5:01
define the address of the qsbi here
5:05
now after the memory mapped mode is
5:07
enabled disable the cache if you are
5:15
next we will disable the systick
5:26
and finally the code to make the jump
5:30
here we are setting the address for the
5:33
this one is the address for the stack
5:37
and then we call jump to application to
5:42
let's try to debug this to see what
5:46
i am putting a break point at the jump
5:52
as you can see we got into the hard
5:57
since there is no executable code at the
5:59
provided location yet
6:02
all right now we need to write some code
6:05
and store it into the qsbi memory
6:08
i am creating a new project for that
6:11
so choose the board give the name and
6:16
first things first select the proper
6:19
this application will execute from qsbi
6:22
flash so make sure the qsbi clock is
6:25
same as the previous clock
6:27
now we will enable the cache
6:30
let's configure the mpu also
6:37
the address of the qsbr flash
6:40
as i mentioned in the previous video the
6:52
if you remember the memory configuration
6:54
video from the cortex m7 playlist here i
6:57
have explained the memory setups
7:01
we will set the normal region for the
7:06
so it should be cacheable and bufferable
7:08
with tex equal to zero
7:17
first disable the instructions and then
7:20
set cacheable and bufferable
7:25
we will create one more region in the
7:32
the size will only be one megabyte
7:40
and we will keep the same settings just
7:42
enable the instruction access
7:45
this is because our code is going to
7:48
execute from this flash so we need the
7:52
so that's it for the mpu configuration
8:02
now before setting anything up make sure
8:04
you enable the quad sbi
8:12
also make sure the pins are correct
8:15
we don't need to do any configuration
8:19
we are doing this so that we don't
8:21
configure these pins for some other use
8:23
or else the qsb qsbi communication will
8:27
once all the setup is finished disable
8:30
the qsbi as it is already enabled in the
8:33
first part of the code
8:35
all right all the setup is finished so
8:38
click save to generate the project
8:53
now here we will first edit this system
9:00
come to this system init function and
9:02
here we will reset the rcc configuration
9:09
next we need to relocate the vector
9:11
table and we will relocate it to the
9:16
you can also provide the flash memory
9:19
that's it for this let's go back to our
9:24
i will just write a simple code where
9:26
the counter will increment every second
9:29
so create a counter variable and
9:31
increment it inside the while loop
9:34
we need to do one last thing and that is
9:37
to change the flash memory address to
9:39
the qsbi flash memory
9:42
the size is 16 megabytes
9:45
let's build it once to check for any
9:52
no errors and we are good to go
9:55
here you can see the flash has been
9:57
relocated and so are the other things
10:03
now if we want to debug this we need to
10:06
use the external loader
10:08
so go to the debug configuration create
10:11
a new configuration for this project
10:16
now go to the debugger tab
10:19
check the external loader and click scan
10:26
here you can see the list of all the
10:30
here it is n 25 q for f seven five zero
10:36
click apply and click debug
10:43
notice that the debugger will not halt
10:46
in the main function
10:48
but here we see the download is verified
10:52
you can just press the reset once and
10:54
now it came inside the main function
11:00
you can see the memory address here
11:02
corresponds to the qsbi flash memory
11:11
let's add the counter to the live
11:21
you can see the counter value is
11:24
also note the memory address
11:35
we can also browse the memory here
11:41
so the qsbi flash memory is working as
11:43
our internal flash and also we were able
11:46
to execute a piece of code from it
11:49
this is very useful for some
11:50
microcontrollers with low flash memory
11:53
like this one here itself it only have
11:56
64 kilobytes of flash which is not
11:59
enough for majority of the things
12:02
so this way we can increase the flash
12:06
we saw that executing the code from
12:08
external flash involves two things
12:11
the first is to initialize the qsbi and
12:14
set it in the memory mapped mode
12:17
and the second one is the code itself
12:19
which will execute from the flash memory
12:22
you need two different projects for
12:25
but i think there is some way to make it
12:27
work in a single project itself
12:30
i will try to look for it and if i do
12:32
succeed i will release another video on
12:36
in the meantime do let me know if you
12:38
want to see the qsp a tutorial for mt25
12:42
flash memory on the h745 board
12:46
this is it for the video
12:48
the code will be updated on the github
12:50
and the link is in the description
12:53
leave comments in case of any doubt
12:56
keep watching and have a nice day ahead