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.
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 V184.108.40.206 utility to format cards correctly in Windows. A digital camera’s SD card format function will usually write the correct file table types too.
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.
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 (http://192.168.1.135, 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.
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.