SlideShare a Scribd company logo
1
2
C/Embedded Base Camp
Connection of GL Embedded Starter Kit to Ethernet
Petro Shevchenko
July 2021
1. STM32F407x Ethernet Interface
2. STM32F407x HAL Ethernet Driver
3. Lightweight TCP/IP Stack
4. TCP Client Example
5. TCP Server Example
6. HTTP Server Demo
7. UDP Server Implementation
Agenda
STM32F407x Ethernet Interface
● GlobalLogic Embedded Starter Kit (GL ESK) is based on the STM32F407G-DISC1 board
produced by STMicroelectronics
● STM32F407VG microcontroller contains an Ethernet MAC (Media Access Control) module
that supports two industry standard interfaces to the external physical layer chip (PHY):
- Media Independent Interface (MII)
- Reduced Media Independent Interface (RMII)
● To connect the STM32F407G-DISC1 board to the KSZ8081RNB PHY, placed on GL ESK,
RMII is used
5
STM32F407VG Ethernet MAC
STM32F407VG Ethernet MAC
● The Ethernet peripheral consists of a MAC 802.3 (media access control) with a dedicated
DMA controller
- The DMA controller interfaces with the Core and memories through the AHB Master
and Slave interfaces
- The AHB Master Interface controls data transfers while the AHB Slave interface
accesses Control and Status registers (CSR) space
● A set of configuration registers permit the user to select the desired mode and features for the
MAC and the DMA controller
STM32F407VG Ethernet MAC
STM32F407VG Ethernet MAC
The Ethernet block diagram contains the following abbreviation :
● PTP IEEE 1588 : Precision Time Protocol is a protocol used to synchronize clocks throughout
a computer network
● PMT : Power Management Technology supports the reception of network wakeup frames and
Magic Packet frames
● MMC : MAC Management Counters maintain a set of registers for gathering statistics on the
received and transmitted frames
Looking at the Ethernet block diagram above, there are two different interfaces between MCU and
an external physical chip :
● MII/RMII to transfer data between MCU and external PHY
● Station Management Interface (SMI) to communicate with external PHY
Station Management Interface (SMI)
● The station management interface allows the application to access any PHY registers
through a 2-wire clock (MDC) and data (MDIO) lines
● The interface supports accessing up to 32 PHYs
● The application can select one of the 32 PHYs and one of the 32 registers within any PHY
and send control data or receive status information
● Only one register in one PHY can be addressed at any given time
There are three types of registers :
● Basic (0 - 1)
● Extended (2 - 14)
● Vendor specific (16 - 31)
Note : For more information about SMI refer to the Reference Manual.
Reduced Media Independent Interface (RMII)
● The reduced media-independent interface specification reduces the pin count between the
microcontroller Ethernet peripheral and the external Ethernet
● According to the IEEE 802.3u standard, an MII contains 16 pins for data and control. The
RMII specification is dedicated to reduce the pin count to 7 pins
● The RMII is instantiated between the MAC and the PHY. This helps to translate the MAC’s
MII into the RMII
The RMII block has the following characteristics :
● It supports 10-Mbit/s and 100-Mbit/s operating rates
● The clock reference must be doubled to 50 MHz
● The same clock reference must be sourced externally to both MAC and external Ethernet
PHY
● It provides independent 2-bit wide (dibit) transmit and receive data paths
Reduced Media Independent Interface (RMII)
Reduced Media Independent Interface (RMII)
Looking at the description of RMII signals, consider each of them in detail :
● TXD[1:0]: transmit data is a bundle of 2 data signals driven synchronously by the MAC
sublayer
● TX_EN: while TX_EN is asserted the transmit data have effect upon the PHY
● RXD[1:0]: reception data is a bundle of 2 data signals driven synchronously by the PHY
● CRSDV: Carrier Sense (CRS) and RX_Data Valid (RX_DV) multiplexed on alternate clock
cycles
● MDC: SMI clock signal
● MDIO: SMI data input/output
● REF_CLK: Continuous 50 MHz reference clock
13
KSZ8081RND PHY
KSZ8081RND PHY
● The KSZ8081RND is a single-supply 10Base-T/100Base-TX Ethernet physical layer
transceiver for transmission and reception of data over standard CAT-5 unshielded twisted
pair (UTP) cable
● The KSZ8081RND takes in the 50MHz RMII reference clock as the power-up default
● The KSZ8081RND is configured optionally to RMII – 25MHz Clock Mode after it is powered up
or hardware reset and software programmed with the following :
- An external 25MHz clock source (oscillator) connected to XI (pin 8)
- Register 1Fh, bit [7] programmed to ‘1’ to select RMII – 25MHz Clock Mode
KSZ8081RNB PHY
KSZ8081RND PHY
KSZ8081RND PHY
● The KSZ8081RND supports PHY addresses 0x0h, 0x3h, 0x4, 0x7
● The PHY Address is latched at the deassertion of reset
○ Pull-up = PHY Address bits [1:0] are both set to 1
○ Pull-down (default) = PHY Address bits [1:0] are both set to 0
● PHY Address bits [4:3] are set to 0x00 by default
● The KSZ8081RND contains 32 registers, the register map is shown below
Note: For information on the formats of internal registers, see the documentation for the KSZ8081RND
KSZ8081RND PHY
19
STM32F407x HAL Ethernet Driver
STM32F407x HAL Ethernet Driver
● The STM32Cube IDE uses STM32CubeMX plug-in to automatically generate initialization
code. The generated source code is based on the HAL driver
● The STM32CubeMX plug-in can automatically generate configurations for two PHYs :
- LAN8742A
- DP83848
● The STM32CubeMX plug-in allows users to configure HAL Ethernet driver. The next pictures
illustrate configuration of HAL Ethernet driver in the STM32Cube IDE through the
STM32CubeMX plug-in
Note: Unfortunately, the KSZ8081RND PHY installed on GL Embedded Starter Kit is not supported by
the STM32CubeMX code generator so the Ethernet driver was replaced with another one, which was created
based on the HAL Ethernet driver. This driver sets up 25MHz clock mode and uses the vendor specific
registers to configure the KSZ8081RND chip
ETH Parameter Settings
ETH Advanced Parameters
ETH GPIO Settings
ETH Driver settings
25
Lightweight TCP/IP (LwIP) Stack
Lightweight TCP/IP Stack features
● LwIP is a free TCP/IP stack developed by Adam Dunkels at the Swedish Institute of
Computer Science (SICS) and licensed under a modified BSD license
● The focus of the LwIP TCP/IP implementation is to reduce RAM usage while keeping a full
scale TCP/IP stack. This makes LwIP suitable for use in embedded systems
● LwIP comes with the following protocols :
- IPv4 and IPv6 (Internet Protocol v4 and v6)
- ICMP (Internet Control Message Protocol) for network maintenance and debugging
- IGMP (Internet Group Management Protocol) for multicast traffic management
- UDP (User Datagram Protocol)
- TCP (Transmission Control Protocol)
- DNS (Domain Name Server)
- SNMP (Simple Network Management Protocol)
- DHCP (Dynamic Host Configuration Protocol)
- PPP (Point to Point Protocol)
- ARP (Address Resolution Protocol)
Lightweight TCP/IP Stack features
LwIP has three application programming interfaces (APIs) :
● Raw API is the native LwIP API. It enables the development of applications using event
callbacks. This API provides the best performance and optimized code size, but adds
some complexity to application development
● Netconn API is a high-level sequential API that requires a real-time operating system
(RTOS). The Netconn API enables multithreaded operations.
● BSD Socket API: Berkeley-like Socket API (developed on top of the Netconn API)
LwIP architecture
● LwIP complies with the TCP/IP model architecture which specifies how data should be
formatted, transmitted, routed and received to provide end-to-end communications
● This model includes four abstraction layers which are used to sort all related protocols
according to the scope of networking involved (see Figure 1).
From lowest to highest, the layers are :
- The link layer contains communication technologies for a single network segment
(link) of a local area network
- The internet layer (IP) connects independent networks, thus establishing
internetworking
- The transport layer handles host-to-host communications
- The application layer contains all protocols for specific data communications services on
a process-to-process level
LwIP architecture
LwIP configuration
● LwIP provides a file named lwipopts.h that allows the user to fully configure the stack and all
its modules. If an option is not defined, a default value defined in opt.h file is used
● The user can choose the modules he needs for his application, so that the code size will be
optimized by compiling only the selected features
example:
#define LWIP_UDP 1 /* Enable UDP */
● LwIP provides a flexible way to manage memory pool sizes and organization. It reserves a
fixed-size static memory area in the data segment
● The following table provides a summary of the main RAM memory options
LwIP memory configuration
LwIP memory option Definition
MEM_SIZE LwIP heap memory size: used for all LwIP dynamic
memory allocations
MEMP_NUM_PBUF Total number of MEM_REF and MEM_ROM pbufs
MEMP_NUM_UDP_PCB Total number of UDP PCB structures
MEMP_NUM_TCP_PCB Total number of TCP PCB structures
MEMP_NUM_TCP_PCB_LISTEN Total number of listening TCP PCBs
MEMP_NUM_TCP_SEG Maximum number of simultaneously queued TCP
segments
LwIP memory configuration
LwIP memory option Definition
PBUF_POOL_SIZE Total number of PBUF_POOL type pbufs
PBUF_POOL_BUFSIZE Size of a PBUF_POOL type pbufs
TCP_MSS TCP maximum segment size
TCP_SND_BUF TCP send buffer space for a connection
TCP_SND_QUEUELEN Maximum number of pbufs in the TCP send queue
TCP_WND Advertised TCP receive window size
LwIP setting in STM32CubeMX
● LwIP stack is used in STM32CubeMX plug-in together with FreeRTOS, which is wrapped by
the CMSIS_OS interface
● The STM32Cube IDE through STM32CubeMX plug-in allows to automatically configure LwIP
stack
- as a result of LwIP settings, the files in the LWIP directory of the project will be modified
- automatically generated ethernetif.c file is used to link the LwIP stack to the STM32F407x
HAL Ethernet driver
● Here is a list of APIs from ethernetif.c file
- low_level_init : calls driver functions to initialize Ethernet
- low_level_output : calls driver functions to send Ethernet packet
- low_level_input : calls driver functions to receive Ethernet packet
- ethernetif_init : initializes the network interface structure (netif) then calls low_level_init
- ethernetif_input : calls low_level_input to receive a packet then push it onto LwIP stack
LwIP General Settings
LwIP Key Options
LwIP Debug
FreeRTOS Config Parameters
38
TCP Client Example
How to use TCP Client Example
● connect GL Embedded Starter Kit to the same local network as your PC is connected to
● open Linux terminal then install and launch Wireshark to capture a connection session
between the board and PC :
$ sudo apt install wireshark -y
$ sudo usermod -a -G wireshark $USER
$ sudo reboot
● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client
project
● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’
menu item, then define SERVER=”XXX.XXX.XXX.XXX” with IP address of your PC. Build and
load the firmware
● check if network interface of your board is up by pinging the board. If so, open Linux terminal
and launch the following commands :
$ sudo apt install ncat -y
$ ncat -l 1500 --keep-open --exec /bin/cat
● push the blue button on the board and watch the packets in the Wireshark window
TCP Client Example
TCP Client Example
TCP Client Example
TCP Client Example
TCP Client Example
45
TCP Server Example
How to use TCP Server Example
● connect GL Embedded Starter Kit to the same local network as your PC is connected to
● launch Wireshark to capture a connection session between the board and PC
● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client
project
● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’ menu
item, check if USE_TCP_SERVER macros is defined. If not, define USE_TCP_SERVER. Build
and load the firmware
● check if network interface of your board is up by pinging the board. If so, open Linux terminal
and launch the following command then enter some text message to be sent :
$ ncat <IP of the board> 1500
● to read logs from TCP server through USB-UART, define USE_TCP_SERVER_PRINTF=1 in
Core/Inc/main.h. Build and load the firmware
TCP Server Example
TCP Server Example
TCP Server Example
50
HTTP Server Demo
How to use HTTP Server Demo
● connect GL Embedded Starter Kit to the same local network as your PC is connected to
● launch Wireshark to capture a connection session between the board and PC
● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client
project
● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’
menu item, check if USE_TCP_SERVER macros is defined. If so, remove
USE_TCP_SERVER. Define USE_HTTP_SERVER, USE_HTTP_SERVER_SOLUTION if
they are not defined. Build and load the firmware
● open your internet browser and enter the IP address of your board. Use form controls to
toggle LEDs
● read humidity from DHT11 by entering ‘<IP of the board>/humidity’ in your internet browser
● read temperature from DHT11 by entering ‘<IP of the board>/temperature’ in your internet
browser
HTTP Server Demo
HTTP Server Demo
HTTP Server Demo
HTTP Server Demo
56
UDP Server Implementation
UDP Server Implementation
● Implement a UDP server, that must be launched in a separate thread of the tcp_socket_client
project
● The UDP server must accept and execute the following commands from the UDP client :
- led<N> on : turn on the LED<N>, where N = 3,4,5,6
- led<N> off : turn off the LED<N>, where N = 3,4,5,6
- led<N> toggle : toggle the LED<N>, where N = 3,4,5,6
- example: led3 toggle
● Use ncat utility as a UDP client :
$ ncat -u <IP of the board> 5678
led3 toggle
● Use Wireshark, output through USB-UART or LCD to debug your application
● Demonstrate how your server works
58
Thank You

More Related Content

PPTX
Networking essentials lect2
PPTX
Networking essentials lect3
PPTX
Basic Programming concepts - Programming with C++
PPTX
Ports and protocols
DOCX
Ports and protocols
PPT
rip, ospf 13-14
PPTX
16 coms 525 tcpip - routing protocols -all
PPT
Networking essentials lect2
Networking essentials lect3
Basic Programming concepts - Programming with C++
Ports and protocols
Ports and protocols
rip, ospf 13-14
16 coms 525 tcpip - routing protocols -all

What's hot (20)

PPT
TCP/IP(networking)
PDF
TCP - Transmission Control Protocol
PPSX
Lesson.7: Configuring IP Routing B
PPTX
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
PPT
Transport protocols
PDF
Transport layer services
PPTX
TCP/IP and UDP protocols
PPTX
Transport layer
PDF
Unit 4 tansport layer in the internat
PPTX
10 routing-bgp
PPTX
Multipath TCP
PPTX
Tcp udp
PPTX
Transport Layer in Computer Networks (TCP / UDP / SCTP)
PPT
User Datagram protocol For Msc CS
PPTX
Computer Network Syllabus
PPTX
Multipath TCP as Security Solution
PPT
Features of tcp (part 2) .68
PPT
Chap 10 igmp
PDF
MultiPath TCP - The path to multipath
PPTX
Transport Layer Part 1
TCP/IP(networking)
TCP - Transmission Control Protocol
Lesson.7: Configuring IP Routing B
TCP & UDP ( Transmission Control Protocol and User Datagram Protocol)
Transport protocols
Transport layer services
TCP/IP and UDP protocols
Transport layer
Unit 4 tansport layer in the internat
10 routing-bgp
Multipath TCP
Tcp udp
Transport Layer in Computer Networks (TCP / UDP / SCTP)
User Datagram protocol For Msc CS
Computer Network Syllabus
Multipath TCP as Security Solution
Features of tcp (part 2) .68
Chap 10 igmp
MultiPath TCP - The path to multipath
Transport Layer Part 1
Ad

Similar to Gl embedded starterkit_ethernet (20)

PDF
Tft touch screen manufacturers
DOCX
Assignment
PDF
[Application guide] IoT Protocol gateway
PPTX
Webinar: Comunicação TCP/IP segura
PDF
Nt1310 Unit 5 Algorithm
PPT
An Overview of LPC2101/02/03
PDF
Arm usr m,anl
PDF
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
PDF
A42060105
PPTX
Modbus
PPTX
Cdot Max ng architecture working models
PDF
VJITSk 6713 user manual
PDF
Lecture 5-Embedde.pdf
PPT
Basic Study on the WT12 Family of Bluetooth Devices
PPTX
Bhabha atomic research Centre (BARC)
PPTX
PPTX
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
PPT
Overview of LPC213x MCUs
PDF
Bm36382385
PDF
International Refereed Journal of Engineering and Science (IRJES)
Tft touch screen manufacturers
Assignment
[Application guide] IoT Protocol gateway
Webinar: Comunicação TCP/IP segura
Nt1310 Unit 5 Algorithm
An Overview of LPC2101/02/03
Arm usr m,anl
AN INTEGRATED FOUR-PORT DC-DC CONVERTER-CEI0080
A42060105
Modbus
Cdot Max ng architecture working models
VJITSk 6713 user manual
Lecture 5-Embedde.pdf
Basic Study on the WT12 Family of Bluetooth Devices
Bhabha atomic research Centre (BARC)
INDUSTRIAL TRAINING REPORT EMBEDDED SYSTEM.pptx
Overview of LPC213x MCUs
Bm36382385
International Refereed Journal of Engineering and Science (IRJES)
Ad

More from Roman Brovko (20)

PDF
Individual task Networking
PPTX
Networking essentials lect1
PPTX
Bare metal training_07_spi_flash
PPTX
Bare metal training_06_I2C
PPTX
Glesk worshop
PPTX
Bare metal training_05_uart
PPTX
Bare metal training_04_adc_temp_sensor
PPTX
Bare metal training_03_timers_pwm
PPTX
Bare metal training_02_le_ds_and_buttons
PPTX
Bare metal training_01_hello_world
PPTX
Bare metal training_00_prerequisites
PPTX
C language lect_23_advanced
PPTX
C language lect_22_advanced
PPTX
C language lect_21_advanced
PPTX
подготовка рабочего окружения
PPTX
C language lect_20_advanced
PPTX
C language lect_19_basics
PPTX
C language lect_18_basics
PPTX
C language lect_17_basics
PPTX
C language lect_16_basics
Individual task Networking
Networking essentials lect1
Bare metal training_07_spi_flash
Bare metal training_06_I2C
Glesk worshop
Bare metal training_05_uart
Bare metal training_04_adc_temp_sensor
Bare metal training_03_timers_pwm
Bare metal training_02_le_ds_and_buttons
Bare metal training_01_hello_world
Bare metal training_00_prerequisites
C language lect_23_advanced
C language lect_22_advanced
C language lect_21_advanced
подготовка рабочего окружения
C language lect_20_advanced
C language lect_19_basics
C language lect_18_basics
C language lect_17_basics
C language lect_16_basics

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
RMMM.pdf make it easy to upload and study
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
RMMM.pdf make it easy to upload and study
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Renaissance Architecture: A Journey from Faith to Humanism
2.FourierTransform-ShortQuestionswithAnswers.pdf
Cell Structure & Organelles in detailed.
Anesthesia in Laparoscopic Surgery in India
O5-L3 Freight Transport Ops (International) V1.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPH.pptx obstetrics and gynecology in nursing
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharma ospi slides which help in ospi learning

Gl embedded starterkit_ethernet

  • 1. 1
  • 2. 2 C/Embedded Base Camp Connection of GL Embedded Starter Kit to Ethernet Petro Shevchenko July 2021
  • 3. 1. STM32F407x Ethernet Interface 2. STM32F407x HAL Ethernet Driver 3. Lightweight TCP/IP Stack 4. TCP Client Example 5. TCP Server Example 6. HTTP Server Demo 7. UDP Server Implementation Agenda
  • 4. STM32F407x Ethernet Interface ● GlobalLogic Embedded Starter Kit (GL ESK) is based on the STM32F407G-DISC1 board produced by STMicroelectronics ● STM32F407VG microcontroller contains an Ethernet MAC (Media Access Control) module that supports two industry standard interfaces to the external physical layer chip (PHY): - Media Independent Interface (MII) - Reduced Media Independent Interface (RMII) ● To connect the STM32F407G-DISC1 board to the KSZ8081RNB PHY, placed on GL ESK, RMII is used
  • 6. STM32F407VG Ethernet MAC ● The Ethernet peripheral consists of a MAC 802.3 (media access control) with a dedicated DMA controller - The DMA controller interfaces with the Core and memories through the AHB Master and Slave interfaces - The AHB Master Interface controls data transfers while the AHB Slave interface accesses Control and Status registers (CSR) space ● A set of configuration registers permit the user to select the desired mode and features for the MAC and the DMA controller
  • 8. STM32F407VG Ethernet MAC The Ethernet block diagram contains the following abbreviation : ● PTP IEEE 1588 : Precision Time Protocol is a protocol used to synchronize clocks throughout a computer network ● PMT : Power Management Technology supports the reception of network wakeup frames and Magic Packet frames ● MMC : MAC Management Counters maintain a set of registers for gathering statistics on the received and transmitted frames Looking at the Ethernet block diagram above, there are two different interfaces between MCU and an external physical chip : ● MII/RMII to transfer data between MCU and external PHY ● Station Management Interface (SMI) to communicate with external PHY
  • 9. Station Management Interface (SMI) ● The station management interface allows the application to access any PHY registers through a 2-wire clock (MDC) and data (MDIO) lines ● The interface supports accessing up to 32 PHYs ● The application can select one of the 32 PHYs and one of the 32 registers within any PHY and send control data or receive status information ● Only one register in one PHY can be addressed at any given time There are three types of registers : ● Basic (0 - 1) ● Extended (2 - 14) ● Vendor specific (16 - 31) Note : For more information about SMI refer to the Reference Manual.
  • 10. Reduced Media Independent Interface (RMII) ● The reduced media-independent interface specification reduces the pin count between the microcontroller Ethernet peripheral and the external Ethernet ● According to the IEEE 802.3u standard, an MII contains 16 pins for data and control. The RMII specification is dedicated to reduce the pin count to 7 pins ● The RMII is instantiated between the MAC and the PHY. This helps to translate the MAC’s MII into the RMII The RMII block has the following characteristics : ● It supports 10-Mbit/s and 100-Mbit/s operating rates ● The clock reference must be doubled to 50 MHz ● The same clock reference must be sourced externally to both MAC and external Ethernet PHY ● It provides independent 2-bit wide (dibit) transmit and receive data paths
  • 11. Reduced Media Independent Interface (RMII)
  • 12. Reduced Media Independent Interface (RMII) Looking at the description of RMII signals, consider each of them in detail : ● TXD[1:0]: transmit data is a bundle of 2 data signals driven synchronously by the MAC sublayer ● TX_EN: while TX_EN is asserted the transmit data have effect upon the PHY ● RXD[1:0]: reception data is a bundle of 2 data signals driven synchronously by the PHY ● CRSDV: Carrier Sense (CRS) and RX_Data Valid (RX_DV) multiplexed on alternate clock cycles ● MDC: SMI clock signal ● MDIO: SMI data input/output ● REF_CLK: Continuous 50 MHz reference clock
  • 14. KSZ8081RND PHY ● The KSZ8081RND is a single-supply 10Base-T/100Base-TX Ethernet physical layer transceiver for transmission and reception of data over standard CAT-5 unshielded twisted pair (UTP) cable ● The KSZ8081RND takes in the 50MHz RMII reference clock as the power-up default ● The KSZ8081RND is configured optionally to RMII – 25MHz Clock Mode after it is powered up or hardware reset and software programmed with the following : - An external 25MHz clock source (oscillator) connected to XI (pin 8) - Register 1Fh, bit [7] programmed to ‘1’ to select RMII – 25MHz Clock Mode
  • 17. KSZ8081RND PHY ● The KSZ8081RND supports PHY addresses 0x0h, 0x3h, 0x4, 0x7 ● The PHY Address is latched at the deassertion of reset ○ Pull-up = PHY Address bits [1:0] are both set to 1 ○ Pull-down (default) = PHY Address bits [1:0] are both set to 0 ● PHY Address bits [4:3] are set to 0x00 by default ● The KSZ8081RND contains 32 registers, the register map is shown below Note: For information on the formats of internal registers, see the documentation for the KSZ8081RND
  • 20. STM32F407x HAL Ethernet Driver ● The STM32Cube IDE uses STM32CubeMX plug-in to automatically generate initialization code. The generated source code is based on the HAL driver ● The STM32CubeMX plug-in can automatically generate configurations for two PHYs : - LAN8742A - DP83848 ● The STM32CubeMX plug-in allows users to configure HAL Ethernet driver. The next pictures illustrate configuration of HAL Ethernet driver in the STM32Cube IDE through the STM32CubeMX plug-in Note: Unfortunately, the KSZ8081RND PHY installed on GL Embedded Starter Kit is not supported by the STM32CubeMX code generator so the Ethernet driver was replaced with another one, which was created based on the HAL Ethernet driver. This driver sets up 25MHz clock mode and uses the vendor specific registers to configure the KSZ8081RND chip
  • 26. Lightweight TCP/IP Stack features ● LwIP is a free TCP/IP stack developed by Adam Dunkels at the Swedish Institute of Computer Science (SICS) and licensed under a modified BSD license ● The focus of the LwIP TCP/IP implementation is to reduce RAM usage while keeping a full scale TCP/IP stack. This makes LwIP suitable for use in embedded systems ● LwIP comes with the following protocols : - IPv4 and IPv6 (Internet Protocol v4 and v6) - ICMP (Internet Control Message Protocol) for network maintenance and debugging - IGMP (Internet Group Management Protocol) for multicast traffic management - UDP (User Datagram Protocol) - TCP (Transmission Control Protocol) - DNS (Domain Name Server) - SNMP (Simple Network Management Protocol) - DHCP (Dynamic Host Configuration Protocol) - PPP (Point to Point Protocol) - ARP (Address Resolution Protocol)
  • 27. Lightweight TCP/IP Stack features LwIP has three application programming interfaces (APIs) : ● Raw API is the native LwIP API. It enables the development of applications using event callbacks. This API provides the best performance and optimized code size, but adds some complexity to application development ● Netconn API is a high-level sequential API that requires a real-time operating system (RTOS). The Netconn API enables multithreaded operations. ● BSD Socket API: Berkeley-like Socket API (developed on top of the Netconn API)
  • 28. LwIP architecture ● LwIP complies with the TCP/IP model architecture which specifies how data should be formatted, transmitted, routed and received to provide end-to-end communications ● This model includes four abstraction layers which are used to sort all related protocols according to the scope of networking involved (see Figure 1). From lowest to highest, the layers are : - The link layer contains communication technologies for a single network segment (link) of a local area network - The internet layer (IP) connects independent networks, thus establishing internetworking - The transport layer handles host-to-host communications - The application layer contains all protocols for specific data communications services on a process-to-process level
  • 30. LwIP configuration ● LwIP provides a file named lwipopts.h that allows the user to fully configure the stack and all its modules. If an option is not defined, a default value defined in opt.h file is used ● The user can choose the modules he needs for his application, so that the code size will be optimized by compiling only the selected features example: #define LWIP_UDP 1 /* Enable UDP */ ● LwIP provides a flexible way to manage memory pool sizes and organization. It reserves a fixed-size static memory area in the data segment ● The following table provides a summary of the main RAM memory options
  • 31. LwIP memory configuration LwIP memory option Definition MEM_SIZE LwIP heap memory size: used for all LwIP dynamic memory allocations MEMP_NUM_PBUF Total number of MEM_REF and MEM_ROM pbufs MEMP_NUM_UDP_PCB Total number of UDP PCB structures MEMP_NUM_TCP_PCB Total number of TCP PCB structures MEMP_NUM_TCP_PCB_LISTEN Total number of listening TCP PCBs MEMP_NUM_TCP_SEG Maximum number of simultaneously queued TCP segments
  • 32. LwIP memory configuration LwIP memory option Definition PBUF_POOL_SIZE Total number of PBUF_POOL type pbufs PBUF_POOL_BUFSIZE Size of a PBUF_POOL type pbufs TCP_MSS TCP maximum segment size TCP_SND_BUF TCP send buffer space for a connection TCP_SND_QUEUELEN Maximum number of pbufs in the TCP send queue TCP_WND Advertised TCP receive window size
  • 33. LwIP setting in STM32CubeMX ● LwIP stack is used in STM32CubeMX plug-in together with FreeRTOS, which is wrapped by the CMSIS_OS interface ● The STM32Cube IDE through STM32CubeMX plug-in allows to automatically configure LwIP stack - as a result of LwIP settings, the files in the LWIP directory of the project will be modified - automatically generated ethernetif.c file is used to link the LwIP stack to the STM32F407x HAL Ethernet driver ● Here is a list of APIs from ethernetif.c file - low_level_init : calls driver functions to initialize Ethernet - low_level_output : calls driver functions to send Ethernet packet - low_level_input : calls driver functions to receive Ethernet packet - ethernetif_init : initializes the network interface structure (netif) then calls low_level_init - ethernetif_input : calls low_level_input to receive a packet then push it onto LwIP stack
  • 39. How to use TCP Client Example ● connect GL Embedded Starter Kit to the same local network as your PC is connected to ● open Linux terminal then install and launch Wireshark to capture a connection session between the board and PC : $ sudo apt install wireshark -y $ sudo usermod -a -G wireshark $USER $ sudo reboot ● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client project ● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’ menu item, then define SERVER=”XXX.XXX.XXX.XXX” with IP address of your PC. Build and load the firmware ● check if network interface of your board is up by pinging the board. If so, open Linux terminal and launch the following commands : $ sudo apt install ncat -y $ ncat -l 1500 --keep-open --exec /bin/cat ● push the blue button on the board and watch the packets in the Wireshark window
  • 46. How to use TCP Server Example ● connect GL Embedded Starter Kit to the same local network as your PC is connected to ● launch Wireshark to capture a connection session between the board and PC ● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client project ● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’ menu item, check if USE_TCP_SERVER macros is defined. If not, define USE_TCP_SERVER. Build and load the firmware ● check if network interface of your board is up by pinging the board. If so, open Linux terminal and launch the following command then enter some text message to be sent : $ ncat <IP of the board> 1500 ● to read logs from TCP server through USB-UART, define USE_TCP_SERVER_PRINTF=1 in Core/Inc/main.h. Build and load the firmware
  • 51. How to use HTTP Server Demo ● connect GL Embedded Starter Kit to the same local network as your PC is connected to ● launch Wireshark to capture a connection session between the board and PC ● open STM32Cube IDE, select default workspace with previously imported tcp_socket_client project ● select ‘Project->Properties->C/C++Build->Settings->MCU GCC Compiler->Preprocessor’ menu item, check if USE_TCP_SERVER macros is defined. If so, remove USE_TCP_SERVER. Define USE_HTTP_SERVER, USE_HTTP_SERVER_SOLUTION if they are not defined. Build and load the firmware ● open your internet browser and enter the IP address of your board. Use form controls to toggle LEDs ● read humidity from DHT11 by entering ‘<IP of the board>/humidity’ in your internet browser ● read temperature from DHT11 by entering ‘<IP of the board>/temperature’ in your internet browser
  • 57. UDP Server Implementation ● Implement a UDP server, that must be launched in a separate thread of the tcp_socket_client project ● The UDP server must accept and execute the following commands from the UDP client : - led<N> on : turn on the LED<N>, where N = 3,4,5,6 - led<N> off : turn off the LED<N>, where N = 3,4,5,6 - led<N> toggle : toggle the LED<N>, where N = 3,4,5,6 - example: led3 toggle ● Use ncat utility as a UDP client : $ ncat -u <IP of the board> 5678 led3 toggle ● Use Wireshark, output through USB-UART or LCD to debug your application ● Demonstrate how your server works