0:10
hello and welcome to controller Tech
0:13
this is the 10th video in the ethernet
0:16
series and today we will see how to use
0:18
the SDM 32 as the HTTP server in today's
0:23
video I will create a very simple web
0:25
server which will use the get method for
0:27
the request and then display the web
0:31
accordingly later we will cover a more
0:33
detailed server using the Ajax but that
0:36
will be in the upcoming
0:38
videos let's start the cube ID and
0:43
project I am using the usual SDM 32
0:49
board give some name to the project and
1:08
pinouts all right let's start with the
1:12
setup I am using the external high-speed
1:15
Crystal for the clock the board has 25
1:18
MHz Crystal and the system is running at
1:25
MHz all right now go to the ethernet and
1:29
enable the type of connection you have
1:32
as I mentioned earlier this board have
1:34
our MI connection type let's start with
1:38
the parameter configuration
1:40
first since we are using the onboard
1:43
connector the phy address must be zero
1:47
also change the RX mode to the interrupt
1:51
mode when you do this you can see the
1:54
ethernet interrupt is
1:56
enabled finally do check the pinouts and
1:59
match it with the schematics of your
2:02
board also make sure that the speed is
2:15
maximum next go to the free
2:18
R I am enabling the version two of the
2:22
cmsis no changes are needed to be made
2:27
R just leave every thing to
2:31
default you can see there is a default
2:33
task created and later the lwip will use
2:37
this task so leave this too I am
2:40
enabling the new library re-entrant as
2:43
it gives the error while generating the
2:52
lwip here first of all we will disable
2:55
the DHCP and manually enter the IP
3:08
Etc you can see here the rtos usage is
3:12
enabled by default as we have enabled it
3:15
already anyway leave everything else to
3:18
default in the general
3:20
settings in the key options the only
3:23
change we need to make is increase the
3:27
size I am setting it to 10
3:30
kilobytes so far we did the usual setup
3:34
whatever we did in the previous three
3:37
videos for the HTTP server we need to
3:43
httpd if all these options don't show up
3:46
you need to check this box let's leave
3:50
everything to default here for
3:53
now all right if you are not using
3:56
cortex M7 based MCU go ahead and
3:59
generate the code as I mentioned I am
4:04
F750 Discovery board and as St
4:07
recommends we must enable the
4:09
instruction and data cache for better
4:11
processing also this board has less
4:14
flash memory and it won't be able to
4:16
store all the variables in the
4:19
flash that is why I am going to use the
4:22
external flash memory and for this
4:24
purpose I must use the
4:26
mpu set the mpu to background region PR
4:29
privileged access only plus mpu will be
4:34
fault now enable the mpu
4:38
region The Base address will be the
4:40
address of the external flash that is
4:42
the qspi which is at 9 million
4:45
hexa the size will be 512
4:50
mbes and we will disable all the access
4:56
region as mentioned here in the memory
4:59
description the qspi is in the block 4
5:05
mbes this is why I blocked access to 512
5:09
mbes of memory so as to prevent the
5:12
speculative access to this region if you
5:15
don't understand this part watch the mpu
5:18
configuration Series in the cortex M7
5:21
playlist the link is in the
5:24
description the Region 2 will start
5:27
again at the 9 million hexa and the size
5:32
MB this is the actual size of the qspi
5:35
memory available on the
5:37
board here we will permit the access and
5:41
we will set the region to cachable and
5:44
buffable this was actually explained in
5:46
my video about the memory configuration
5:51
MCU we are trying to set this region as
5:54
the normal memory region with the right
5:57
attribute this is as according to to the
5:59
st's recommendation for the qspi memory
6:04
configuration we will create one more
6:06
memory region at 9 million hexa but this
6:09
time we will enable the instruction
6:20
region this is it for the mpu
6:23
configuration for the external
6:25
flash click save to generate the code
6:31
before we go any forward let's build the
6:35
once we will see a lot of errors and we
6:38
will resolve them one by one here we
6:41
have the error about the fs data custom.
6:44
C file the file is not present in the
6:48
directory doubleclick the error to see
6:52
occurred here we will go to the
6:54
definition of the custom FS data and set
6:57
it to zero so now we are not using the
7:02
file apparently there is no way to
7:05
disable it in the cube setting so we
7:07
have to manually do it here now we have
7:11
another error about FS data file and it
7:13
is also not present in the
7:16
directory you can go to middleware Third
7:24
HTTP here you can see the fs data header
7:27
file is present but there is no source
7:29
SCE file this file is actually generated
7:33
based on your resources and we need to
7:35
use the make FS data application to do
7:38
that here we have the fs folder which
7:42
consists of all the resources we have
7:45
project by default there are two HTML
7:48
files index and 404 and I am leaving
7:52
them as it is this is how our index file
7:56
will look like and this is how the four
8:01
look you can create any HTML file and
8:05
place it in this folder and then
8:07
generate the fs data file as I mentioned
8:11
I am keeping the files as it is and we
8:13
will copy all these files into our HTTP
8:16
directory now doubleclick the fs data
8:19
application and it will generate the fs
8:22
data file for you I will leave the link
8:25
to this folder in the description below
8:31
let's go back to our project and build
8:43
again we have seven errors now and most
8:46
of them are about the multiple
8:51
definitions now go to the fs data file
8:54
we just created and exclude it from the
9:08
again all the errors regarding the
9:11
multiple definitions are gone now this
9:14
error about the flash overflow is
9:16
specific to this board as I mentioned
9:18
that the flash has a low space and this
9:20
is why I configured the mpu for the
9:24
flash now I will set the flash to the
9:26
external location and this is done in
9:29
the flash script file if your board has
9:32
enough flash memory you don't need to do
9:35
this all right there is one last error
9:38
and it is about the multiple definition
9:41
erno let's go to this location
9:44
middleware third party
9:46
lwip system OS CIS arch. C here just
9:52
comment out the definition of
9:54
nno all right all the errors are gone
9:57
now now since I have used the external
10:01
flash I need to relocate the vector
10:04
table again this is specific to some
10:06
boards and if you did not set the
10:09
external flash you don't need to do
10:25
this this is our main
10:27
file here the default task is created
10:31
and once this task will run it will
10:35
lwi all right everything is set now and
10:39
it's time to Ping since I am using the
10:42
external flash I need to use the
10:44
external loader in the debugger
11:13
now now we will ping to our IP
11:19
address you can see the Ping is
11:22
successful so everything seems okay so
11:25
far and we can proceed ahead with it
11:28
let's include the Library files now here
11:31
I have the HTTP server source and header
11:35
files put the source file in the source
11:38
directory and header file in the include
11:41
directory the HTTP server header file
11:44
only has one function HTTP server in it
11:49
let's see its implementation in the
11:51
source file the HTTP server in it
11:54
creates a new HTTP thread whose entry
11:57
function is http thread itself the stack
12:00
size is default 1 kilobyte and the
12:08
normal inside the HTTP thread we will
12:14
connection the argument is netcon TCP
12:17
and it will create a new TCP connection
12:20
if the connection is created
12:22
successfully we will bind it to the
12:24
local IP address this is the same as the
12:27
one we set in the cube MX and this will
12:30
be the address of the server the port of
12:33
the server is set to 80 once The Binding
12:36
is successful we will put the server in
12:39
the listen mode now the connection will
12:41
listen for any client which is trying to
12:44
connect to this server once the client
12:47
connects to This Server we will accept
12:49
the connection the netcon accept takes
12:52
two arguments the first argument is the
12:56
TCP connection which is listening to the
13:00
and the second argument is the pointer
13:02
where the new connection is going to
13:04
store our TCP listening connection is
13:07
Con and we will store the new connection
13:09
in the new con both of them are defined
13:13
in the beginning of the function once
13:15
the client connection is accepted by the
13:17
server we will call the HTTP server to
13:20
handle the requests made by this
13:26
client in the HTTP server we will
13:29
receive the requests made by the client
13:32
netcon receive takes two
13:35
arguments the first is the connection
13:37
and the second is the net buff structure
13:40
where the request data is going to store
13:43
next we will check what request was made
13:45
by the client and to do that we will
13:48
first get the data pointer and its
13:50
length from the net buff
13:52
structure net buff data takes three
13:55
arguments here the first is the net buff
13:58
structure Ure where we want to get the
14:00
data from next is the pointer where you
14:04
want to store the data pointer to and at
14:07
last is the pointer where the length
14:10
stored so now the data pointer is stored
14:13
in buff and the length is stored in
14:16
buffen now we will compare the data in
14:19
the data pointer to whatever requests
14:22
serve for example here I am checking if
14:25
the client has requested the index.html
14:30
if it did then we will open the file
14:33
index.html we will store the information
14:36
about this file in the file
14:38
structure now we will write this data to
14:42
connection netcon write takes four
14:45
arguments the connection where the data
14:48
is to be written the data pointer length
14:52
of the data pointer and the last one is
14:56
flag this API flag basically decid
14:59
decides how the data will be written for
15:02
example the netcon copy will be used if
15:05
you want to copy the data into the
15:07
memory belonging to the
15:11
stack here we are using no copy and it
15:15
means the data will be simply written
15:19
conditions after writing the data we
15:21
will close the file so we served the
15:24
requests made by the client to get the
15:30
if you remember I only have one file in
15:32
the fs folder and hence if any other
15:34
request comes from the client my server
15:37
will show the 404 error page you can see
15:43
condition once the client request is
15:45
served we will close the connection and
15:48
delete the net buff finally we will
15:51
delete the connection itself so that a
15:53
new client can make another request this
15:56
while loop will keep running and the the
15:59
server will keep looking for the
16:01
clients all right let's write the main
16:08
now first of all we will include the
16:14
file now in the default task after the
16:17
lwip is initialized we will initialize
16:20
the HTTP server also this will
16:24
eventually create a new HTTP thread and
16:27
everything will begin let's build and
16:45
page you can see the page is being
16:52
displayed if we request the 404 page the
16:55
server displays it perfectly as I me
16:58
mentioned the server currently has two
17:00
pages only and if we request anything
17:02
other than the index page the server
17:05
will show the 404 error the HTTP basic
17:09
server is working all right in the
17:12
future videos we will cover the Ajax
17:15
with the web server for the asynchronous
17:18
loading this is it for today's video you
17:22
can download the code from the link in
17:25
description keep watching and have a