1.13 TCP/IP TCP Server Bridge

The TCP/IP TCP Server Bridge configuration demonstrates creating a network server with two netwrok interfaces which are bridged together (Layer2 / MAC bridge). This demo 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 bridged, which are Internal ethmac & External Ethernet controller ENC624J600.

TCP/IP TCP Server Bridge MCC Configuration

The following Project Graph diagram shows the Harmony components included in the TCP Server Bridge 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.

    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 Bridge 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

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

    • We have two host,

      • Establish a connection between the host1 with the PIC32MZ EF Starter Kit through the RJ45 connector on LAN8740 PHY daughter board

      • Establish a connection between the host2 with the PIC32MZ EF Starter Kit through the RJ45 connector on External ENC624J600 daughter board

TCP/IP TCP Server Bridge 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 Bridge 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 each of the host, when the USB cable is connected to USB-UART connector.

    2. Open a standard terminal application on each of the host (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.

  3. Assigning the static IP address:

    • The IP address of all the network nodes in the test setup must be configured to have the first three octects same (for an IPV4 address),

      In this setup, the following is the example of how the ip addresses are assigned for each node:

NodeIP AddressInterface NameHow to configure
host1192.168.100.9Laptop1Static IP address can be assinged in the ethernet settings
LAN8740 daughter board192.168.100.10eth1Static IP address can be assigned in the MCC
External ENCX24J600 daughter board192.168.100.12eth0Static IP address can be assigned in the MCC
host2192.168.100.13Laptop2Static IP address can be assinged in the ethernet settings
  • Please see the below shown network setup and connections between the nodes:

    tcpip_pic32mz_project

  1. Execution :

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

    tcpip_pic32mz_project
  • Bridge Test:

    1. Ping Test -

      1. Ping host2 from host1:

        tcpip_pic32mz_project

      2. Ping host1 from host2:

        tcpip_pic32mz_project

    2. TCP Server Test on Interface < eth0/ENCX24J600 > from host1

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

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

        tcpip_pic32mz_project
    3. HTTP Server Test on Interface < eth1/PIC32INT > from host2

      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://mchpboard_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://mchpboard_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.