SMART ARM-based Microcontroller
AT16827: TCP/IP Server-Client with CycloneTCP
APPLICATION NOTE
Introduction
In today’s world, computer networking has become an integral part of life.
There are many different networks available to share information between
groups of devices through a shared communication medium. They are
mainly differentiated by the physical medium and protocol standards.
Ethernet is a prime wired networking standard which is an an obvious choice
for many network applications due to reliability, efficiency, and speed.
Ethernet standard is used in various application segments.
Nowadays, microcontrollers integrate peripherals to support Ethernet.
Atmel
®
| SMART SAM E70 and SAM V71 series devices contain an inbuilt
peripheral for 10/100 Mbps Ethernet MAC, compatible with IEEE 802.3
standard.
This application note address the use of Ethernet MAC (GMAC) peripheral
on SAM V70/E71 devices in network applications. When discussing network
applications, the basic understanding of TCP/IP protocol layers is necessary.
As an introduction, this application note explains the basic concepts of
TCP/IP software stacks.
The TCP/IP stack used in this application note is CycloneTCP from Oryx
Embedded. The CycloneTCP is a dual IPv4/IPv6 stack dedicated to
embedded applications. This application note describe following topics:
• TCP/IP Protocol Model
• Ethernet Peripheral overview
• CycloneTCP overview
• HTTP Server Implementation using CycloneTCP
• HTTP Client using CycloneTCP
• Test setup and procedure
Atmel-42738A-TCP/IP-Server-Client-with-CycloneTCP_AT16287_Application Note-06/2016
Table of Contents
Introduction......................................................................................................................1
1. Abbreviations.............................................................................................................4
2. TCP/IP Protocol Model.............................................................................................. 5
2.1. Layered Architecture.................................................................................................................... 5
2.1.1. Application Layer........................................................................................................... 5
2.1.2. Transport Layer..............................................................................................................6
2.1.3. Internet Layer.................................................................................................................6
2.1.4. Network Access Layer................................................................................................... 7
2.2. Encapsulation...............................................................................................................................7
2.3. Basics of TCP Client – Server communication.............................................................................8
2.4. TCP/IP Application Programming Interface (API).........................................................................9
2.4.1. The Socket Interface......................................................................................................9
2.5. Messages on Network Interface.................................................................................................12
2.5.1. TCP/IP Socket Opening Sequence............................................................................. 12
2.5.2. TCP/IP Socket Connection Sequence.........................................................................12
2.5.3. TCP/IP Socket Data Transfer Sequence..................................................................... 13
2.5.4. TCP/IP Socket Closing Sequence............................................................................... 14
2.6. Summary of the section..............................................................................................................15
3. Ethernet Peripheral Overview..................................................................................16
3.1. Ethernet Frame...........................................................................................................................16
3.2. Ethernet MAC (GMAC)...............................................................................................................17
3.2.1. GMAC Features...........................................................................................................17
3.2.2. GMAC Memory............................................................................................................ 19
3.2.3. GMAC - Transmit Block............................................................................................... 20
3.2.4. GMAC - Receive Block................................................................................................ 21
3.2.5. GMAC- Frame Filtering................................................................................................22
3.2.6. GMAC- PHY interfacing...............................................................................................22
3.2.7. GMAC - Other functions.............................................................................................. 22
3.3. Ethernet PHY..............................................................................................................................23
3.4. Summary of the section..............................................................................................................25
4. CycloneTCP Stack Overview...................................................................................26
4.1. CycloneTCP Features................................................................................................................ 26
4.2. Supported Operating Systems................................................................................................... 28
4.3. Source Files................................................................................................................................28
5. Demo Applications with CycloneTCP ..................................................................... 29
5.1. HTTP Web-Server Demo........................................................................................................... 29
5.2. HTTP Client Demo..................................................................................................................... 32
5.3. Demo Test Procedure.................................................................................................................35
5.3.1. HTTP Web-server Demo............................................................................................. 35
5.3.2. HTTP Client on SAM V71............................................................................................ 38
Atmel AT16827: TCP/IP Server-Client with CycloneTCP [APPLICATION NOTE]
Atmel-42738A-TCP/IP-Server-Client-with-CycloneTCP_AT16287_Application Note-06/2016
2
6. Conclusion...............................................................................................................41
7. Suggested reading...................................................................................................42
7.1. Atmel SMART SAM E70 and V71 Datasheet.............................................................................42
7.2. ARM Documentation on Cortex-M7 core....................................................................................42
7.3. CycloneTCP Documentation...................................................................................................... 42
7.4. FreeRTOS documentation..........................................................................................................42
7.5. Ethernet PHY..............................................................................................................................42
7.6. Networking Reference Standards.............................................................................................. 42
8. Revision history....................................................................................................... 44
Atmel AT16827: TCP/IP Server-Client with CycloneTCP [APPLICATION NOTE]
Atmel-42738A-TCP/IP-Server-Client-with-CycloneTCP_AT16287_Application Note-06/2016
3
1. Abbreviations
ACK Acknowledgment; refer to ACK bit in TCP header
ARP Address Resolution Protocol
CRC Cyclic Redundancy Check
CSMA/CD Carrier sense multiple access / collision detection
DMA Direct Memory Access
FIN Finish; refer to FIN bit in TCP header
HTTP HyperText Transfer Protocol
HTTPS HyperText Transfer Protocol Secure
ICMP Internet Control Message Protocol
IP Internet Protocol
LAN Local area network
MAC Media access control
Mbps Megabits per second
MDI Medium Dependent Interface or Management Data Input
MDIO Management Data Input/Output
MDO Management Data Output
MII Media Independent Interface
NAT Network Address Translation
OSI Open System Interconnect (joint ISO and ITU standard)
PHY Ethernet physical layer
RMII Reduced Media Independent Interface: A 2-bit version of the MII
SYN Synchronize; refer to SYN bit in TCP header
TCP Transmission Control Protocol
TCP/IP Transmission Control Protocol/Internet Protocol
UDP User Datagram Protocol
UTP Unshielded Twisted Pair cable
Atmel AT16827: TCP/IP Server-Client with CycloneTCP [APPLICATION NOTE]
Atmel-42738A-TCP/IP-Server-Client-with-CycloneTCP_AT16287_Application Note-06/2016
4
2. TCP/IP Protocol Model
The TCP/IP protocol handles information transfer between various nodes of a network. The layered
architecture of TCP/IP provides multiple options for the physical medium to transfer data.
Ethernet is one such option that constitute the lower layers of TCP/IP protocol. Ethernet standard
describes how networked devices can format data for transmission to other devices on the same network.
Before understanding more about Ethernet MAC peripheral and using a TCP/IP protocol in applications,
this document introduces the layered architecture of TCP/IP protocol and functionality of each layer and
how protocol layers interact.
2.1. Layered Architecture
All network communication protocols follow OSI reference model from ISO (International organization of
Standardization). But for internet, the preferred choice is TCP/IP model.
The TCP/IP model with four layers maps to the seven protocol layers of OSI reference model.
The following diagram provides a comparison between the OSI layers against different layers of TCP/IP
stack.
Figure 2-1. OSI Model vs TCP/IP Model
2.1.1. Application Layer
The application layer is the topmost layer in TCP/IP model. This layer process the data, receive and
transmit to the lower layers of TCP/IP model. It also implements the application level protocol for
exchanging data with other network nodes.
The most widely known application layer protocols are:
• The Hypertext Transfer Protocol (HTTP) - used to transfer files that make up the web pages of the
World Wide Web.
• The File Transfer Protocol (FTP) - used for interactive file transfer.
• The Simple Mail Transfer Protocol (SMTP) - used for the transfer of mail messages and
attachments.
Atmel AT16827: TCP/IP Server-Client with CycloneTCP [APPLICATION NOTE]
Atmel-42738A-TCP/IP-Server-Client-with-CycloneTCP_AT16287_Application Note-06/2016
5