1.14 TCP/IP TCP Server Dual Interface

The TCP/IP TCP Server Dual Interface configuration demonstrates creating a network server that uses the MPLAB Harmony TCP API to create

  • a TCP/IP echo server on port 9760.

  • an HTTP web server on a Microchip board. The Non-Volatile Memory (NVM) Microchip Proprietary File System (MPFS) is used for storing the web pages in the internal Flash.

The board is configured with dual ethernet interfaces, which are Internal ethmac & External Ethernet controller ENC624J600.

TCP/IP TCP Server Dual Interface MCC Configuration

The following Project Graph diagram shows the Harmony components included in the TCP Server Dual Interface application demonstration.

  • 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 UART2 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.

    The ENCX24J600 daughter board use SPI driver and SPI1 peripheral library to communicate with the PIC32MZ EF Starter Kit -

    tcpip_pic32mz_project

    The file system component is required to select MPFS module. This is the below snapshot for the FS configuration.

    tcpip_pic32mz_project
  • TCP/IP Configuration

    • PIC32MZ EF Starter Kit

      tcpip_pic32mz_project

  • TCP/IP Required Application

    TCP/IP demo use these application module components for this demo.

    Announce module to discover the Microchip devices within a local network.

    DHCP Client module to discover the IPv4 address from the nearest DHCP Server.

    DNS Client provides DNS resolution capabilities to the stack.

    HTTPNET Server module is selected to run the web_server for the port number 80.

  • TCP/IP Data Link Layer

    1. Internal ethernet driver(ethmac)

      Internal ethernet driver(ethmac) is enabled with the external LAN8740 PHY driver library for the starter kit. The MIIM Driver supports asynchronous read/write and scan operations for accessing the external PHY registers and notification when MIIM operations have completed.

    2. External ENCX24J600 ethernet driver

      TCP/IP ENCX24J600 driver module selected for the external ethernet mac ENCX24J600 device. For high MAC TX and RX performance DRV_ENCX24J600_MAC_TX_DESCRIPTORS and DRV_ENCX24J600_MAC_RX_DESCRIPTORS can be configured respectively more than the default descriptor value size "3".

      Refer below for the components selected in the Data Link Layer of the TCP/IP stack

      tcpip_pic32mz_project

      GPIO RE9 pin is configured for SPI chip select.

      tcpip_pic32mz_project

TCP/IP TCP Server Dual Interface Hardware Configuration

This section describes the hardware configuration for PIC32MZ EF Starter Kit and one can be used for the respective application demonstration.

  1. This section describes PIC32MZ EF Starter Kit custom hardware configuration which uses the on-board debugger and programmer with Internal ethmac and External Ethernet controller ENC624J600 for this application demonstration.

    • Refer to the PIC32MZ EF Starter Kit User Guide for the programming/debugging options supported & setting up the hardware.

    • Refer to the Starter Kit I/O Expansion Board - DM320002 User Guide

    • Refer to the ENC624J600 External Ethernet PICtail Plus Daughter Board

    • The Fast 100Mbps Ethernet PICtail Plus Daughter Board is inserted to J2(or J4) on the Starter Kit I/O Expansion Board. The J2, PICtail Plus (SPI) connector on Fast 100Mbps Ethernet PICtail Plus Daughter Board is attached to I/O Expansion Board with white arrows on the two boards lined up. The PICtail daughter board is inserted to use SPI1.

    • Connect the 168 pin to 132 pin Starter Kit Adapter board to the Starter Kit I/O Expansion Board (DM320002), optionally use a nylon nut and bolt to secure the two boards together

    • Connect the PIC32MZ EF Starter kit to the 168 pin to 132 pin Starter Kit Adapter board, optionally use a nylon nut and bolt to secure the two boards together

    • Connect the mini USB cable from the computer to the USB DEBUG connector on the PIC32MZ EF Starter Kit

    • Connect the mini USB cable from the computer to the USB-UART connector on the PIC32MZ EF Starter Kit

    • Establish a connection between the router/switch with the PIC32MZ EF Starter Kit through the RJ45 connector on both the interfaces, LAN8740 PHY & External ENC624J600 daughter board.

    • Please refer to the following figure for GPIO PIN RE9.

      The pin 46 on J10 and pin 47 on J11 (on I/O Expansion board) need to be connected to control the Chip-Select ( GPIO RE9 configuration ) line by the board.

      required_hardware

      Note: In this demo, GPIO RE9 pin is configured for SPI chip select.

TCP/IP TCP Server Dual Interface Running Application

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

Project NameTarget DeviceTarget Development BoardDescription
pic32mz_ef_sk_encx24j600.XPIC32MZ2048EFH144PIC32MZ EF Starter Kit(with LAN8740 PHY) + External Ethernet Pictail Controller ENCX24J600 + I/O Expansion Board(with 168 pin to 132 pin Starter Kit Adapter board)Demonstrates the TCP Server Dual Interface on development board with PIC32MZ2048EFH144 device with LAN8740 PHY and external Ethernet controller ENCX24J600 daughter board. This is a bare-metal (non-RTOS) implementation

Running Demonstration Steps

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

  2. If the board has a 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: 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.

  3. Execution :

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

    tcpip_pic32mz_project
  • Dual Interface Test:

    1. TCP Server Test on Interface < eth0/PIC32INT >

      • Send a TCP packet to the IP address of the hardware board using port 9760 from any TCP Client application running on the computer.

      • The TCP Server Dual Interface demonstration running on the board will echo back everything it receives along the connection.

        tcpip_pic32mz_project
    2. HTTP Server Test on Interface < eth1/ENCX24J600 >

      An HTTP server is hosted by the demonstration application. Open a web browser and direct it to the board running the HTTP server by typing the URL in the address bar (for example, http://mchpencx24_e or http://< ip-address as shown in the console > ), and then pressing Enter.

      tcpip_pic32mz_project

      The demonstration application features following:

      1. Dynamic Variables and Real-time Hardware Control - On the Overview page the LEDs can be clicked to toggle the LEDs on the Microchip hardware development board. The SWITCHes on the Microchip hardware development board can be pressed to toggle the Buttons on the web page. The dynamic variables can be updated in real-time on the HTTP server.

      2. Form Processing - Input can be handled from the client by using the GET and POST methods (this functionality controls the on-board LEDs and is operational only on the Explorer 16 Development Board)

      3. Authentication - Shows an example of the commonly used restricted access feature

      4. Cookies - Shows an example of storing small text strings on the client side

      5. Server Side Includes - An example of how SSI can be used to support dynamic content

      6. File Uploads - Shows an example of a file upload using the POST method. The HTTP server can_accept_a user-defined MPFS/MPFS2 image file for web pages.

      7. Send E-mail - Shows simple SMTP POST methods

      8. Dynamic DNS - Exercises Dynamic DNS capabilities

      9. Network Configuration - The MAC address, host name, and IP address of the evaluation kit can be viewed in the Network Configuration page and some configurations can be updated

      10. MPFS Upload - A new set of web pages can be uploaded to the web server using this feature, which is accessed through http://mchpencx24_e/mpfsupload

      Notes:

      • For the LED and SWITCH functionality portion of the demonstration, configure the GPIOs connected to LEDs and Switches on Microchip hardware development board, through the Pin Configuration manager in MPLAB® Code Configurator (MCC).

      • The location of the MPFS image is fixed at the beginning of the Flash page specified by DRV_MEMORY_DEVICE_START_ADDRESS. The size of the MPFS upload is limited to DRV_MEMORY_DEVICE_MEDIA_SIZE in the demonstration. The HTTP File Upload functionality has to be enabled when the project is generated.