Microchip TCPIP - Page 1
Forum section: electronics / general

author: Christopher
author_rank: Frequent Contributor
timestamp: December 23, 2013, 12:03:27 am
content: I've got a simple stripboard setup with an ENC28j60 and a PIC32MX130F064B (All I had) which is all working OK so far.Trying to compile the demo stack downloaded from MCP, I've literally got none of the features selected, a custom Main file, and with the HTTP Server example enabled it used 70k of flash!The MCP site says it uses 10k max.. Is this normal or can I make it any smaller..I've got no room left for my program!

author: Psi
author_rank: Super Contributor
timestamp: December 23, 2013, 12:10:43 am
content: I've never used that chip/IDE/toolchain but just from what your saying i'm wondering if selecting/unselecting "features" may not be the same as removing them from the project.Also check your compile options, maybe the compiler isn't doing any optimisations

author: Christopher
author_rank: Frequent Contributor
timestamp: December 23, 2013, 12:20:46 am
content: Ive tried various optimisation levels on the compiler.Selecting demo features is done by commenting out defines ~ so all of the crap i dont want is presumably taken out at compike time. I wonder if theres any webpages stored in flash ?Normally id just say chuff it and get another pic with 4x the flash but im stuck with getting a prototype ready over christmas with the bits i have on hand.....

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 23, 2013, 12:22:06 am
content: I think you need to specify a compiler option to make it not to link in procedures that aren't used.And yes, that is totally brain-dead behaviour, especially when they provide loads of general-purpose libraries which nobody is going to use every part of.I really wish Microchip would get their compilers up the standard of the likes of IAR.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 23, 2013, 12:23:26 am
content: Take a look through the .map file to see where the memory is going - could well be that an HTTP demo has an image embedded in there somewhere

author: nctnico
author_rank: Super Contributor
timestamp: December 23, 2013, 03:00:41 am
content: Maybe the optimisation isn't on (optimisation may be crippled so look for generic GCC MIPS compiler with full optimisation) or like Mike said: check the mapfile.

author: JTR
author_rank: Regular Contributor
timestamp: December 23, 2013, 04:36:04 am
content: Quote from: Christopher on December 23, 2013, 12:03:27 am10K for a TCP/IP stack in a PIC32? Dream on... If that was 10K machine instructions and not bytes well maybe...

author: andersm
author_rank: Super Contributor
timestamp: December 23, 2013, 08:04:26 am
content: In the compiler options, enable "Isolate each function in a section" and "Generate 16-bit code". Also set the optimization level to 1, or s if your license allows it. In the linker options, enable "Remove unused sections" and "Generate 16-bit code".

author: RoadRunner
author_rank: Frequent Contributor
timestamp: December 23, 2013, 08:54:02 am
content: Quote from: mikeselectricstuff on December 23, 2013, 12:23:26 amas mike said.i believe the demo is storing webpages at the flash itself. and the microchip site will only give you size for the stack not for webpages.

author: matkar
author_rank: Regular Contributor
timestamp: December 24, 2013, 07:27:17 pm
content: As far as I remember I was able to strip the compiled stack to around 10k with UDP communication only and a static IP. I used PIC18F87K22. As soon as you start adding TCP/IP, DHCP, HTTP... the numbers jump up quickly. Try it yourself by defining/undefining options. Beware that defining some options automatically defines other options as well.I have just reopened the stack in MPLab. Here is an exaple of configuration settings from TCPIP ENC28.h file:Code:// =======================================================================// Application Options// =======================================================================/* Application Level Module Selection* Uncomment or comment the following lines to enable or* disabled the following high-level application modules.*/#define STACK_USE_UART// Application demo using UART for IP address display and stack configuration//#define STACK_USE_UART2TCP_BRIDGE// UART to TCP Bridge application example//#define STACK_USE_IP_GLEANING#define STACK_USE_ICMP_SERVER// Ping query and response capability//#define STACK_USE_ICMP_CLIENT// Ping transmission capability//#define STACK_USE_HTTP2_SERVER// New HTTP server with POST, Cookies, Authentication, etc.//#define STACK_USE_SSL_SERVER// SSL server socket support (Requires SW300052)//#define STACK_USE_SSL_CLIENT// SSL client socket support (Requires SW300052)//#define STACK_USE_AUTO_IP // Dynamic link-layer IP address automatic configuration protocol//#define STACK_USE_DHCP_CLIENT// Dynamic Host Configuration Protocol client for obtaining IP address and other parameters#define STACK_USE_DHCP_SERVER// Single host DHCP server//#define STACK_USE_FTP_SERVER// File Transfer Protocol (old)//#define STACK_USE_SMTP_CLIENT// Simple Mail Transfer Protocol for sending email//#define STACK_USE_SNMP_SERVER// Simple Network Management Protocol v2C Community Agent//#define STACK_USE_SNMPV3_SERVER// Simple Network Management Protocol v3 Agent//#define STACK_USE_TFTP_CLIENT// Trivial File Transfer Protocol client//#define STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE// HTTP Client example in GenericTCPClient.c//#define STACK_USE_GENERIC_TCP_SERVER_EXAMPLE// ToUpper server example in GenericTCPServer.c//#define STACK_USE_TELNET_SERVER// Telnet server//#define STACK_USE_ANNOUNCE// Microchip Embedded Ethernet Device Discoverer server/client//#define STACK_USE_DNS// Domain Name Service Client for resolving hostname strings to IP addresses//#define STACK_USE_DNS_SERVER// Domain Name Service Server for redirection to the local device//#define STACK_USE_NBNS// NetBIOS Name Service Server for repsonding to NBNS hostname broadcast queries//#define STACK_USE_REBOOT_SERVER// Module for resetting this PIC remotely. Primarily useful for a Bootloader.//#define STACK_USE_SNTP_CLIENT// Simple Network Time Protocol for obtaining current date/time from Internet#define STACK_USE_UDP_PERFORMANCE_TEST// Module for testing UDP TX performance characteristics. NOTE: Enabling this will cause a huge amount of UDP broadcast packets to flood your network on the discard port. Use care when enabling this on production networks, especially with VPNs (could tunnel broadcast traffic across a limited bandwidth connection).//#define STACK_USE_TCP_PERFORMANCE_TEST// Module for testing TCP TX performance characteristics//#define STACK_USE_DYNAMICDNS_CLIENT// Dynamic DNS client updater module//#define STACK_USE_BERKELEY_API// Berekely Sockets APIs are available//#define STACK_USE_ZEROCONF_LINK_LOCAL// Zeroconf IPv4 Link-Local Addressing//#define STACK_USE_ZEROCONF_MDNS_SD// Zeroconf mDNS and mDNS service discovery// =======================================================================// Data Storage Options// =======================================================================/* MPFS Configuration* MPFS is automatically included when required for other* applications. If your custom application requires it* otherwise, uncomment the appropriate selection.*///#define STACK_USE_MPFS2/* MPFS Storage Location* If html pages are stored in internal program memory,* comment both MPFS_USE_EEPROM and MPFS_USE_SPI_FLASH, then* include an MPFS image (.c or .s file) in the project.* If html pages are stored in external memory, uncomment the* appropriate definition.** Supported serial flash parts include the SST25VFxxxB series.*///#define MPFS_USE_EEPROM//#define MPFS_USE_SPI_FLASH/* EEPROM Addressing Selection* If using the 1Mbit EEPROM, uncomment this line*///#define USE_EEPROM_25LC1024/* EEPROM Reserved Area* Number of EEPROM bytes to be reserved before MPFS storage starts.* These bytes host application configurations such as IP Address,* MAC Address, and any other required variables.** For MPFS Classic, this setting must match the Reserved setting*on the Advanced Settings page of the MPFS2 Utility.*/#define MPFS_RESERVE_BLOCK(137ul)/* MPFS File Handles* Maximum number of simultaneously open MPFS2 files.* For MPFS Classic, this has no effect.*/#define MAX_MPFS_HANDLES(7ul)With this configuration it compiles to 9897 words.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 24, 2013, 09:19:04 pm
content: ..of course if the compiler omitted unused code by default, you wouldn't need most of these configuration options - it would just only include stuff that gets called.

author: JTR
author_rank: Regular Contributor
timestamp: December 25, 2013, 01:11:03 pm
content: Quote from: matkar on December 24, 2013, 07:27:17 pmPIC18 != PIC32. The comparison is pointless.

author: matkar
author_rank: Regular Contributor
timestamp: December 25, 2013, 05:17:15 pm
content: Quote from: JTR on December 25, 2013, 01:11:03 pmFair enough.Now to be more fair I've tested space savings with two different options on a PIC32 uC as well. Here is my first configuration file:Code:// =======================================================================// Application Options// =======================================================================/* Application Level Module Selection* Uncomment or comment the following lines to enable or* disabled the following high-level application modules.*///#define STACK_USE_UART // Application demo using UART for IP address display and stack configuration//#define STACK_USE_UART2TCP_BRIDGE // UART to TCP Bridge application example//#define STACK_USE_IP_GLEANING#define STACK_USE_ICMP_SERVER // Ping query and response capability#define STACK_USE_ICMP_CLIENT // Ping transmission capability#define STACK_USE_HTTP2_SERVER // New HTTP server with POST, Cookies, Authentication, etc.//#define STACK_USE_SSL_SERVER // SSL server socket support (Requires SW300052)//#define STACK_USE_SSL_CLIENT // SSL client socket support (Requires SW300052)#define STACK_USE_AUTO_IP // Dynamic link-layer IP address automatic configuration protocol#define STACK_USE_DHCP_CLIENT // Dynamic Host Configuration Protocol client for obtaining IP address and other parameters#define STACK_USE_DHCP_SERVER // Single host DHCP server//#define STACK_USE_FTP_SERVER // File Transfer Protocol (old)#define STACK_USE_SMTP_CLIENT // Simple Mail Transfer Protocol for sending email//#define STACK_USE_SNMP_SERVER // Simple Network Management Protocol v2C Community Agent//#define STACK_USE_SNMPV3_SERVER // Simple Network Management Protocol v3 Agent//#define STACK_USE_TFTP_CLIENT // Trivial File Transfer Protocol client#define STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE // HTTP Client example in GenericTCPClient.c#define STACK_USE_GENERIC_TCP_SERVER_EXAMPLE // ToUpper server example in GenericTCPServer.c#define STACK_USE_TELNET_SERVER // Telnet server#define STACK_USE_ANNOUNCE // Microchip Embedded Ethernet Device Discoverer server/client#define STACK_USE_DNS // Domain Name Service Client for resolving hostname strings to IP addresses//#define STACK_USE_DNS_SERVER // Domain Name Service Server for redirection to the local device#define STACK_USE_NBNS // NetBIOS Name Service Server for repsonding to NBNS hostname broadcast queries#define STACK_USE_REBOOT_SERVER // Module for resetting this PIC remotely. Primarily useful for a Bootloader.#define STACK_USE_SNTP_CLIENT // Simple Network Time Protocol for obtaining current date/time from Internet//#define STACK_USE_UDP_PERFORMANCE_TEST // Module for testing UDP TX performance characteristics. NOTE: Enabling this will cause a huge amount of UDP broadcast packets to flood your network on the discard port. Use care when enabling this on production networks, especially with VPNs (could tunnel broadcast traffic across a limited bandwidth connection).#define STACK_USE_TCP_PERFORMANCE_TEST // Module for testing TCP TX performance characteristics//#define STACK_USE_DYNAMICDNS_CLIENT // Dynamic DNS client updater module#define STACK_USE_BERKELEY_API // Berekely Sockets APIs are available//#define STACK_USE_ZEROCONF_LINK_LOCAL // Zeroconf IPv4 Link-Local Addressing//#define STACK_USE_ZEROCONF_MDNS_SD // Zeroconf mDNS and mDNS service discoveryCompile size was 45853 words.I've changed the config file (which is almost identical to my config file for PIC18 uC in my previous reply) to:Code:// =======================================================================// Application Options// =======================================================================/* Application Level Module Selection* Uncomment or comment the following lines to enable or* disabled the following high-level application modules.*///#define STACK_USE_UART // Application demo using UART for IP address display and stack configuration//#define STACK_USE_UART2TCP_BRIDGE // UART to TCP Bridge application example//#define STACK_USE_IP_GLEANING#define STACK_USE_ICMP_SERVER // Ping query and response capability//#define STACK_USE_ICMP_CLIENT // Ping transmission capability//#define STACK_USE_HTTP2_SERVER // New HTTP server with POST, Cookies, Authentication, etc.//#define STACK_USE_SSL_SERVER // SSL server socket support (Requires SW300052)//#define STACK_USE_SSL_CLIENT // SSL client socket support (Requires SW300052)//#define STACK_USE_AUTO_IP // Dynamic link-layer IP address automatic configuration protocol//#define STACK_USE_DHCP_CLIENT // Dynamic Host Configuration Protocol client for obtaining IP address and other parameters#define STACK_USE_DHCP_SERVER // Single host DHCP server//#define STACK_USE_FTP_SERVER // File Transfer Protocol (old)//#define STACK_USE_SMTP_CLIENT // Simple Mail Transfer Protocol for sending email//#define STACK_USE_SNMP_SERVER // Simple Network Management Protocol v2C Community Agent//#define STACK_USE_SNMPV3_SERVER // Simple Network Management Protocol v3 Agent//#define STACK_USE_TFTP_CLIENT // Trivial File Transfer Protocol client//#define STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE // HTTP Client example in GenericTCPClient.c//#define STACK_USE_GENERIC_TCP_SERVER_EXAMPLE // ToUpper server example in GenericTCPServer.c//#define STACK_USE_TELNET_SERVER // Telnet server//#define STACK_USE_ANNOUNCE // Microchip Embedded Ethernet Device Discoverer server/client//#define STACK_USE_DNS // Domain Name Service Client for resolving hostname strings to IP addresses//#define STACK_USE_DNS_SERVER // Domain Name Service Server for redirection to the local device//#define STACK_USE_NBNS // NetBIOS Name Service Server for repsonding to NBNS hostname broadcast queries//#define STACK_USE_REBOOT_SERVER // Module for resetting this PIC remotely. Primarily useful for a Bootloader.//#define STACK_USE_SNTP_CLIENT // Simple Network Time Protocol for obtaining current date/time from Internet#define STACK_USE_UDP_PERFORMANCE_TEST // Module for testing UDP TX performance characteristics. NOTE: Enabling this will cause a huge amount of UDP broadcast packets to flood your network on the discard port. Use care when enabling this on production networks, especially with VPNs (could tunnel broadcast traffic across a limited bandwidth connection).//#define STACK_USE_TCP_PERFORMANCE_TEST // Module for testing TCP TX performance characteristics//#define STACK_USE_DYNAMICDNS_CLIENT // Dynamic DNS client updater module//#define STACK_USE_BERKELEY_API // Berekely Sockets APIs are available//#define STACK_USE_ZEROCONF_LINK_LOCAL // Zeroconf IPv4 Link-Local Addressing//#define STACK_USE_ZEROCONF_MDNS_SD // Zeroconf mDNS and mDNS service discoveryand compile size dropped to 7801 words.I want to point out that substantial space savings can be achieved by carefully selecting only modules you really need in your project.

author: JTR
author_rank: Regular Contributor
timestamp: December 26, 2013, 02:39:13 am
content: Quote from: matkar on December 25, 2013, 05:17:15 pmThat seems reasonable. 7801 words = 31204 bytes.What would be really interesting is seeing the same done for the PIC24. Somehow I think it will use about half of what the PIC32 did.

author: SirDan
author_rank: Contributor
timestamp: December 30, 2013, 12:48:17 am
content: Quote from: JTR on December 26, 2013, 02:39:13 amJust to clarify. 7801 words = 15602 bytes because a word = 2 bytes. 7801 dwords = 31204 bytes because a dword = 4 bytes.

author: nctnico
author_rank: Super Contributor
timestamp: December 30, 2013, 01:28:50 am
content: Quote from: mikeselectricstuff on December 24, 2013, 09:19:04 pmThat could get messy with interrupt handlers, functions which are getting called through tables with function pointers or are mapped into a section with a fixed address.

author: JTR
author_rank: Regular Contributor
timestamp: December 30, 2013, 05:29:20 am
content: Quote from: SirDan on December 30, 2013, 12:48:17 amAn instruction word on a PIC32 is 4 bytes. Please anyone, feel free to post a working TCP/IP stack for the PIC32 written in C that fits in 15k bytes.

author: nctnico
author_rank: Super Contributor
timestamp: December 30, 2013, 11:22:22 am
content: Quote from: JTR on December 30, 2013, 05:29:20 amLook for uIP. AFAIK PIC32 also has a 16 bit instruction set just like ARM's thumb. I managed to get a TCP/IP stack (uip), BSD socket layer interface, http client, http server, DHCP, DNS a proprietary protocol and some meaningful software into 32kB of flash on ARM. I probably could make it smaller (the BSD socket interface was about as big as uIP) but I liked the convenience of the BSD socket layer to be able to re-use exisiting software and develop parts the software on a PC first.

author: JTR
author_rank: Regular Contributor
timestamp: December 30, 2013, 01:48:17 pm
content: Quote from: nctnico on December 30, 2013, 11:22:22 amI am well aware of the MIP16e instruction set on the PIC32. I have written a USB stack and bootloader that fits into the 3K bootblock with room (maybe) for a debugger as well. Prior to that I tried with 32-bit assembler and also with C using the MIP16e option. I think I have a good understanding of what a memory hog the PIC32 can be. It is a pig when the most common data unit is a byte as it is for TCP/IP and USB.While I have not written code for the ARM my understanding is that PIC32 != ARM when it comes to code size.If anyone really has a real world TCP/IP stack for the PIC32 that fits within 15kB I sure would like to see it.(BTW, Not saying that it cannot be done just I seriously doubt that it has been done. There are very few "suckers" like me who get right down to the bare metal and scrooge over every instruction. The tool set just is not friendly for that sort of nth degree coding...)

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 30, 2013, 03:50:40 pm
content: On the subject of code size, does anyone have a feel for how much better the paid version of Microchip C32 is compared to the free version?I've done a few PIC32 projects with the free one, which although not using much code, have been fairly speed-sensitive, and not found speed to be a major problem. If anything, limitations in the PIC32MX1xx hardware have been worse, like not implementing shadow registers and poor UART FIFO implementation.

author: nctnico
author_rank: Super Contributor
timestamp: December 30, 2013, 04:00:24 pm
content: This thread on Microchip's website pretty much answers that:http://www.microchip.com/forums/m481688.aspx

author: Rufus
author_rank: Super Contributor
timestamp: December 30, 2013, 04:20:21 pm
content: Quote from: mikeselectricstuff on December 30, 2013, 03:50:40 pmCan't you install with the 60 day trial to find out? Maybe on a virtual machine, dunno if the activation/licensing scheme cares about that.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: December 30, 2013, 04:34:03 pm
content: Quote from: Rufus on December 30, 2013, 04:20:21 pmI could - just wondered if anyone else already had

author: Rufus
author_rank: Super Contributor
timestamp: December 30, 2013, 05:20:44 pm
content: Quote from: mikeselectricstuff on December 30, 2013, 04:34:03 pmThe results on your code would be more useful to you.The differences from a PIC24 project built with XC1.20 with -Os and -O1 optimization levelsCode:-Ossection address length (PC units) length (bytes) (dec)------- ------- ----------------- --------------------.text 0x200 0x1878 0x24b4 (9396).text 0x3958 0x16fc 0x227a (8826)-O1section address length (PC units) length (bytes) (dec)------- ------- ----------------- --------------------.text 0x200 0x1b0a 0x288f (10383).text 0x3bea 0x1892 0x24db (9435)

author: andersm
author_rank: Super Contributor
timestamp: December 30, 2013, 09:19:35 pm
content: Quote from: JTR on December 30, 2013, 01:48:17 pmMIPS32 is comparable in size to "full" ARM, but the newer Cortex-M cores use a more compact 16/32-bit instruction encoding called Thumb-2, which in my tests produces maybe 30% smaller binaries. The new Microchip PIC32MZ MCUs use a similar compact instruction encoding called microMIPS, which produces similarly-sized binaries as Thumb-2.