0:09
hello everyone welcome to controllers
0:12
Tech today with this video we are going
0:15
to start the ethernet Series where we
0:18
will cover all sort of
0:20
protocols this video will cover the
0:22
initialization of the ethernet port and
0:24
in the end we will do the Ping test
0:28
before I start the video I want to share
0:30
some important information so first
0:33
listen to the information and then
0:36
decide for yourself after I saw some
0:39
different MCU I found out that there are
0:41
four major things with the ethernet some
0:44
of the boards of media independent
0:46
interface Mii while the others have
0:50
Mii other than this some MCU let us
0:54
configure the memory in the cube MX
0:56
While others don't these four things are
0:59
mixed up with each other so your board
1:01
could have Mii with memory config or
1:04
without it or the RMI with memory config
1:08
or without it I am going to make two
1:11
videos for the initialization of the
1:13
hardware itself one of the boards I have
1:16
supports Mi with memory configuration
1:19
while the other have our Mi without
1:23
configuration but again since we don't
1:25
know what you could have watch both the
1:27
videos carefully let let's assume for
1:30
now that I don't know which one do I
1:33
have we will find out eventually as we
1:36
progress in the video now let's see the
1:39
problems you are going to face most of
1:42
you are going to face hard fa issues I
1:45
know this I have seen the watch time in
1:47
my videos and there are very few who
1:50
actually watch till the end let me be
1:53
clear here the half fa you are going to
1:55
get is because of the memory issue and I
1:58
am not going to address any comment
2:00
regarding hard fault errors probably I
2:03
will delete them too so if you don't
2:06
want the hard fault watch the video
2:08
carefully and listen to every
2:11
explanation the next problem is the
2:13
memory issue if you have less than 80
2:16
kiloby of Flash and don't know about
2:19
qspi then don't watch the video I will
2:23
eventually make some videos about
2:24
booting from qspi you have to wait till
2:28
then same goes for the ram last but not
2:32
least watch the previous videos about
2:35
memory configuration and mpu
2:38
configurations first don't comment about
2:41
not understanding The Flash script or
2:43
mpu part so if you are okay with
2:47
everything let's start the
2:58
h74 Discovery board p and here is the
3:04
it let's give some name to the project
3:10
finish by the time it configures the
3:13
cube let's take a look at the
3:24
schematics here is the ethernet module
3:27
and as you can see it have the Mii
3:30
connection type remember that the MCU
3:33
can support both types but what is
3:35
connected with your Hardware that
3:38
matters all right let's keep it open and
3:48
MX first things first let's configure
3:55
clocks I am selecting external
3:57
high-speed Crystal to provide the clock
4:03
make sure you use the correct Crystal
4:05
frequency at the input let's configure
4:12
frequency 400 mahz is enough the clocks
4:24
now note that the cach are disabled by
4:27
default and I am leaving it like this
4:30
let's go to the ethernet tab enable the
4:34
module I have Mi type connection on this
4:37
board so I am going to choose Mii we
4:40
will configure the parameters in a while
4:43
but first take a look at the GPI
4:50
o the cube MX mostly configures the
4:53
wrong pins by default so make sure that
4:56
you choose the right ones match every
5:00
schematics in this case they are all
5:03
configured correctly so it's fine if any
5:06
pin is incorrect you can click on the
5:09
correct pin and choose the function the
5:12
incorrect one will disable
5:14
automatically now comes the very
5:16
important part memory
5:19
configuration here we have some buffer
5:21
lengths and their addresses to configure
5:25
these RX and TX are the dma descriptors
5:28
and if you remember the dma issues with
5:30
cash I think you got an idea about the
5:32
part mpu is going to play here notice
5:36
that here the cube MX is letting me
5:38
configure the memory locations so this
5:41
is the memory config type I can leave
5:44
everything to default here but just for
5:46
the sake of explanation I am going to
5:49
choose another memory
5:50
location let's see the reference manual
5:54
first go to the memory organization to
5:57
find more about memory dist
6:07
distribution here I have a lot of
6:10
srams the main code is organized in the
6:13
axi SRAM and let's say I don't want to
6:18
it I have few more options to choose
6:21
from and I am going with SRAM
6:26
1 this is 130 Koby in eyes and it's
6:33
job SRAM 1 start at the address of 3
6:37
million and that's where I am going to
6:51
descriptor now the length of descriptors
6:54
is set to four by default so let's leave
6:56
it like that but I don't know how how
6:59
many bytes does one dma descriptor
7:02
takes if it's 24 bytes then the total
7:06
size for RX descriptor would be 96 bytes
7:09
but if it's 32 bytes then the size will
7:14
bytes let's go with the higher range and
7:17
I am assuming that the hdma descriptors
7:20
is going to occupy 32
7:22
bytes so the memory occupied by each
7:25
descriptor will be 128
7:28
bytes now now we need to put the address
7:30
of TX descriptor at an offset of 128
7:35
bytes and therefore the address for TX
7:37
descriptor will become
7:40
3,80 now comes the RX buffer the total
7:44
space occupied by both the descriptors
7:46
is 256 bytes so we will keep the RX
7:55
offset so the RX buffer address will be
8:02
the length of the RX buffer is
8:06
1,524 and I will explain this in a while
8:10
so everything is set for the ethernet
8:12
now let's enable the lightweight
8:14
IP okay it's not letting me enable
8:20
this this is because the cash are
8:23
disabled so let's go and enable the
8:44
it let's configure this first option is
8:49
if we want to enable the
8:51
DHCP enabling Dynamic host will assign
8:54
the dynamic IP address to our module but
8:57
we will disable it and the assign the IP
9:01
ourselves this will be a static IP
9:03
address and it's easier for us to test
9:05
with right now so let's assign some IP
9:09
address neck mask and the Gateway leave
9:12
everything to default here and we will
9:21
option here this option is for free
9:24
R and since we are not using it it's
9:27
disabled next we need need to set the
9:30
memory pool size let's keep it 10 kiloby
9:33
for now it's enough for our current
9:42
application now comes another memory
9:47
assignment let's see our memory
9:49
distribution by far the memory starts at
9:53
3 million and here we have the DMX
9:56
descriptor then at an offset of 100 128
10:00
bytes we have dmat TX
10:05
descriptor again at another offset of
10:08
128 bytes we have RX
10:13
buffer I forgot the size of RX
10:18
buffer the length was
10:22
1,524 the size will be RX buffer length
10:25
multiplied by RX descriptor length the
10:30
6,096 bytes in total the address here
10:35
80 here is 100 and the address at the
10:39
end of RX buffer will be 18
10:47
d0 totally they takes
10:59
now we need to assign the address to
11:01
this 10 kilobytes of
11:04
Heap so we will assign it here but not
11:07
exactly to the very next position let's
11:10
round it up a little 2,000 seems
11:15
fine the address for the Heap pointer
11:24
3,200 so this is our entire memory range
11:28
starting from 3 million and going up to
11:32
4,800 a total of 18 kiloby of
11:41
ram out of this 10 kiloby is used by the
11:45
Heap around 6 Koby is used by these
11:48
buffers and then there is some space in
11:50
the middle so that completes our memory
11:53
allocation for now let's see the rest of
12:01
leave the rest of them as it is we don't
12:04
need to set up any of
12:15
these here make sure the hardware check
12:23
enabled and in this platform setting
12:26
both are set as Lan 8742
12:33
that completes our configuration for the
12:36
lwip and now comes the
12:39
mpu if you haven't watched the mpu
12:42
configuration videos don't complain
12:44
about this part let's select the mpu
12:54
region our Base address is going to be
12:57
the address of the SRAM 1 where
13:02
starts enter the Base address
13:06
here now the size of the region we are
13:10
using a total of 18 kiloby of this Ram
13:13
so we need to choose 18
13:17
kilobytes after 16 we have 32 so select
13:24
size now comes the configuration
13:30
I hope you remember this picture from
13:32
the memory attributes video as we are
13:35
using the dma descriptors in the normal
13:38
memory region we need to make it
13:40
non-cashable so I think this one should
13:43
work the text value is one and it is
13:46
non-cashable non- buffable but
13:52
sharable all right let's set the region
13:59
permit the access set the text as one
14:01
and set the rest of the
14:10
configuration so that's it we have
14:13
configured the mpu also click save to
14:26
project let's build the code once to see
14:33
details if you notice here the ram D2 is
14:37
still unused even after we have defined
14:39
the buffers in the ram this is because
14:42
we still need to configure The Flash
14:47
script before we do that open this
14:50
etherne if. C file this is where
14:53
everything is configured even the pin
14:56
connections but here we are only in
15:00
definitions we are using GN see so this
15:04
is our region here the sections are
15:07
already defined we just need to Define
15:09
them in the flash script if you haven't
15:12
watched the memory configuration video
15:15
yet we watch it first or else you are on
15:17
your own I am going to call it lwip
15:22
section let's define the memory
15:24
locations for all those sections
15:27
individually make make sure you use the
15:30
same locations that you have used in the
15:33
MX I hope you remember this from the
15:36
memory management video all the sections
15:39
should be same as they are defined in
15:41
the etherne if. C file
15:59
so I have defined them and now if we
16:01
build the code you can see the D2 RAM
16:11
occupied we can see the locations in the
16:18
details apparently the dma descriptors
16:21
are taking 96 bytes each but that's all
16:24
right since we have given them the space
16:36
fine so this completes the configuration
16:40
part now let's write some
16:49
code I am disabling the second core
16:52
related functions you don't need to
17:00
write the exact same code that I am
17:06
writing ethernet if input handles the
17:09
incoming data it determines the type of
17:13
package received and calls the
17:15
appropriate input function this is just
17:32
this set a break point here and run it
17:37
this is to check if there is any hard
17:38
fault due to memory issue so we hit the
17:42
break point and everything is fine now
17:45
we will let it run freely and we are
17:48
going to Ping to the IP address
18:12
let me reset it once all right it's
18:16
working pretty good our static IP
18:19
address is responding well the
18:21
initialization of the hardware is
18:23
complete and we can go for some
18:25
protocols now this is it for the video
18:29
make sure you watch the another video
18:31
which will cover the RMI with no memory
18:34
configuration in Cube MX you can
18:37
download the code from the link in the
18:40
description keep watching and have a