Web platform firmware
In this article we introduce the bootloader firmware, do a simple network function test and exercise a small HTTP server that controls I/O pins and accepts new web page uploads through a web browser.
We ported the open source ds30 Loader bootloader to the web platform so it can be programmed through the USB connection; no PIC programmer required. The ds30 Loader project has serial bootloader firmware for most PICs, and bootloader software for most computer operating systems. The bootloader is programmed into the chip once with a PIC programmer like an ICD or PICKIT, then future updates can be done over the USB port.
The bootloader resides in the uppermost page of the PIC program memory. It activates immediately after power on and waits for a commands entering the UART connected to the FTDI USB->serial converter. The bootloader passes control to the main firmware if it doesn’t detect an update request after three seconds.
To use the bootloader:
- Power up the web platform.
- Attach a USB cable from a computer to the web platform.
- Start the bootloader client software.
- Configure the bootloader to communicate with a PIC 33FJ128GP204 at 115200bps on the appropriate serial port for your system. See the image above.
- Press the reset button on the web platform. Next, click download on the bootloader software within 3.5seconds. Always follow this order or the bootloader may be damaged. The new firmware will be loaded into the PIC.
- The bootloader will automatically pass control to the main program when the upload completes.
If the client warns you that the bootloader will be overwritten, ALWAYS CANCEL. If the bootloader is overwritten you’ll need to program it into the chip again with a PIC programmer.
The compiled firmware end address is 0×153fe. The bootloader resides in the page starting at 0×15400, and the client will refuse to upload new firmware that overwrites the bootloader.
Network test and HTTP server
Our first firmware example is a simple network function test with an HTTP server. This demonstration verifies that the network, EEPROM, and USB->serial connection are functioning correctly.
Microchip’s ‘free’ TCP/IP stack provides all the network functions we need to exist on an ethernet network and work with internet resources. The stack is open source and free-as-in-beer, but the Microchip license prohibits distribution. Due to licensing issues, we compiled firmware and our original source code in the project Github SVN. If you want to compile the firmware yourself, you’ll need to download the Microchip TCP/IP stack and follow the instructions in the source files.
A compiled version of the network function test is included in the project archive. Program it into the PIC via the bootload procedure described above.
Note: The HEX file in the project archive causes the web platform to lockup, so you will need to re-compile from source after making one of the following changes in the Microchip TCP/IP stack source file
- change the statement
ENC_SPICON1bits.CKE = 1;to
ENC_SPICON1bits.CKE = 0;or
- add the statement
ENC_SPICON1bits.SMP = 1;after the
ENC_SPICON1bits.MSTEN = 1;statement; or
- add a delay using 9 Nop()s in the WriteReg() function after the statement
Dummy = ENC_SSPBUF;to ensure the required CS hold time of 210ns is met (per page 82 of ENC28J60 Rev C datasheet). This is possibly the more 'correct' fix.
If you just want a working HEX file, ask in the Web Platform forum.
DHCP and IP announce
The demo includes a Dynamic Host Configuration Protocol client that automatically configures the network settings using the DHCP server on your local network. The vast majority of networks and routers support DHCP.
When an IP address is acquired by DHCP, the web platform announces it in a broadcast packet to all computers on the local network. Microchip provides a small Windows utility called MCHPDetect that displays these packets, source code is available in the TCP/IP stack download.
Ping the web platform at the IP address shown in the broadcast packet to check if the web platform is alive on your network. The dsPiC is really fast, it has sub-millisecond response times on our network.
Any character received through the FTDI USB->serial connection is echoed back. Use a serial terminal to verify that the UART and FTDI232R function correctly. The USB LED should blink.
EEPROM-based web server
The demo includes Microchip’s HTTP web server with “out of the box” ability to read and control pins on the IO header from a web page. Web pages are uploaded with a web browser and stored in the EEPROM.
Open the server’s IP address with a web browser. If there’s no existing pages in the EEPROM, you’ll be redirected to the website upload page (http://192.168.1.129/mpfsupload, for example). Upload the demo website from the Microchip TCP/IP stack (
Microchip Solutions\TCPIP Demo APP\MPFSIMG2.bin). We’ve included our own, much simpler demo if the Microchip image isn’t available.
/mpfsupload again at any time to upload a new website image.
After the image is uploaded, navigate to the base web address (http://192.168.1.129/) and view the demo page. You may need to control-refresh to clear your browser’s cache.
Microchip’s demo page is a super easy way to control outputs and read digital sensors from a web browser. The demo site uses AJAX to control LEDs and the I/O header pins. We mapped the LEDs to LD1, LD2 (IO1), and IO2-4 on the web platform I/O header. The buttons are mapped to I/O header pins 5-8.