1.12 TCP/IP TCP Client Server AT24MAC
This demonstration is a combination of the TCP Client and TCP Server application using AT24MAC Serial EEPROM.
It shows the usage of MPLAB Harmony TCP API to implement:
- A TCP echo server on port 9760.
- A TCP client that establishes TCP/IP connection to a TCP server.
TCP/IP TCP Client Server AT24MAC MCC Configuration
The following Project Graph diagram shows the Harmony components included in the TCP Client Server AT24MAC demonstration application.
MCC is launched by selecting Tools > Embedded > MPLAB® Code Configurator from the MPLAB X IDE and after opening the project, TCP/IP demo project is ready to be configured and regenerated.
TCP/IP Root Layer Project Graph
The root layer project shows that SERCOM2 peripheral is selected to do read and write operation for TCP/IP commands.
This is the basic configuration with SYS_CONSOLE, SYS_DEBUG and SYS_COMMAND modules. These modules are required for TCP/IP command execution.
TCP/IP Configuration
- SAM E54 Xplained Pro
Note: In the Basic Configuration layer’s TCPIP Core, the Enable Stack Initialization Callback must be enabled/checked.
- SAM E54 Xplained Pro
TCP/IP Required Application
TCP/IP demo use these application module components for this demo.
DHCP Client module to discover the IPv4 address from the nearest DHCP Server.
DNS Client provides DNS resolution capabilities to the stack.
TCP/IP Data Link Layer
Internal ethernet driver(gmac) is enabled with the external KSZ8091 PHY driver library. The MIIM Driver supports asynchronous read/write and scan operations for accessing the external PHY registers and notification when MIIM operations have completed.
TCP/IP TCP Client Server AT24MAC Hardware Configuration
This is the following section describes the hardware configuration used for this application demonstration.
- This section describes the required default hardware configuration use USB device as on board debugger and programmer for this application demonstration.
No hardware related configuration or jumper setting changes are necessary
Refer to the SAM E54 Xplained Pro User Guide
Connect the micro USB cable from the computer to the DEBUG USB connector on the SAM E54 Xplained Pro.
Establish a connection between the router/switch with the SAM E54 Xplained Pro through the RJ45 connector
TCP/IP TCP Client Server AT24MAC Running Application
This table list the name and location of the MPLAB X IDE project folder for the demonstration.
Project Name | Target Device | Target Development Board | Description |
---|---|---|---|
sam_e54_xpro.X | ATSAME54P20A | SAM E54 Xplained Pro | Demonstrates the TCP Client Server AT24MAC on development board with ATSAME54P20A device and KSZ8091 PHY daughter board. This implementation is based on bare-metal(non-RTOS). |
Running Demonstration Steps
Build and download the demonstration project on the target board.
If the board has a SERCOM2 configuration:
A virtual COM port will be detected on the computer, when the USB cable is connected to USB-UART connector.
Open a standard terminal application on the computer (like Hyper-terminal or Tera Term) and configure the virtual COM port.
Set the serial baud rate to 115200 baud in the terminal application.
See that the initialization prints on the serial port terminal.
When the DHCP client is enabled in the demonstration, wait for the DHCP server to assign an IP address for the development board. This will be printed on the serial port terminal.
Alternatively: Use the Announce service or ping to get the IP address of the board.
Run tcpip_discoverer.jar to discover the IPv4 and IPv6 address for the board.
Execution :
After the successful board bring up, the console output becomes
By entering the command netinfo, the response is obtained as shown above.
As highlighted in the above screenshot, the MAC address of the Serial EEPROM is printed instead of the default board’s MAC address as provided in the DLL’s MAC component. This indicates that the AT24MAC Serial EEPROM is used in this application.
For TCP Client test, input the following command from the serial port:
openurl < url > - The < url > argument must be a fully formed URL; for instance, http://www.microchip.com/.
For this above URL , the DNS module will make a DNS query. Then it will open a connection to the requested URL and perform a simple HTTP GET command.
The response received from the server will be printed on the terminal application through the serial port.
The expected output -
For TCP Server test, the TCP Client application is required to run on the computer (SocketTest, Packet Sender etc). In this demonstration, we use the SocketTest.
Send a TCP packet to the IP address of the hardware board using port 9760 from any TCP Client application running on the computer (SocketTest is used here).
The TCP Server demonstration running on the board will echo back everything it receives along the connection.