0:11
welcome to controllers tech this is the
0:14
first video in the series
0:16
where we will be discussing about memory
0:19
there will be few more videos on this
0:21
topic and they all will be mostly the
0:25
as due to the lack of proper resources i
0:28
have put together few conclusions from
0:32
and i will share them with you if
0:34
something you think is lacking
0:36
let me know in the comments i will put
0:40
and release another video so let's start
0:43
with the first one today
0:45
and here we will see what is mpu and why
0:50
memory protection unit is a piece of
0:52
hardware which is attached to the mcu
0:55
itself the main purpose of mpu is to
0:58
prevent any process from accessing the
1:01
that hasn't been assigned to it it does
1:04
that by allowing the privileged access
1:06
for the process in the allocated
1:10
privileged access means that the process
1:12
can use all the instructions
1:14
and have access to all the resources the
1:17
memory protection unit monitors all the
1:20
including the instruction fetching and
1:23
any violation of the access by the
1:25
process will trigger fault exception
1:28
this could result in unpredictable
1:30
behavior and sometimes hard
1:32
fault too we can control the mpu with
1:35
the attributes provided in the cortex
1:37
m7 such as shareability cache ability
1:41
etc we will cover them in upcoming
1:44
there are three main reasons that i can
1:46
think of to use the mpu
1:50
the first one is to prevent speculative
1:52
access to the some memory
1:54
locations then we have dma limitations
1:59
and the third is not a reason but we can
2:03
tasks in much better ways let's start
2:07
access speculative access is when cpu
2:12
some memory locations in advance and
2:14
fetches the instructions or data from
2:17
so that the wait cycles can be reduced
2:20
this accessing is done by the cpu on its
2:23
without any provided instruction and it
2:26
helps improve the performance
2:28
but the problem arises when cpu accesses
2:33
that are not available like external
2:37
this could sometimes result in hardware
2:39
fault and we need to prevent this
2:41
speculative access to such locations
2:45
there are 3 types of speculative access
2:51
speculative instruction fetch and
2:53
speculative cache line fills
2:56
speculative read is when the cpu tries
2:59
to read the data in advance from the
3:01
normal memory regions i said normal
3:06
and this is a type of memory regions
3:09
m7 we will cover it in the next video
3:13
anyway cpu tries to read data from this
3:17
even if the data might not be needed it
3:21
so to reduce the weight cycles and
3:23
improve the performance
3:25
but if the memory location is
3:27
unavailable it can cause faults in the
3:31
there you could see errors like this the
3:34
cpu is trying to access a location
3:36
which isn't available we can use mpu to
3:40
block the access to such memory
3:43
here is the memory map of cortex m7 and
3:46
you can see the addresses from 6 million
3:49
to e-million belongs to the external
3:52
these addresses are already available in
3:54
the core irrespective of whether the
3:56
memory is available or not
3:59
so in case we are not using any external
4:02
we must block the access to these
4:04
locations to prevent speculation
4:06
read to external memories next is the
4:10
speculative instruction
4:11
fetch here the cpu fetches the
4:15
instructions in advance
4:16
so to increase the performance but
4:19
sometimes the instruction is not needed
4:22
or sometimes it fetches the instructions
4:24
that aren't even valid
4:27
we could use m-p-u to block the
4:28
instruction access to any location
4:31
and this would prevent cpu to fetch
4:33
instruction from that memory location
4:36
cache line fill means when the processor
4:39
recognizes that an information being
4:41
read from memory is cachable
4:43
the processor reads an entire cache line
4:45
into the appropriate cache slot
4:48
we can make the region not cacheable to
4:50
prevent speculative cache line fill
4:54
that's all about the speculative access
4:58
now let's talk about the second major
5:00
issue and that is d-m-a
5:03
the d-m-a can't work in the cachable
5:05
regions because it needs data coherency
5:09
as of now the hardware support for data
5:11
synchronization is not available in
5:18
we can achieve the coherency using the
5:22
typically by cleaning the cache and
5:26
but an easier way is to use mpu to set
5:29
the region as non-cacheable
5:30
so that the dma can synchronize with cpu
5:35
we will see more about data coherency in
5:41
another thing we can do using mpu is the
5:45
we can restrict any task within certain
5:48
region to prevent its access to other
5:52
this is a good example to understand it
5:55
you can read more about it on the source
5:59
basically here the task a has been
6:01
restricted to the green memory zone
6:04
while the task v is allowed to access
6:06
the entire memory region
6:08
we won't be dealing with this task
6:11
but we will certainly take care of the
6:13
speculative access and the dma
6:17
this is it for the video the next one
6:20
will cover the memory types
6:22
and attributes types in cortex m7
6:26
keep watching and have a nice day ahead