0:09
hello and welcome to controllers tech
0:13
in my previous video i covered how to
0:15
create udp server with stm32 ethernet
0:19
and as i mentioned in that video today
0:21
we will see the udp client
0:24
in the previous video i used the f7
0:27
board which doesn't need any memory
0:29
configuration and we went with the
0:33
in this video i will use the h7 board
0:36
which is going to need the memory
0:38
configuration and we will try to keep
0:40
things as close to default as possible
0:43
i am saying this again you need to watch
0:45
the first two videos about the hardware
0:48
connection for ethernet module
0:51
let's start the video and create a new
0:56
as i mentioned i am using h7 board
1:01
give some name to the project and click
1:10
let's enable the ethernet connection
1:22
the pins looks too messy let me clear
1:28
now we will enable the mii or rmii
1:32
whatever type your port have
1:35
make sure the pins are configured
1:38
schematics we will check the rest of the
1:41
settings in a while let's configure the
1:45
i am selecting external high speed
1:47
crystal for the clock
1:50
configure the clocks as per the crystal
1:52
available on your board
2:00
all right now let's go back to ethernet
2:03
and configure the rest of the setup
2:06
enable the global interrupt
2:11
in the parameter setting we do have the
2:13
option to configure the memory
2:16
i am leaving everything to default
2:19
take a good look at these addresses as
2:21
we are going to use them in the flash
2:27
now let's enable the lightweight ip
2:34
it's not letting me enable it because i
2:36
haven't enabled the cache yet
2:39
so enable the data and instruction cache
2:43
now i got the option to enable the lwip
2:47
i am going to do the same configuration
2:52
the memory size will be 10 kilobytes
2:59
leave everything to default here
3:02
and now we will disable the dhcp and
3:05
instead provide a static ip to our
3:14
that's it now choose the available
3:21
the mpu configuration must be done when
3:23
we have configured the memory in the
3:27
enable the background region privileged
3:31
enable the mpu region
3:34
the base address will be the start of
3:36
the dma descriptor addresses
3:42
the size will be 32 kilobytes
3:46
text should be 1 and this way we set the
3:48
region as non cachable memory region
3:59
before we go any further let's enable
4:03
we will set this periodic interrupt
4:05
which when triggered will send the data
4:09
i am choosing timer 1 for this purpose
4:13
choose the source as internal clock
4:20
if we check the data sheet we can see
4:23
that in this particular mcu the timer 1
4:25
is connected to the a-p-b-2 clock
4:34
right now the a-p-b-2 timer clock is
4:37
running at 240 megahertz
4:40
the plan is to use a periodic callback
4:43
every one second so that the client can
4:45
send the data to the server
4:48
to bring this 240 megahertz clock to 1
4:51
hertz we will first use the prescaler of
4:54
24 000. this will bring the clock down
4:59
an auto reload value of 10 000 will
5:02
further divide this clock and bring it
5:06
make sure the update interrupt is
5:08
enabled this is it for the configuration
5:11
now click save to generate the project
5:17
i am going to use the same code that i
5:20
did in the previous video
5:22
this way we will be able to test the
5:33
let's build and test this part first
5:36
we also need to add the memory details
5:41
this is necessary in this video as we
5:43
did the memory configuration in the cube
5:47
everything so far has already been
5:49
covered in the hardware connection video
5:51
so if you didn't understood anything
5:53
watch the first video in the ethernet
5:57
this is it let's try to ping to the
6:02
this is the ip address that has been
6:05
assigned to the module and here you can
6:07
see the ping test is a success
6:10
all right let's move on and now we will
6:20
copy the udp client source and header
6:23
files into the project folder
6:33
here are the steps to configure the udp
6:37
you can check out this source website
6:41
here i have defined the timer you can
6:44
change it as per your setup
6:47
here is the period elapsed callback
6:49
function and it will run every 1 second
6:53
inside the callback we will send the
6:57
now let's see the steps to configure the
7:02
first of all we will create the udp
7:09
we can do this by calling udp new
7:12
then we will bind the client to the
7:18
the local ip is the ip of the module and
7:21
port is just some random port
7:32
and also connect the client to the
7:34
server using the server ip and port
7:40
you can look for the destination ip by
7:42
typing ipconfig in your windows machine
7:51
this port 7 we will assign to the server
7:55
when we will create the server
8:00
now the step 2 is to send the data to
8:04
i am using this function udp client send
8:07
to send the data to the server
8:10
then we will wait for the response from
8:14
to do this we will set a receive
8:16
callback which will be called when the
8:18
server will send some data to this
8:21
udp receive takes the udp control block
8:24
as the parameter and the next parameter
8:27
is the udp receive function which is the
8:43
let's see the function to send the data
8:49
here first we are creating a packet
8:51
buffer which we will send later
8:54
this buffer will contain the information
8:56
about the data that we are going to send
9:07
next we will copy this string into the
9:11
this counter value will keep changing
9:14
then we will allocate the memory for the
9:24
next the p-buff take will copy the data
9:26
into the packet buffer
9:31
finally udp send will send the data to
9:35
and in the end we will free the memory
9:37
for the packet buffer
9:41
when the client receives some data from
9:43
the server this callback will be called
9:47
here we will copy the data from the
9:49
server into this buffer
9:51
this is just in case if you want to
9:55
and here we will increment this counter
9:59
this counter variable will increment
10:01
every time the server sends some data to
10:05
and the data is being sent by the timer
10:07
callback every one second
10:14
now in the main function all we need to
10:17
do is call the udp client connect
10:20
also don't forget to start the timer
10:32
let's build and flash this
10:37
i am using hercules to create a udp
10:39
server so that the client can connect to
10:45
i am opening the port 7 which will be
10:59
here you can see the same message is
11:01
being continuously sent by the client
11:03
until the server sends some data to the
11:12
as soon as the server sends the data the
11:14
counter value is increased
11:17
it will keep continuously sending the
11:19
same data again until the server sends
11:26
the message is being sent every one
11:28
second just as we programmed it in the
11:32
when the client receives the data from
11:34
the server the receive callback is
11:36
called where the value of the counter
11:38
variable gets updated
11:41
so the udp client is sending the data to
11:43
the server the server sends some
11:46
response to the client and this process
11:48
keep going on forever
11:50
this is it for this video
11:53
i don't have any better way of showing
11:54
the working right now
11:57
maybe in the near future i will make
11:59
some application oriented video on this
12:02
but for now i just wanted to show the
12:05
working of udp client and the server
12:08
you can download the code from the link
12:12
leave comments in case of any doubt
12:15
keep watching be safe and have a nice