0:10
welcome to the fifth video in the mpu
0:14
this video is in the continuation from
0:17
and today we will see how to use the
0:19
sub-regions in the mpu
0:23
this is the picture from one of the sds
0:26
video and it shows how the region is
0:30
a region can be divided to eight
0:33
only if the region size is greater than
0:38
another important point is that the
0:40
setting a corresponding sub-region bit
0:42
will exclude the sub region from the mpu
0:46
for example if we have this 8 kilobytes
0:51
if we are using sub region then this 8
0:53
kilobytes region will be divided into 8
0:58
this means each subpart will be one
1:02
now if the subregion setting is zero
1:06
then all the positions that are set to
1:08
one will not be a part of the mpu
1:12
this region will exhibit the default
1:16
and all the positions that are set to
1:18
zero will be a part of
1:19
mpu configuration we will see the
1:27
here i have already created a project so
1:30
i will directly take you to the qmx
1:42
here the clock is set as usual in the
1:47
i have selected the background region
1:51
the base address is set to 3 million
1:54
this is actually the address of one of
1:58
i am also using the 8 kilobyte size
2:02
let's disable the sub-regions at first
2:04
so it will be easier to compare when we
2:10
all access are permitted and the region
2:24
i am also using adma just like the
2:47
here we have 2 buffers each 10 bytes in
2:50
and they are defined at some particular
2:52
locations in the memory
3:04
here the copy buffer is located at the
3:07
and the paste buffer is located at an
3:09
offset of 1 kilobyte from the start of
3:27
you can also see the buffers in the
3:36
here is the c data at the start of the
3:40
and the p data is at 400 offset
3:48
i have created a callback for the dma
3:51
and this flag will be set
3:52
when the data transfer is finished
3:59
here i am registering the callback for
4:03
memory to memory transfer dma don't have
4:07
so we need to register manually this
4:10
parameter here defines
4:12
when the callback will be called this
4:15
you can find in the dma.h file
4:20
this is the id for the full transfer
4:23
and at last we have the callback itself
4:32
now in the while loop we will first set
4:34
the data in the c data buffer
4:37
then start the dma to transfer this data
4:40
here c data is the source and p data is
4:46
then we will wait for the transfer
4:48
complete flag to set in the callback
4:50
and we will repeat the process again as
4:54
for now we have made this region
4:56
non-cachable so this transfer should
4:59
before we run this let me show you how
5:02
the region is set right now
5:11
here is the setting for the region
5:14
even if we consider that the region is
5:15
divided into eight subparts
5:18
here all the subparts are set to zero
5:20
and everything will be included in the
5:27
let's see the working now
5:36
here are both the buffers in the live
5:46
so everything seems to be working all
5:50
both the data buffers have the same data
5:52
so no coherency issue
5:55
this is working because we set the 8
5:57
kilobytes of non-cacheable region in the
6:00
and both the buffers are placed in that
6:04
now let's go back to the q m x and
6:06
configure the sub regions
6:11
right now every region is included in
6:14
and we will exclude the p data from it
6:18
to do that we need to set a one in the
6:21
and that means we need to write zero
6:24
in the mpu sub region settings
6:32
everything else will remain unchanged
6:34
and we will just exclude the p data
6:36
region from the mpu configuration
6:40
this means the p data region will
6:42
exhibit the default memory behavior
6:44
where it is a cachable region let's
6:47
see what happens with this configuration
6:55
we will keep our program same as before
7:14
so everything is working fine here also
7:18
let's understand what's going on
7:20
remember that we have only excluded the
7:23
data region but the c data region is
7:28
so the cpu writes the data to this
7:30
region and since the region is
7:33
the dma is able to copy the latest data
7:37
that's why we see the same data in the
7:44
but if we make the c data region
7:46
cacheable the coherency issues should
7:54
to do that we will set the region
7:56
setting to zero cross zero
7:58
one this will exclude the c
8:01
data region from the mpu and this region
8:04
will say to the default behavior
8:06
which will make it cacheable
8:30
now the p data region is not updating
8:33
this is because the c data region is
8:35
cacheable and the dmas keep fetching the
8:39
which was the initial data in the buffer
8:42
this was explained in the previous video
8:44
and is also known as data coherency
8:48
so we saw even the region was set to
8:51
but with the sub-region configuration
8:53
the c data becomes cachable
8:55
and we had to face the coherency issue
8:58
now let's see what happens if we change
9:01
the location of the c data buffer
9:04
here i am going to put the c data in
9:07
which is set to zero in the sub region
9:11
c hundred would be fine so if we put the
9:15
data buffer at this new location it
9:17
should follow the mpu configuration
9:20
and the buffer should be non-cacheable
9:22
let's make the changes in the location
9:29
here i am updating the location in the
9:34
so we have some error
9:50
here it's mentioned that the memory
9:52
counter cannot go backwards
9:54
well this is happening because we have
9:56
defined the higher location before the
10:00
we need to define the locations in their
10:11
now it builds up successfully all right
10:15
let's see the working now
10:30
as expected now the dma works perfectly
10:34
it's able to copy the newest data from
10:38
because the c data buffer is in the
10:39
non-cachable region now
10:42
remember that only the first sub-region
10:44
was excluded from the mpu
10:46
so if the c data is placed in that
10:48
region it will follow the default
10:50
properties of that memory region
10:53
but now we have changed the location of
10:57
so it is following the properties of the
11:01
this is it for this video i hope
11:04
things didn't got too complicated
11:07
you can ask the doubts in the comment
11:11
this is the last video i have planned
11:13
for the mpu configuration
11:16
but if something new comes up i will
11:20
this is it for now keep watching
11:23
be safe and have a nice day ahead