0:10
hello and welcome to controllers tech
0:13
few months ago i covered the ethernet in
0:15
stm32 which includes udp tcp and http
0:21
based servers and clients
0:24
all the videos we covered so far were
0:29
as promised in the last video today we
0:31
will start another series for the
0:33
ethernet videos but this time we will
0:38
in order to use the lwip with the rtos
0:42
sdm stm32 uses the netcon api which is
0:46
basically to make the stack easier to
0:48
use compared to the raw api
0:51
you can think of the netcon as a layer
0:53
on top of the raw api that we used so
0:57
for this video i am going to use the
1:00
controller with rmii connection type and
1:02
no memory configuration
1:05
if you are using the mcu which allows
1:07
you to configure the memories you should
1:09
watch my first video on ethernet or wait
1:12
for the next video as i will use the
1:15
h745 controller in the next video
1:19
if you don't know what memory
1:20
configuration means or what am i even
1:23
talking about please go and watch the
1:25
first two videos of the ethernet series
1:28
the link to the playlist is in the
1:32
other than the ethernet configuration
1:34
the things will remain same for all the
1:36
controller types and by this i mean the
1:44
let's start the video and create a new
1:46
project with cube ide
1:52
stm32f750 discovery board
1:55
give some name to the project and click
2:01
let me clear the pin outs first
2:15
we will start with the clock
2:18
i have 25 megahertz crystal on board and
2:21
i am running it as 200 megahertz clock
2:32
all right now go to the ethernet and
2:35
enable the type of connection you have
2:38
as i mentioned earlier this board have r
2:40
m i i connection type
2:43
let's start with the parameter
2:47
since we are using the on-board
2:49
connector the phy address must be zero
2:53
also change the rx mode to the interrupt
2:58
when you do this you can see the
3:00
ethernet interrupt is enabled
3:03
finally do check the pin outs and match
3:05
it with the schematics of your board
3:08
also make sure that the speed is set to
3:21
next go to the free r t o s
3:25
i am enabling the version 2 of the c m
3:29
no changes are needed to be made in the
3:34
just leave everything to default
3:37
you can see there is a default task
3:39
created and later the lwip will use this
3:43
task so leave this too i am enabling the
3:47
new library re-entrant as it gives the
3:49
error while generating the code
3:59
here first of all we will disable the
4:01
dhcp and manually enter the ip address
4:14
you can see here the rtos usage is
4:17
enabled by default as we have enabled it
4:22
anyway leave everything else to default
4:24
in the general settings
4:27
in the key options the only change we
4:29
need to make is increase the heap memory
4:34
i am setting it to 10 kilobytes
4:37
this is it for the lwip configuration
4:40
leave everything else to default for now
4:45
last but not least since we are using
4:48
the rtos we have to use the time base as
4:51
anything other than cystic
4:53
i am using the timer 6 for this purpose
4:57
all right if you are not using cortex m7
5:00
based mcu go ahead and generate the code
5:04
as i mentioned i am using the f750
5:07
discovery board and as st recommends we
5:10
must enable the instruction and data
5:12
cache for better processing
5:15
also this board has less flash memory
5:18
and it won't be able to store all the
5:20
variables in the flash
5:22
that is why i am going to use the
5:24
external flash memory and for this
5:26
purpose i must use the mpu
5:30
set the mpu to background region
5:32
privileged access only plus mpu will be
5:35
disabled during heart fault
5:38
now enable the mpu region
5:41
the base address will be the address of
5:43
the external flash that is the qspi
5:46
which is at nine million hexa
5:49
the size will be 512 megabytes
5:53
and we will disable all the access in
6:00
as mentioned here in the memory
6:02
description the qspi is in the block 4
6:05
which is 512 megabytes
6:09
this is why i blocked access to 512
6:12
megabytes of memory so as to prevent the
6:14
speculative access to this region
6:17
if you don't understand this part watch
6:20
the mpu configuration series in the
6:25
the link is in the description
6:28
the region 2 will start again at the 9
6:30
million hexa and the size will be 16
6:35
this is the actual size of the q s p i
6:38
memory available on the board
6:41
here we will permit the access and we
6:43
will set the region to cacheable and
6:47
this was actually explained in my video
6:49
about the memory configuration in cortex
6:54
we are trying to set this region as the
6:56
normal memory region with the right back
7:00
this is as according to the s ts
7:03
recommendation for the q s p i memory
7:07
we will create one more memory region at
7:10
9 million hexa but this time we will
7:12
enable the instruction execution from
7:24
this is it for the mpu configuration for
7:29
save to generate the code
7:37
you can see there is the default task
7:41
and inside the default task the lwip
7:49
let's build the code once to check for
8:02
all right we have 4 errors let's solve
8:06
the first one is about the multiple
8:10
it is defined in the middleware third
8:13
party lwip system os sysarch file
8:19
let's open this file first
8:28
this must be where the redefinition is
8:32
let's comment out this line and rebuild
8:37
we still have some errors but the error
8:39
regarding redefinition is gone
8:42
now the issue is related to the flash
8:44
memory being overflowed
8:47
for this reason we have already set up
8:49
the mpu so that we can use the external
8:52
flash memory to store the data
8:55
let's go to the flash script file to do
8:59
we have to change the origin of the
9:01
flash to the q s p i memory
9:09
the address is 9 million hexa and the
9:25
save the file and generate the code
9:28
and all the errors are gone now
9:31
we have modified the flash script but
9:35
we still need to make some changes in
9:46
go to system init function and we will
9:51
first we will reset the configuration
9:53
register and then we must relocate the
9:55
vector table to the new flash base
9:58
this is all the setup needed for now
10:01
we will do the ping test first and for
10:04
that we don't need any functions
10:06
let's build the code and debug it
10:10
since i am using external flash i need
10:12
to use the external loader in the
10:16
so here we will create a new debug
10:21
go to debugger tab check external loader
10:34
click apply to save the configuration
10:44
download verified successfully let's
10:46
reset the controller
10:48
let's put a break point in the error
10:50
handler to make sure we don't hit it
11:10
let's ping to the board
11:16
the ping test is successful and before
11:19
we go ahead i want to show you the
11:21
configuration for the ethernet
11:23
this time i have connected the
11:25
controller directly with the computer
11:27
without using any router
11:29
this is why i want to show the
11:31
configuration for the ethernet in the
11:34
here i have changed the ip assignment to
11:39
and you can see the rest of the
11:42
i will upload these images along with
11:44
the project so you can access them later
11:51
all right the ping test was successful
11:54
and now we will go ahead with the udp
12:01
here i have created the library files
12:06
let's include them in the project folder
12:22
here is the udp server source file
12:27
here is the netconstructure to handle
12:29
the connection parameter and the netbuff
12:32
structure to handle the message related
12:36
the address and port will store the same
12:40
first of all the udp server in it will
12:44
in this function we will create a new
12:48
the name is udp thread and the entry
12:53
the argument is null
12:55
the stack size will be default 1
12:59
the priority will be normal
13:01
once the udp thread is called this
13:04
function will be executed
13:07
here we will create a new netcon
13:10
netcon udp will be used to create the
13:15
if the connection is successfully
13:17
created we will bind it to any available
13:22
and the port will be 7.
13:24
this will be the port for the server
13:27
if we don't have any error we will
13:29
receive the data from this connection
13:33
this function will wait for some data to
13:35
be received from the client
13:40
if the receive is successful we will
13:42
first get the address and port of the
13:48
then we will copy the payload into the
13:54
you can make use of this message but
13:56
here i am going to modify this message
13:58
and store it in the s message
14:11
next we will allocate the ram for the
14:15
actually while using netcon the netbuff
14:17
is used to store all the information
14:22
and the p-buff is just a part of this
14:24
net buff along with other things like
14:34
this t-x buffer is the pointer to the
14:36
p-buff structure we created in the
14:43
p buff take is used to copy the message
14:50
next we will refer the p buff in the net
14:52
buff to rp buff so that we can send the
14:55
net buff to the client with updated
15:03
now connect to the address and port of
15:05
the client which we stored earlier
15:12
then send the buffer to the respective
15:21
finally we will clear everything
15:26
if there was any error during the
15:28
binding we will delete the connection
15:39
if you remember from the udp server raw
15:42
video the steps we performed were pretty
15:46
creating a new udp connection binding to
15:49
the port and then receiving the data
15:54
and once the data is received we modify
15:57
the message allocate the memory for the
15:59
p-buff copy the message into the p-buff
16:02
connect to the destination address and
16:04
port and send the buffer
16:09
that's enough explaining now we will
16:23
include the udp server header file
16:30
in the default task after initializing
16:35
we will initialize the udp server
16:42
this is it let's build the code and
16:55
i am going to use the hercules as the
17:10
enter the server address and port
17:13
local port is the port of the client
17:17
let's send hello world
17:19
there is a response from the server
17:26
this is exactly what we programmed in
17:38
you can see the server is responding
17:40
well to every message sent by the client
17:44
things are working well and you saw the
17:46
udp server responding
17:49
this is it for the udp server using the
17:55
we saw how to configure the rmii
17:57
connection type and also no memory
18:00
configuration was required for the
18:03
the next video will be about udp client
18:06
and i am going to use the h745mcu
18:10
which have the mii connection type and
18:12
also need the ethernet memory
18:16
you can leave comments in case of any
18:19
the link to download the code is in the
18:24
keep watching and have a nice day ahead