0:09
welcome to controllers tech
0:11
in the previous video we saw the data
0:15
and how to resolve it this video will
0:18
show an actual working example of what
0:20
we saw in the previous video
0:23
also we will see how to configure the
0:25
mpu in the cube mx let me show you the
0:34
here i have enabled the instruction
0:37
cache and the data cache
0:39
other than that everything is set to
0:49
here i have created two buffers receive
0:54
and both of them have been assigned a
0:56
particular location in the memory
1:03
here is the assignment they are both
1:06
placed in the sram one
1:11
i am doing this because the ram in my
1:13
case starts from dtcm region
1:16
and it's not cacheable therefore the
1:19
demonstration will not be valid in this
1:22
you can watch the memory management
1:24
video to understand this
1:27
check it in the cortex m7 playlist
1:30
let's see example from the previous
1:38
we talked about two different coherency
1:42
first when dma writes to sram
1:46
and second when dma reads from sram
1:59
i am using a memory to memory transfer
2:25
so first we will write some data to the
2:29
and then we will use the cpu to copy the
2:32
data from the tx buffer to the rx buffer
2:35
i am using the cpu transfer first
2:39
let's test this part to see if the
2:41
transfer works in the cachable region
2:44
here you can see the location of the tx
2:46
buffer and the rx buffer
2:54
they are just where we have allocated
3:20
here i have put both the buffers in the
3:33
so the transfer is working all right
3:36
the cpu can copy data around without any
3:40
that's why the cases are very specific
3:48
now instead of mem copy let's try to use
3:51
the dma to transfer this data
3:54
here the source address is the tx buffer
3:57
and destination address is rx buffer
4:00
100 milliseconds will be enough to do
4:04
abort the dma so that we can start it
4:10
all right let's run it
4:18
you can see the tx buffer is updating
4:20
but the rx buffer is not changing
4:24
this brings us to the issue we discussed
4:26
in the previous video
4:29
here both these issues are taking place
4:33
because the dma is reading from the sram
4:38
and dma is writing to sram that is rx
4:42
let's start from the solution for the
4:44
dma reading from sram
4:56
here after the cpu writes the data to
5:00
we must perform a cache clean operation
5:02
which will flush the cached tx buffer
5:05
into the sram so after copying the data
5:10
we must clean cache by using clean d
5:20
let's call the function here the address
5:23
will be the address of the tx buffer
5:25
and the size will be the size of the tx
5:46
now let's see for the dma writing to the
5:57
after the dma is finished writing we
5:59
must invalidate the cache
6:06
we can do it in the transfer complete
6:16
i will just do it here for now
6:20
cash by address the address is the
6:22
address of the rx buffer
6:24
and the size is the size of the rx
6:32
all right the first set of data is
6:38
the second set got copied too
6:47
it's working all right now so whenever
6:50
we are using multiple masters
6:52
we must perform these steps before the
6:57
we must perform cache clean
7:02
and the invalidate cache must follow
7:04
after the dma writes the data into the
7:08
this was the software solution to
7:12
if this seems too much for you there is
7:14
another way around it
7:16
and i personally prefer using the mpu to
7:19
solve the coherency issue
7:22
so let's see the mpu configuration
7:42
first of all here we will select the
7:46
mpu region privilege access only and mpu
7:59
now here we have bunch of settings for
8:03
there are 16 regions for me but this
8:05
might be different for you
8:07
we will start will the region zero
8:11
let's enable it the first parameter
8:14
is the base address here we will put the
8:17
address of our buffers
8:23
the buffers are starting from this
8:34
next is the region size
8:41
i have placed the buffers at different
8:43
locations in the memory
8:50
and together they take around 63 bytes
8:53
from the beginning note that the buffer
8:57
bytes each so they take 20 bytes
9:00
but since i have kept them at different
9:02
locations the region between them is
9:04
also covered in this 63 bytes
9:08
so we will choose the next possible size
9:17
this is the image i showed you in the
9:20
and this have the configuration settings
9:22
for different regions
9:24
here we can choose the region type that
9:29
for example we can make the memory as
9:32
where we can make it shareable and
9:34
bufferable or we can keep it as normal
9:37
but as a non-cachable memory i will go
9:40
with the shareable device type
9:43
just to demonstrate that the normal
9:44
memory can also be made to behave as a
9:50
so the text field will be zero
9:52
instruction should be disable
9:54
as there are no instructions available
9:57
and make it shareable non-cacheable and
10:13
this is as per the requirement mentioned
10:20
similarly if you want to set another
10:23
you can choose here and configure it as
10:35
now since we have configured the mpu we
10:37
don't need this software solutions
10:40
let's just disable them and see if the
10:42
dma can handle the transfer
11:07
you can see the rx buffer is updating
11:11
so the dma is able to read and write to
11:21
i have shown you two different methods
11:24
to handle the data coherency issues
11:26
and you can choose according to your
11:30
just to show you that it is working
11:32
because of the mpu configuration
11:34
let's disable the mpu config and see
11:45
now the data is not updating in the rx
11:49
so configuring the region as a shared
11:51
device made the dma transfer possible
11:54
this is it for this video i hope you
11:57
understood the mpu configuration
11:59
data coherency issue and how to solve it
12:06
this is the end for the mpu
12:08
configuration series
12:10
there is one more topic remaining which
12:13
is about the sub-regions in the mpu
12:15
but we will skip it for now it's not
12:19
unless you are writing a very
12:23
if required i will cover it in the
12:26
since the memory regions are covered now
12:28
i will cover some external memories
12:31
like sdram quad spi and i will also make
12:34
videos on ethernet peripheral
12:37
that's it for today keep watching
12:41
and have a nice day ahead