1.11 TCP/IP UDP Client Server

The UDP Client Server configuration demonstrates creating a network client and a network server that uses the MPLAB Harmony UDP API. This demonstration shows how the UDP/IP loopback works and it is a combination of the TCP/IP UDP Client and TCP/IP UDP Server application.

TCP/IP UDP Client Server MCC Configuration

The following Project Graph diagram shows the Harmony components included in this application demonstration.

  • MCC is launched by selecting Tools > Embedded > MPLAB® Code Configurator from the MPLAB X IDE, demo project is ready to be configured and regenerated.

  • TCP/IP Root Layer Project Graph

    The root layer project shows that FLEXCOM1 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.

    tcpip_samrh71_project
  • 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. During these components selection, the required transport and network modules are also selected.

    tcpip_samrh71_project
  • TCPIP Driver Layer

    Internal ethernet driver(GMAC) is enabled with the external KSZ8061 PHY driver library.

    tcpip_samrh71_project_driver

    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 UDP Client Server Hardware Configuration

This section describes the required default hardware configuration for SAMRH71 Evaluation Kit that can be used for the respective application demonstration.

  • For initial setup, you can refer to the Getting Started with SAMRH71F20 Evaluation Kit application note.

  • Set all SW5 DIP Switch to 0.

  • Connect the micro USB cable from the computer to the J15 USB connector on the SAMRH71 Evaluation Kit

  • Establish a connection between the router/switch with the SAMRH71 Evaluation Kit through the RJ45 connector

    required_hardware

TCP/IP UDP Client Server Running Application

MPLAB X IDE Project

This table lists the name and location of the MPLAB X IDE project folder for the demonstration.

Project NameTarget DeviceTarget Development BoardDescription
sam_rh71_ek.XATSAMRH71F20CSAMRH71F20-EKDemonstrates the TCP/IP UDP Client Server on development board with ATSAMRH71F20C device. This implementation is based on Bare Metal ( non-RTOS).

Demonstration Commands

There are three sequential commands implemented in this demonstration.

  1. setopt < hostname > < port > < message > - This command specifies the following parameters for the UDP packet: Destination IP Address or Host name, Destination Port and Message to transfer

  2. getopt - This command displays the current options

  3. sendudp - This command sends a UDP packet

Running The Demonstration

  1. Build and download the demonstration project on the target board.

  2. Connect the board UART connection:

    1. A virtual COM port will be detected on the computer, when the USB cable is connected to USB-UART connector.

    2. Open a standard terminal application on the computer (like Hyper-terminal or Tera Term) and configure the virtual COM port.

    3. Set the serial baud rate to 115200 baud in the terminal application.

    4. See that the initialization prints on the serial port terminal.

    5. 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: You can use the ping service to find the IP address of the board.

  3. Execution:

    1. Set the UDP packet options by typing setopt at the terminal console.

    2. Verify the UDP packet settings by typing getopt at the terminal console.

    3. Send the UDP packet to the destination using the sendudp command.

    4. After the sendudp command is input, the demonstration will make a DNS query to look up the host name and send a UDP packet to that host.

    5. The output message will be received by the UDP server on the port that is configured by the command setopt.

  4. Testing the UDP Server part of demonstration:

    1. As soon as a valid IP address is assigned through the DHCP to the demonstration, it is ready to accept a UDP/IP connection on port 9760.

    2. Send a UDP packet to the IP address of the hardware board and port 9760 from any UDP Client application running on the computer (SocketTest, Packet Sender etc).

    3. The UDP Server demonstration running on the evaluation kit will echo back everything it receives along the connection.