1.12 TCP/IP TCP Server
The TCP/IP TCP Server configuration demonstrates creating a network server that uses the MPLAB Harmony TCP API to create a TCP/IP echo server on port 9760.
TCP/IP TCP Server MCC Configuration
The following Project Graph diagram shows the Harmony components included in the TCP Server 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.
Project Graph of the TCP Server application demonstration with Internal ethmac
Project Graph of the TCP Server application demonstration with External Ethernet Daughter Board (demos with PIC32MZ EF Starter Kit)
Both ENC28j60 and ENCX24j600 daughter boards use SPI driver and SPI1 peripheral library to communicate with the PIC32MZ EF Starter Kit -
NOTE - The above diagram contains FreeRTOS component and that is required for RTOS application. For bare-metal(non-RTOS) FreeRTOS component shouldn't be selected.
TCP/IP Configuration
PIC32MZ DA Starter Kit / PIC32MZ EF Starter Kit
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(ethmac)
Internal ethernet driver(ethmac) is enabled with the external LAN8740 PHY driver library for both the starter kits. The MIIM Driver supports asynchronous read/write and scan operations for accessing the external PHY registers and notification when MIIM operations have completed.
External ENC28J60 ethernet driver
TCP/IP ENC28J60 driver module selected for the external ethernet mac ENC28J60 device. For high MAC TX and RX performance DRV_ENC28J60_MAC_TX_DESCRIPTORS and DRV_ENC28J60_MAC_RX_DESCRIPTORS can be configured respectively more than the default descriptor value size "2".
Refer below for the components selected in the Data Link Layer of the TCP/IP stack
GPIO RH12 pin is configured for SPI chip select.
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
GPIO RE9 pin is configured for SPI chip select.
TCP/IP TCP Server Hardware Configuration
This section describes the hardware configuration for PIC32MZ DA/EF Starter Kit and one can be used for the respective application demonstration.
This section describes the PIC32MZ DA Starter Kit default hardware configuration which uses the on-board debugger and programmer for this application demonstration.
Refer to the PIC32MZ DA Starter Kit User Guide for the programming/debugging options supported & setting up the hardware.
Connect micro USB cable from the computer to the DEBUG USB connector(J19) on the PIC32MZ DA Starter Kit
Connect micro USB cable from the computer to the USB-UART connector(J5) on the PIC32MZ DA Starter Kit
Establish a connection between the router/switch with the PIC32MZ DA Starter Kit through the RJ45 connector on PHY daughter board
This section describes the PIC32MZ EF Starter Kit default hardware configuration which uses the on-board debugger and programmer for this application demonstration.
Refer to the PIC32MZ EF Starter Kit User Guide for the programming/debugging options supported & setting up the hardware.
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 PHY daughter board
This section describes PIC32MZ EF Starter Kit custom hardware configuration which uses the on-board debugger and programmer with external Ethernet controller ENC28J60 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 ENC28J60 External Ethernet PICtail Plus Daughter Board
The 10 Mbps 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 Ethernet PICtail Plus Daughter Board is attached to I/O Expansion Board. 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 Starter Kit through the RJ45 connector on External ENC28J60 daughter board.
Please refer to the following figure for GPIO PIN RH12 ( without Jumper).
Note: In this demo, GPIO RH12 pin is configured for SPI chip select.
This section describes PIC32MZ EF Starter Kit custom hardware configuration which uses the on-board debugger and programmer with 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 Starter Kit through the RJ45 connector on 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.
Note: In this demo, GPIO RE9 pin is configured for SPI chip select.
TCP/IP TCP Server 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 |
---|---|---|---|
pic32mz_das_sk.X | PIC32MZ2064DAS169 | PIC32MZ DA Starter Kit | Demonstrates the TCP Server on development board with PIC32MZ2064DAS169 device and LAN8740 PHY daughter board. This implementation is based on bare-metal(non-RTOS). |
pic32mz_das_sk_freertos.X | PIC32MZ2064DAS169 | PIC32MZ DA Starter Kit | Demonstrates the TCP Server on development board with PIC32MZ2064DAS169 device and LAN8740 PHY daughter board. This implementation is based on FreeRTOS. |
pic32mz_ef_sk.X | PIC32MZ2048EFH144 | PIC32MZ EF Starter Kit | Demonstrates the TCP Server on development board with PIC32MZ2048EFH144 device and LAN8740 PHY daughter board. This implementation is based on bare-metal(non-RTOS). |
pic32mz_ef_sk_enc28j60.X | PIC32MZ2048EFH144 | PIC32MZ EF Starter Kit + External Ethernet Pictail Controller ENC28J60 + I/O Expansion Board (with 168 pin to 132 pin Starter Kit Adapter board) | Demonstrates the TCP Server on development board with PIC32MZ2048EFH144 device and external Ethernet controller ENC28J60. This is a bare-metal (non-RTOS) implementation |
pic32mz_ef_sk_enc28j60_freertos.X | PIC32MZ2048EFH144 | PIC32MZ EF Starter Kit + External Ethernet Pictail Controller ENC28J60 + I/O Expansion Board (with 168 pin to 132 pin Starter Kit Adapter board) | Demonstrates the TCP Server on development board with PIC32MZ2048EFH144 device and external Ethernet controller ENC28J60. This is with FreeRTOS implementation |
pic32mz_ef_sk_encx24j600.X | PIC32MZ2048EFH144 | PIC32MZ EF Starter Kit + External Ethernet Pictail Controller ENCX24J600 + I/O Expansion Board(with 168 pin to 132 pin Starter Kit Adapter board) | Demonstrates the TCP Server on development board with PIC32MZ2048EFH144 device and external Ethernet controller ENCX24J600. This is a bare-metal (non-RTOS) implementation |
pic32mz_ef_sk_freertos.X | PIC32MZ2048EFH144 | PIC32MZ EF Starter Kit | Demonstrates the TCP Server on development board with PIC32MZ2048EFH144 device and LAN8740 PHY daughter board. This implementation is based on FreeRTOS. |
Running Demonstration Steps
Build and download the demonstration project on the target board.
If the board has a UART connection:
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 :
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.
LAN8740 PHY daughter board
External ENC28J60 ethernet daughter board
External ENCX24J600 ethernet daughter board
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 demonstration running on the board will echo back everything it receives along the connection.