0:09
hello and welcome to controllers tech
0:12
Previously we explored a comprehensive
0:15
tutorial series on Ethernet integration
0:17
with SDM32 microcontrollers
0:21
This series covered various aspects
0:23
including the utilization of raw TCP and
0:26
UDP protocols their implementation using
0:29
the netkin API and the setup of an HTTP
0:32
server All these functionalities were
0:35
demonstrated using the lightweight IP
0:37
stack which is integrated into the SDM32
0:43
Many users encountered difficulties in
0:45
implementing Ethernet functionality
0:47
primarily due to complexities associated
0:50
with LUIP Challenges included managing
0:53
DMA descriptors buffers and memory
0:57
protection Today I will present a
0:59
simplified approach for integrating
1:01
Ethernet functionality on SDM32
1:04
microcontrollers the Mongoose library
1:08
Mongoose is a network library for
1:11
CC++ It provides event-driven
1:14
non-blocking APIs for TCP UDP HTTP
1:19
websocket MQTT and other
1:22
protocols It is designed for connecting
1:25
devices and bringing them
1:27
online On the market since 2004 used by
1:31
a vast number of open-source and
1:33
commercial products it even runs on the
1:37
Station Mongoose makes embedded network
1:40
programming fast robust and easy The
1:44
Mongoose wizard simplifies the creation
1:47
of professional interfaces without
1:49
requiring design or front-end expertise
1:53
It supports user authentication with
1:55
multiple access levels which can be
1:57
enabled effortlessly via a single
2:00
checkbox Additionally dashboards are
2:03
kept up to date with a built-in device
2:05
connection indicator on the
2:07
toolbar UI controls such as drop-downs
2:10
toggles and inputs can be easily mapped
2:13
to see structures by adjusting getter
2:18
Conditional display functionality allows
2:20
data exceeding predefined thresholds to
2:23
be highlighted using alternative
2:25
styles Moreover Mongus provides seamless
2:29
firmware update support for
2:31
microcontrollers like
2:34
ESP32 and others requiring no additional
2:38
configuration We will explore the
2:40
Mongoose wizard in detail in the
2:44
Today we will demonstrate how
2:46
straightforward it is to integrate the
2:48
library with SDM32 and enable Ethernet
2:52
functionality The tutorial section of
2:55
the documentation outlines the steps
2:59
integration Navigate to the action plan
3:03
guidance As mentioned the first step
3:06
involves creating a minimal skeleton
3:09
firmware for the hardware board
3:12
Next you need to add the Mongus library
3:14
and configure the TCP IP stack We will
3:18
now review these steps in detail The
3:22
initial step is to develop a skeleton
3:25
firmware The documentation provides
3:27
instructions for creating firmware
3:29
across various devices Since I am using
3:33
SDM32 with cube ID we will focus on this
3:37
specific setup The documentation
3:40
includes pin configurations for several
3:43
boards However I am using the H745
3:47
discovery board whose details are not
3:50
listed Instead we will refer to the
3:53
schematic of this board to identify the
3:55
required pins The following steps
3:58
outline the process for creating a
4:00
skeleton firmware using Cube ID
4:03
Developing a skeleton firmware involves
4:06
configuring Ethernet pins setting up
4:08
UART and optionally configuring LED
4:11
pins To begin open Cube IDE and create a
4:16
new project For this demonstration I am
4:23
Board Assign a name to your project and
4:26
click finish The schematic of the
4:29
H745 discovery board provides helpful
4:33
details This board includes an
4:35
integrated ST link allowing the use of a
4:38
virtual comp port for UART
4:41
communication The relevant VCPX and RX
4:45
pins are PV10 and PV11 For a detailed
4:49
explanation of UART setup refer to the
4:51
UART video linked in the top right
4:53
corner If your board lacks a virtual COM
4:57
port you can use a USB to UR converter
5:00
as an alternative solution The onboard
5:03
LED is connected to pin PJ2 which will
5:06
later be used in this tutorial to
5:08
control the LED through a web server Now
5:14
IDE First clear the pin out
5:16
configuration and begin by setting up
5:20
Select an external crystal oscillator as
5:23
the clock source The board includes an 8
5:26
MHz crystal and we aim to run the system
5:32
MGHertz If you are using this specific
5:35
board ensure the power supply source is
5:38
set to SMPS to avoid damaging the
5:41
hardware Next configure
5:43
UART The VCPTX and RX pins are connected
5:47
to PB10 and PB11 So these will be set up
5:52
pins These pins correspond to usart 3
5:57
enabled Set the mode to asynchronous and
6:02
configuration The UART will operate with
6:06
115200 using eight data bits one stop
6:09
bit and no parity Configure pin PJ2 as a
6:14
PO output as it is connected to the
6:18
This pin will be used later for
6:20
controlling the LED Next enable the
6:23
Ethernet peripheral The board may use
6:26
either an MII or RMI connection type
6:30
Refer to the schematic to determine the
6:32
connection type for your specific
6:35
board For example the
6:38
H745 board utilizes an MII connection
6:43
It is important to verify the pins
6:45
generated by CubeMX against those
6:47
specified in the schematic as CubeMX
6:50
occasionally assigns one or two
6:53
pins In this case Cube MX correctly
6:56
generated all pins except PH6 Ethernet
6:59
RX2 which should be PB0 according to the
7:05
You can also consult the Mongoose guide
7:07
for Ethernet pin configurations for your
7:09
board but it is recommended to
7:11
cross-check them with the schematic for
7:14
accuracy Leave the parameter
7:18
unchanged Next open the NVIC tab and
7:22
enable the Ethernet global interrupt
7:25
While enabling the interrupt ensure that
7:28
the interrupt handler is not generated
7:30
by CubeMX as it is already included in
7:34
files Uncheck the box to prevent handler
7:38
generation We have completed all the
7:40
steps outlined in the guide However
7:44
there are a few additional
7:47
required Navigate to the security tab
7:50
and enable the random number generator
7:54
This feature will allow Mongoose to
7:56
generate a random MAC address for
7:59
purposes while the project can still be
8:02
built without it using the hardware RNGs
8:06
available Go to the PO configuration and
8:10
associate the pin PJ2 with the Cortex
8:13
M7 This is necessary so that we can
8:16
control the pin using M7 core Once these
8:20
settings are configured in Cubmx click
8:25
project Next open the Cortex M7 main
8:29
file Comment out the code that waits for
8:32
the second core to run as we are not
8:34
utilizing the second core at this
8:37
stage Continuing with the guide note
8:40
that we have already enabled interrupts
8:42
in CubeMX so no further changes are
8:45
needed there Copy the relevant code and
8:48
place it within the while loop To enable
8:52
print f functionality define the right
8:54
function above the main
8:56
function This mgis function will monitor
8:59
and track the number of milliseconds
9:01
elapsed since boot Finally build and run
9:06
the project to observe its output on the
9:09
console You should see uptime displayed
9:13
Let's proceed to build and flash the
9:16
project onto the board I am using the
9:19
WCH serial monitor to view UART logs The
9:23
USB modem corresponds to the port for
9:26
the SDM32 development board The UART
9:30
configuration remains consistent with
9:34
CubeMX Let's connect the serial monitor
9:38
On the console you can observe the
9:40
uptime being displayed updating every
9:45
milliseconds This confirms that
9:47
everything is functioning correctly so
9:49
far The skeleton firmware is ready and
9:52
we can now move on to step two If you
9:56
are using Kyle IDE refer to this guide
10:01
instructions Next we will integrate the
10:03
Mongoose library into the project
10:07
Open this GitHub library
10:09
link First open the mongus.c file and
10:14
content Then create a new source file
10:18
named mongus.c and paste the copied
10:23
it Similarly access the mongus.h file
10:27
from GitHub Copy its content and paste
10:30
it into a new header file named mongus.h
10:34
Next we need to create a configuration
10:40
mongus_config.h and insert the required
10:42
configuration details into this file
10:45
Within this configuration enable the
10:48
driver for the specific board you are
10:51
using For example since I am using the
10:54
H745 discovery board I will include the
11:01
Now that all necessary files are
11:03
prepared include the standard IO header
11:05
file as recommended by the IDE along
11:08
with the mongoose.h header file
11:11
Afterward create a function called run
11:14
mongoose Place this function above the
11:17
main function for better
11:20
organization In addition to these steps
11:23
we need to implement a function that
11:25
generates a random number for the MAC
11:28
This function will utilize the
11:30
hardware's random number
11:32
generator Once done build the
11:36
project If you encounter an error
11:38
indicating multiple definitions of mg
11:40
random it's because this function is
11:43
already defined in the mongus source
11:45
file To resolve this configure the
11:48
library to use your custom random
11:50
function by enabling custom random in
11:52
the configuration file
11:55
Rebuild the project after making this
11:58
change If successful the library will
12:01
now use your custom random
12:04
function Finally call the run mongoose
12:07
function before entering the infinite
12:10
program Note that the while loop won't
12:13
execute anymore because run mongus
12:15
contains its own infinite loop to handle
12:19
events Build and flash your project onto
12:22
the board After flashing check the logs
12:27
console You should see that a random MAC
12:29
address has been generated for your
12:32
board If no further logs appear it could
12:35
indicate that something is stuck Upon
12:38
investigation I found that this issue
12:41
was caused by an incorrect PHY address
12:44
To fix this set the PHY address to one
12:47
in the configuration file The address
12:51
typically ranges from 0 to 4 For
12:54
SDM32H and F-S series devices it is
12:57
usually set to zero by
12:59
default However if your board doesn't
13:02
work with zero try setting it to one as
13:05
I did Rebuild and flash your project
13:08
again Check the logs once more on your
13:13
If everything works correctly now but
13:15
you still don't see an IP address it may
13:18
be because your Ethernet cable is
13:20
connected directly to your computer
13:21
instead of a router The library uses
13:25
DHCP by default So connecting through a
13:28
router would assign an IP address
13:30
automatically as shown in
13:32
guides However if you're connecting
13:34
directly to a computer without a router
13:36
in between you'll need to configure a
13:39
static IP instead To define a static IP
13:43
we will configure it directly in the
13:45
mongus config.h file For this setup I am
13:49
assigning the IP address
13:54
192.168.0.10 Alongside the IP the
13:57
gateway and net mask values are also
14:00
specified With these changes the Mongus
14:03
library will use the static IP instead
14:09
Next we need to adjust the Ethernet
14:11
settings on the computer I am currently
14:15
using a Mac but I will also include
14:17
instructions for Windows in the article
14:21
description By default Ethernet is set
14:24
to use DHCP so we need to switch it to
14:28
configuration Assign an IP address to
14:31
the computer that is greater than the
14:33
gateway address defined earlier in
14:36
config.h Set the subnet mask to
14:42
255.255.255.0 and set the DNS to zero
14:45
Once the Ethernet settings are
14:47
configured to match those on
14:49
SDM32 flash the project onto the board
14:52
again You should now see the assigned
14:55
static IP address in the
14:57
logs Since a static IP is being used
15:00
there's no need to monitor logs further
15:02
The TCP IP stack is functioning
15:05
correctly To verify connectivity ping
15:09
the assigned IP address from your
15:11
computer You should see responses from
15:14
the board confirming that the TCP IP
15:18
operational Now let's proceed with
15:21
additional tasks Step three in the guide
15:24
involves creating a simple web server To
15:28
achieve this start by adding an HTTP
15:30
listener within the run mongus function
15:33
before its infinite loop Then include an
15:37
event handler above run mongus to manage
15:41
requests This handler will respond with
15:44
okay and display uptime
15:47
information Build and flash your project
15:49
onto the board again Open a browser and
15:53
navigate to your server's IP address You
15:55
should see uptime details displayed on
15:57
the web page The uptime updates every
16:01
time we refresh the page So the simple
16:04
web server is fine Next implement a
16:08
basic web UI to control an onboard LED
16:10
via this server Replace the existing
16:14
event handler with new code that manages
16:16
LED state based on HTTP
16:19
requests Ensure you specify the correct
16:22
VO pin for your LED In my case it's
16:25
connected to pin PJ2
16:28
Update your configuration file by adding
16:30
two specific lines required for this
16:34
functionality Then visit a provided link
16:36
to generate a packed file system source
16:43
UI Create a new file named packed fs.c
16:47
in your source folder and paste this
16:54
Rebuild and flash your project once more
16:58
Refresh your web server page in the
17:00
browser You should see a new UI for
17:04
LED The LED will be on by default Toggle
17:08
it via this interface to turn it off or
17:10
on as desired This implementation
17:13
demonstrates how easy it is to control
17:15
hardware components like LEDs over
17:17
Ethernet using Mongus compared to
17:20
alternatives like LUHIP We successfully
17:23
set up a TCP IP stack and created a web
17:26
server using Mongoose on
17:29
SDM32 Additionally I've discussed common
17:32
errors you might encounter and their
17:36
development Mongoose also provides a
17:38
wizard for generating complete web UIs
17:41
with multiple pages along with pre-built
17:43
projects for SDM32 Cubide tailored to
17:46
various SDM32 boards
17:50
These can be imported directly into Cube
17:52
IDE and integrated with physical sensors
17:56
devices We explore this project wizard
17:59
in detail in our next video of this
18:02
series For now you can download this
18:05
project using the link provided in the
18:08
below Feel free to leave comments if you
18:12
have questions or need
18:14
clarification Thank you for watching
18:16
Have a great day ahead