Web platform: SD card web server demo

Posted on Wednesday, December 16th, 2009 in web platforms by Ian

This is an old version, see the latest version on the documentation wiki.

The goal of this demo is to serve files to a web browser from a microSD card using the web platform hardware. Microchip’s latest TCPIP stack demonstration includes an HTTP server that reads files from FAT formatted SD cards, so there’s no need to write our own. A compiled version, ported to the web platform, is included in the project archive that accompanies this article.

The Web Platform is available as a kit for $35, including worldwide shipping. Seeed Studio will assemble yours for $5 more.

A demonstration of the SD card web server firmware follows the break.

Load the demo

A compiled version of the SD card server demo is included in the project archive and the project SVN as a .HEX file. The .HEX file can be flashed to the PIC chip with the ds30 Loader bootloader, or it can be burned directly with a PIC programmer. See the original web platform article for detailed bootloader instructions.

Fat format

The server is compatible with FAT 12/16/32 formatted microSD cards. It’s crucial that your SD card be formatted correctly. FAT is a very common file system used by computers, digital cameras, and MP3 players, but operating systems don’t always apply correct FAT formatting to SD cards. Windows, for example, formats SD cards with a non-standard arrangement of file tables.

We use the freeware SDFormatter V2.0.0.3 utility to format cards correctly in Windows. A digital camera’s SD card format function will usually write the correct file table types too.

Using it

Use a PC to copy some files to a microSD card. All the files will be available from the server. The project download includes a simple website you can use. Put the card into the holder on the web platform before turning on the power.

Apply power to the web platform. The server will announce its IP address at startup. Run Microchip’s MCHPDetect utility or a packet sniffer to grab the address.

The demo firmware includes an ICMP (ping) server. Ping it from the command line to verify that the server is alive and responding.

Now it’s time for the good stuff. Open a web browser and enter the server’s IP as the web address (, for example). If no file is specified with the address, the server looks for index.htm in the root directory of the SD card. If you used the included demo site, you should see something like the image above. Click the links to test image and file transfers.

How fast will it go? We copied a 1.4MB file to the SD card, then downloaded it from the server with Firefox. The maximum download speed was 77KB/sec, and it took a total of 17 seconds to complete the transfer. We ran a parity check against a PAR2 set to verify that the file arrived intact.

Dynamic variables

Microchip’s v2 HTTP server can display the status of pins, and control pins from web pages. Dynamic pages must first be processed with a utility that locates the variables and generates a helper index for the microcontroller. See .\Microchip Solutions\Microchip\Help\ in the Microchip TCPIP stack source for an overview of the dynamic variable utilities.

We tested the dynamic site demo included with the TCPIP stack, but the dynamic features didn’t work. This is an area for improvement, but if the fix requires alterations to one of Microchip’s files, the changes can’t be distributed. This leads us to…

An open source TCPIP stack

An open source TCPIP stack is desperately needed so we have a consistent, redistributable code base to work from. One of the long term goals of this project is to cobble together a generic microcontroller TCPIP stack that will be useful for a lot of embedded platforms.

We found some existing open source TCPIP implementations, all would have to be extensively modified to approach the functionality of the Microchip stack. Tux Graphics has a simple stack for their ATMEGA web server kit. Nuelectronics has a very basic HTTP packet generator for their ENC28J60 Arduino shield.

lwip is a BSD licensed TCPIP stack for “embedded systems with tens of kilobytes of free RAM and room for around 40 kilobytes of code ROM.”  The web platform has plenty of ROM program space, but only 8K of RAM. This is probably the most promising code base we’ve found, assuming the memory requirements can be reduced.

If you know of any other open source TCPIP implementations please share them in the comments.

Compiling the demo

Due to licensing issues, we can’t redistribute the Microchip Applications Libraries source (TCPIP stack, etc).  To compile the firmware yourself, first download and install the Microchip source, then copy our open source replacement files into the Microchip SD card server directory (usually .\Microchip Solutions\TCPIP MDD Demo App\). That’s it. You’ve got the latest source, and we’re compliant with the license. See the instructions in Maindemo.c for more details.

Not all microSD cards are created equal. And they die.

This post was originally scheduled for yesterday, but a pre-publish test of the firmware failed. Firmware that had worked flawlessly a day prior now reset constantly and died during pings. Single stepping with a debugger proved impossible because the PIC crashed randomly.

Eventually, after several hours of rechecking schematics, datasheets, and code, we tried a different microSD card. The server immediately roared to life. The ancient SD card we use for testing, predating even the web server on a business card, failed. It still appears to work in a PC, but it causes problems with the web platform circuit. SD cards purchased in the last year all seem to work fine.

Is there a lesson? When debugging, check everything once, even the unlikely stuff. If you have problems with the SD server demo, try a different SD card.

This entry was posted on Wednesday, December 16th, 2009 at 10:16 am and is filed under web platforms. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

9 Responses to “Web platform: SD card web server demo”

  1. Shadyman says:

    Hmm… The dsPIC33FJ128GP804 has 16kb of memory… It looks to be a drop-in replacement.

  2. Andreas says:

    one other network stack to check out, uip:

    seems lightweight and well documented. Some references to pic already made on the “ports” page, so you may be lucky when it comes to implementing on the web platform.

  3. CHOPPERGIRL says:

    So is there one of these running, serving webpages, that we can access from the web?

    How robust is the webserver code running on it? I’m assuming, not very at all, probably only able to return requested files. In other words, Server Side Include script processing is out of the question… :-( All my websites are made dynamic using primitive SSI directives.

  4. Ian says:

    @choppergirl – There was one running a twitter controlled christmas tree with live streaming video, but it’s down now that Christmas is over.

    The microchip stack has provisions for dynamic variables, and the stack can handle lots of users depending on the amount of memory dedicated to HTTP sockets. It’s not intended to replace an actual server though, it’s for embedded applications where a web interface is handy (like a router’s configuration pages).

  5. EGHM says:

    It appears that SDHC is supported, I tested mine with a 4G SDHC with no problems.

  6. Markus Gritsch says:

    Ian, did you also copy the files ‘DynRcrd.bin’ and ‘FileRcrd.bin’ generated by MPFS2 onto the SD card? These files need to be on the card to make the dynamic variables work.

    However, even with these files, the Microchip demo site does not really work on the Web Platform. I attached a screenshot of how it looks here:

    After a few clicks in the browser, the PIC locks up as also described in the above link.

  7. Jorge says:

    Exists any example for the pic32?

  8. Matt says:

    Hey I’m a total n00b at this but I converted an image over to PNG after trying to use a JPG in the SD server demo. Neither worked, is there some limitation or specific image settings that are compatible with the web platform? Awseome stuff by the way! I’m an openbench and webplatform owner! Not like images are a neccesity just curious.



    • Ian says:

      Hi Matt, that shouldn’t be a problem. The server demo project uses a png I believe. If you start a thread in the forum I’ll do my best to help figure it out.

Leave a Reply

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Recent Comments

  • Derek: Is the Sunday one no longer a thing?
  • MG: Hi Ian, that's great news!!! I had a lot of misunderstandings with the factory that made me PCBs. I guess that despite keeping the "dirty"...
  • Doub: Just add sleeving and black variants of these 5557 and you'll take the enthusiast/gamer PC market by storm.
  • Jonathan Eisch: This is great! Coax with RF and lemo-00 connectors would make a huge difference to physicists everywhere. SHV (high voltage) is probably too much to...
  • James Fowkes: This is a brilliant service, I'm sure I'll be using it a lot. An option for spade/FASTON connectors would be amazing!