Monday, July 19, 2010

Building the TCP/IP Demo for the PICNet1

Update 5/23/18:
I published this article several years ago. No doubt many of the links and references are now outdated. Just keeping it here to preserve the history of some blog entries. 

This article will show how to build the PICNet1 demo application firmware based on the Microchip TCP/IP Stack (v5.25).

The PICNet1 PIC18 Development Board lets you populate the U1 (40-pin) or U2 (28-pin) microcontroller sockets with various PIC18F devices, such as PIC18F2620 or PIC18F4685. Also on the U3 socket you can install different serial EEPROM such as the Microchip 25LC256 or 25LC1024 or any equivalent including FLASH memories that have the same pin out. The Ethernet controller on board is always a Microchip ENC28J60.

Given that the Microchip Software License Agreement does not allow the redistribution of the TCP/IP Stack source code, you MUST obtain your own copy directly from Microchip and accept the terms of the applicable License Agreement.

There are some specific files from the Microchip TCP/IP Stack source code that need to be customized for this particular hardware configuration and application. I arrived to an agreement with Microchip where I can distribute the modified files in a separate directory leaving the original files untouched in their original directories. Those files that are a modified or customized version of the original files from the Microchip TCP/IP Stack distribution will include the following legend and a brief explanation about what has been modified from the original version.

This module is part of the original distribution of the Microchip TCP/IP Stack, and this modified local copy is included only to let you build a binary image for this specific hardware. To be able to create the binary image you MUST download the Microchip TCP/IP Stack directly from Microchip's website and accept the terms of the applicable License Agreement. By using this file you implicitly accept the terms of Microchip's License Agreement which by no means gives you the right to redistribute this particular file in its source code form. For additional information refer to the Microchip License Agreement and if you have any questions please write to Microchip Technology Inc., 2355 W. Chandler Blvd., Chandler, AZ 85224-6199 USA. ATTN: Marketing.

Then before we start, here is the list of items you will need to be able to build the demo application firmware:

Directory Structure and files

The Microchip Applications Library gets normally installed in the directory named "Microchip Solutions", under this directory you will find many subdirectories that include the source code for different application library modules and demos.

The tree structure below, only shows the directories related to the TCP/IP Stack and its generic Demo Application.

 Microchip Solutions    Applications Library install directory
 +- Microchip           Main directory for Microchip Libraries source code
 |  |
 |  +-- Help            Help files for Library modules and demos
 |  +-- Include         General include headers files
 |  |   +-- TCIP Stack  Header files for TCP/IP Stack
 |  |
 |  +-- TCP IP Stack    TCP/IP Stack source code
 +- TCPIP Demo App      Generic TCP/IP Stack Demo application source
                        code, configuration and project files

The structure below shows the directory tree of the files distributed by LJCV to build the binary image for the Demo Application for PICNet1 board.

+- PN1_Demo-vX.Y        PICNet1 Demo application main directory with
    |                   MPLAB project files
    +-- bin             Output directory for binary images
    +-- include         Demo application header and configuration files
    +-- obj             Temporary directory for objects
    +-- src             Demo application source code
        +-- TCIP Stack  Microchip TCP/IP modified modules source code

Here is the list and description of each of the files on each directory:

- Directory PN1_Demo-v2.0 (current version)
  - PICNET1.mcp         MPLAB IDE Project file to build image for PICNet1
  - MPFSImg2.bin        MPFS Image for HTTP v2 server demo pages
  - README.TXT          This file

- Directory bin         Precompiled firmware images (Intel hex format)
   - PICNET1_2620.hex   Demo firmware compiled for PIC18F2620 (*)
   - PICNET1_2680.hex   Demo firmware compiled for PIC18F2680 (*)
   - PICNET1_2682.hex   Demo firmware compiled for PIC18F2682
   - PICNET1_2685.hex   Demo firmware compiled for PIC18F2685
   - PICNET1_4620.hex   Demo firmware compiled for PIC18F4620 (*)
   - PICNET1_4680.hex   Demo firmware compiled for PIC18F4680 (*)
   - PICNET1_4682.hex   Demo firmware compiled for PIC18F4682
   - PICNET1_4685.hex   Demo firmware compiled for PIC18F4685

   (*) Given the program memory required for the Microchip TCP/IP Stack
       demo, these images have been compiled with all optimziations enabled

   All images have been compiled with support for a 25LC256 serial EEPROM.

- Directory include
  - picnet1.h           Hardware configuration definitions for PICNet1
  - HardwareProfile.h   Hardware configuration general definitions
  - HTTPPrint.h         Callback headers for custom HTTP application functions
  - main.h              Global definitions and variables
  - mib.h               Original headers for custom SNMP application
  - misc.h              Header file for miscelaneous support functions
  - TCPIPConfig.h       Customized TCP/IP Stack configuration headers

 - Directory src
   - CustomHTTPApp.c    Customized source code for the HTTP v2 server demo
   - main.c             Source code for the main demo application
   - misc.c             Source code for miscelaneous support functions

Building the demo application

Once you have the Microchip Application Libraries and the development tools properly installed you can add the directories and files needed to build the PICNet1 Demo Application Firmware.

The project file PICNET1.mcp includes the required files on the project file lists.

Given that on the project files and options references to include headers and TCP/IP library modules are done using the "..\Microchip\xyz" path, the PN1_Demo-vX.Y must be copied to the same directory level as the "TCPIP Demo App" directory, under the "Microchip Solutions" directory or whatever directory was used to install the Microchip Application Libraries.

Once you have copied the files to the proper directory, on MPLAB IDE you must open the PICNET1.mcp project file, on the top menu bar select to build the "Release" version of the code, and select the proper target device that is installed on the PICNet1 MCU U1 or U2 sockets.

Take in account that because of the increase in size of the latest versions of the Microchip TCP/IP library, to be able to compile a version of code that includes the latest HTTP 2 server module, you will most probably need to enable the compiler optimizations to generate a binary image that fits on the PIC18F2620/4620 program memory.

Also double check that you are using "overlay" storage class and large code and data models (Project->Build Options->MPLAB C18), and that MPLAB IDE on the Directories tab the Library Search Path is set to the correct directory where the c018 libraries are located.

Be aware that not all the modules included with the original TCP/IP Stack Demo Application has been tested or compiled for the PICNet1 Board, some of these modules may require additional customization to work on this board.

After compiling and programming the binary image on the target device, if you connected a terminal or computer running a terminal emulator to the RS-232 interface (default configuration is 19200bps, N, 8, 1), after RESET you should see a series of informational messages like these:

PICNET1 Hardware Initialized, HW Config Ver.1.0, MCU = PIC18F4620
MPFS Initialized, Ver.2.1
PICNET1 Config loaded
Microchip TCP/IP Stack Ver.v5.25
MAC Address = 00:04:A3:00:00:20, IP Address =
PICNET1 Ready, FW Ver.2.0, Built Jul 19 2010-09:11:22
New IP Address =
New IP Address =

For additional information and documentation about the Microchip TCP/IP Stack refer to the Help file included in the Microchip Applications Libraries distribution, and for latest information and up to date instructions  about how to build the demo firmware for the PICNEt1 board visit the product page at

Happy Networking

1 comment:

ben said...

I'd like to use the older (Version 2) of the Microchip TCP/IP stack but haven't had much luck finding it!

It's also whats used in Microchip's documentation (AN833), and has supports for SLIP and RTL8019AS in Websrvr.c.

Does the new stack (v5.20) in the latest Microchip Application Library Installer (v2009-11-18) support the older boards/hardware?

Has the build process changed very much?