0:09
hello and welcome to controllers tech
0:13
this is the eighth video in the stm 32
0:16
ethernet series and today we will see
0:18
how to use sdm 32 as a udp client using
0:24
here we will periodically send the data
0:28
which is a udp client to the computer
0:32
where we will create a udp server
0:35
along with that whenever the server will
0:38
send some data to the client the client
0:40
will also response to the server by
0:42
sending some reply related to the data
0:46
we have already covered the udp server
0:48
using netcon in the previous video and
0:51
most of the configuration will be
0:52
similar to that video
0:55
so let's start the cube ide and create a
1:03
stm32f750 discovery board
1:06
give some name to the project and click
1:15
let me clear the pin outs first
1:19
if you have watched the previous video
1:21
you can skip to 11th minute
1:24
we will start with the clock
1:27
i have 25 megahertz crystal on board and
1:31
i am running it as 200 megahertz clock
1:41
all right now go to the ethernet and
1:44
enable the type of connection you have
1:47
as i mentioned earlier this board have
1:49
our m-i-i connection type
1:52
let's start with the parameter
1:56
since we are using the on-board
1:58
connector the phy address must be zero
2:02
also change the rx mode to the interrupt
2:07
when you do this you can see the
2:09
ethernet interrupt is enabled
2:12
finally do check the pin outs and match
2:14
it with the schematics of your board
2:18
also make sure that the speed is set to
2:30
next go to the free r-t-o-s
2:34
i am enabling the version 2 of the cm
2:38
no changes are needed to be made in the
2:43
just leave everything to default
2:46
you can see there is a default task
2:48
created and later the lwip will use this
2:52
task so leave this too
2:55
i am enabling the new library reentrant
2:57
as it gives the error while generating
3:08
here first of all we will disable the
3:10
dhcp and manually enter the ip address
3:24
you can see here the rtos usage is
3:26
enabled by default as we have enabled it
3:31
anyway leave everything else to default
3:33
in the general settings
3:36
in the key options the only change we
3:38
need to make is increase the heap memory
3:43
i am setting it to 10 kilobytes
3:46
this is it for the lwip configuration
3:49
leave everything else to default for now
3:54
last but not least since we are using
3:57
the rtos we have to use the time base as
4:00
anything other than cystic
4:02
i am using the timer 6 for this purpose
4:06
all right if you are not using cortex m7
4:09
based mcu go ahead and generate the code
4:14
i am using the f750 discovery board and
4:18
as st recommends we must enable the
4:20
instruction and data cache for better
4:24
also this board has less flash memory
4:27
and it won't be able to store all the
4:29
variables in the flash
4:31
that is why i am going to use the
4:33
external flash memory and for this
4:35
purpose i must use the mpu
4:39
set the mpu to background region
4:41
privileged access only plus mpu will be
4:44
disabled during heart fault
4:47
now enable the mpu region
4:50
the base address will be the address of
4:52
the external flash that is the
4:55
p i which is at 9 million hexa
4:58
the size will be 512 megabytes
5:02
and we will disable all the access in
5:09
as mentioned here in the memory
5:11
description the q s p i is in the block
5:14
4 which is 512 megabytes
5:18
this is why i blocked access to 512
5:21
megabytes of memory so as to prevent the
5:23
speculative access to this region
5:26
if you don't understand this part watch
5:29
the mpu configuration series in the
5:34
the link is in the description
5:37
the region 2 will start again the 9
5:39
million hexa and the size will be 16
5:44
this is the actual size of the q s p i
5:47
memory available on the board
5:50
here we will permit the access and we
5:52
will set the region to cacheable and
5:56
this was actually explained in my video
5:58
about the memory configuration in cortex
6:03
we are trying to set this region as the
6:05
normal memory region with the right back
6:10
this is as according to the st's
6:12
recommendation for the q s p i memory
6:16
we will create one more memory region at
6:19
9 million hexa but this time we will
6:21
enable the instruction execution from
6:33
this is it for the mpu configuration for
6:38
click save to generate the code
6:46
you can see there is the default task
6:50
and inside the default task the lwip
6:58
let's build the code once to check for
7:11
all right we have 4 errors let's solve
7:15
the first one is about the multiple
7:19
it is defined in the middleware third
7:22
party lwip system os sysarch file
7:28
let's open this file first
7:38
this must be where the redefinition is
7:41
let's comment out this line and rebuild
7:46
we still have some errors but the error
7:48
regarding redefinition is gone
7:51
now the issue is related to the flash
7:53
memory being overflowed
7:56
for this reason we have already set up
7:58
the mpu so that we can use the external
8:01
flash memory to store the data
8:04
let's go to the flash script file to do
8:08
we have to change the origin of the
8:10
flash to the q-s-p-i memory
8:18
the address is 9 million hexa and the
8:34
save the file and generate the code
8:38
and all the errors are gone now
8:40
we have modified the flash script but
8:44
we still need to make some changes in
8:55
go to system init function and we will
9:00
first we will reset the configuration
9:02
register and then we must relocate the
9:04
vector table to the new flash base this
9:08
is all the setup needed for now
9:10
we will do the ping test first and for
9:13
that we don't need any functions
9:16
let's build the code and debug it
9:19
since i am using external flash i need
9:21
to use the external loader in the
9:25
so here we will create a new debug
9:31
go to debugger tab check external loader
9:43
click apply to save the configuration
9:53
download verified successfully let's
9:57
let's put a break point in the error
9:59
handler to make sure we don't hit it
10:19
let's ping to the board
10:25
the ping test is successful and before
10:28
we go ahead i want to show you the
10:30
configuration for the ethernet
10:32
this time i have connected the
10:34
controller directly with the computer
10:36
without using any router
10:38
this is why i want to show the
10:40
configuration for the ethernet in the
10:44
here i have changed the i p assignment
10:48
and you can see the rest of the
10:51
i will upload these images along with
10:53
the project so you can access them later
11:04
now as the ping is successful let's
11:07
include the udp client library files
11:14
let's see the udp client source file
11:24
we have the udp client init function
11:27
which creates two new threads
11:30
the udp send thread will be used to
11:33
periodically send the data to the server
11:36
and the udp init thread will be used to
11:39
initialize the udp client
11:42
the stack size in both will be default 1
11:45
kilobytes and the priority is normal
11:49
let's see udp in it thread now
11:52
first of all we will create a new netcon
11:57
the netcon udp argument is used to
12:00
initialize the udp connection
12:03
if the connection is successful we will
12:05
bind the connection to the local ip
12:07
address and the port 7.
12:10
the i p address will be the one we set
12:12
up in the cube mx and the port will be
12:14
the port of the client
12:17
next we will convert the destination i p
12:19
address to the integral format
12:22
this here is the i p address of the
12:24
computer which you can find by typing i
12:27
p config in the command window
12:30
make sure you use the i p address of the
12:36
next we will connect to the destination
12:41
this 8 here is the port of the server
12:44
after the connection is successful we
12:46
will go into the while loop
12:49
here we will wait for the server to send
12:53
the data sent by the server will be
12:55
stored in the r x buff
12:58
r x buff is actually a pointer to the
13:00
net buff structure that we have defined
13:03
the net buff structure contains the p
13:06
buff which contains the actual message
13:11
and other things like the address and
13:15
here we get the message from the net
13:17
buff modify that message and store it in
13:22
then we call the udp send function which
13:25
will send this array to the server
13:28
finally we will delete the net buff so
13:31
that it can receive the new data the
13:34
next function is the udp send function
13:38
it takes the argument as the pointer to
13:40
the data that you want to send to the
13:44
here first of all we will allocate a new
13:48
then the net buff referrer can be used
13:50
to copy the data into the payload of the
13:57
once the data is copied we will call the
13:59
netpuf send to send the data to the
14:03
here the connection parameter contains
14:05
the details like i p address and port of
14:10
and the buff parameter contains the data
14:12
its length and the ip and port of the
14:16
after sending the data we will
14:18
deallocate the net buff structure
14:21
so far the client only sends the
14:23
response to the server but we want the
14:25
client to send the data periodically
14:29
and this is why we need the u d p send
14:33
here we will send the value of the index
14:35
variable every 500 milliseconds
14:39
this way the client will always send the
14:41
data to the server irrespective of
14:43
whether the server responds or not
14:47
let's write the main function now
14:54
here include the udp client header file
15:04
in the default task after the lwip has
15:08
initialized call the initialization of
15:13
this will create the two new threads and
15:15
everything will work from there
15:18
that's all the things we need to do in
15:22
let's build and debug the code
15:33
i am going to use the hercules as the
15:37
this is the address of the client
15:40
7 is the port of the client
15:44
and 8 is the port of the server
15:47
the address of the server is same as the
15:49
i p address of the computer
15:54
let's run the code now
15:56
you can see the client is sending the
15:58
value of the index variable
16:04
and when the server sends some data the
16:07
client modifies it and send it back
16:10
in the meantime it continues sending the
16:13
index value every 500 milliseconds
16:22
we got the udp server and udp clients to
16:25
work with the netcon
16:27
next i will do the tcp server and tcp
16:32
this is it for the video
16:35
you can download the code from the link
16:39
leave comments in case of any doubt
16:42
keep watching and have a nice day ahead