|
|
Updating PICNIC Firmware |
■Updating PICNIC Firmware 0. Problems with PIC16F877A version 1. Outline of Update Procedure 2. MPLAB Setup (including MPASM) 3. Assembling MPASM Edition Firmware ←NEW 5. Operational Tests of Firmware after Updates
→Click here if you have some questions and comments. ←Back to the table of contents
Updated April 29, 2005 21:56
|
●Problems with PIC16F877A version (added 2004/4/29)
<Write problems> <Solution> <Conclusion> ●Outline of updating procedureOperation procedure/Environment and necessary materials for updating 4.1.1 Operation procedurePICNIC firmware can be modified and updated using the following operation procedure. (1)Edit MPASM version firmware
(written in assembly language which can be assembled with the MPASM assembler, *.asm)
In many cases, update operations are not small scale like in this exercise and to cut down the work of (3)and(4)above, in an actual "development environment" often an emulation CPU called ICE(In-Circuit Emulator) which works with the development machine is inserted into the target CPU socket and used to check operations. ICE
kits for the PIC microcomputer are available, but very high priced for individual use. 4.1.2 Environment and necessary materials for updating The main environment and materials needed for updating PICNIC firmware are the following. In this work, we will be assuming development on Windows, but it appears that GNU type tools (GNUPIC)for working on Unix also exist. [A] Program editing, MPASM environment ・assembly language file
for the currently operating firmware [B] Writing to the PIC microcomputer(verify PIC16F877-20/P printing on IC surface) ・PIC16F877-20/P(check labelling on IC surface), included
in the peripheral extension options kit ※ the 877A version IC (PIC16F877A-1/P) included
in newly delivered PICNIC kits cannot be written
with the ver.3 writer.
<Picture 1> PIC microcomputer writer ver.3(ROM versions rev.B~D)
<Picture 2> DIP300mil 40pin zero pressure IC socket (TEXTOOL)
●Setup for MPLAB(including MPASM)Where to find MPLAB(IDE)/Procedure from download to installation/MPASM startup check 4.2.1 Where to find MPLAB(IDE) Microchip MPLAB PIC microcomputer integrated development environment (IDE)ver5.x or ver6.x can be downloaded from the links below. Currently, there are releases for Windows only. MPLAB
ver5.70 download (mp57full.zip
localcopy) 4.2.2 Procedure from download to installation(revised April 19, 2004) Below we will explain the procedure using the MPLAB ver5.70 setup as an example. (1)Get MPLAB ver5.70 full setup ZIP file(mp57full.zip : 13MByte). Download the file to C:\TMP, for example. (2)The downloaded setup files have been compressed in ZIP format so use a decompression tool such as WinZIP and extract them to a temporary folder. ※Click here to
download the
ver8.1 evaluation version of WinZIP! The download will begin automatically. By selecting [Open], the setup will also be done automatically. It is a good idea to select Classic view for the menu. (3)If you are using the WinZIP extraction tool, you can right click on the downloaded MPLAB ZIP file(mp57full.zip)icon (right click→WinZip→extract here) to produce the setup executable file (MP57000full.exe)in a temporary folder. (4)Double click the MP57000full.exe file generated in(3)and perform the setup. (5)The first few questions can be answered using the default values provided. When it is time to do "Component select", check only the first two items and the last item. That is, select only
Unselect the checkmarks on the remaining items.※
Selecting the MPLAB setup package (6)At the end of the setup, you will be asked to restart the computer. Be sure none of the other applications have unsaved files left open and restart. (7)When the setup is completed, the MPLAB IDE tools group will be available in [Programs]→[Microchip MPLAB]. (8)If possible, it will be good to have a shortcut icon for MPASM for Windows on the desktop. (You can assemble *.asm files using drag & drop. Convenient!)
※April 19, 2004 revision:The format of
the Microchip site has changed considerably so we have created link
adjustments and a local copy. 4.2.3 MPASM operation checks Let us check the operation of the MPASM PIC microcomputer macro assembler included in the IDE. (Method 1)If you have created a shortcut icon on the desktop as described in 4.2.2 Procedure(5)above, double click it. (Method 2)Select the MPASM for Windows icon from [Start]→[Programs]→[Microchip MPLAB] to run it. Verify that the MPASM startup screen (Fig. 1) appears as shown below.
<Figure 1> MPASM startup screen. ●Assembling MPASM firmwareDownloading MPASM firmware (ver1.2)/Assembling using MPASM/Files created from assembling 4.3.1 Downloading MPASM firmware (ver1.2) ※For an overview of PICNIC firmware(ver1.2), refer to §1.2. Download firmware (v1.2) for PICNIC ver.2 MPASM assembler below. Assembly source file(v12.asm) For the development work of the remainder of this exercise, let us create a new folder on a drive of the PC for PIC microcomputer development use.(Example:E:\Project\PICNIC, etc.) ※Note of caution concerning folder names: For the directories containing ASM/HEX files, if the folder name contains Japanese characters, MPASM and the PIC programmer mentioned below will sometimes not be able to correctly load the ASM/HEX files. Do not place your files in such folders.(Added April 29, 2005)
During the development work, if you make an error during editing or cease to see correct operations and wish to return to the initial version state (at the time of PICNIC kit purchase), you can download and assemble the firmware assembly code from the above link and return to the beginning state of development. It is very important to save the versions of the source file being developed. For example, to save a version of the source file which was verified to be working correctly on April 27, we can create a copy of the file and set its name to v12-0427.asm for example. If later modifications to the source file cause the system to stop working correctly, we can conveniently "return" to this last working version anytime. 4.3.2 Assembling with MPASM Let us now use the MPASM assembler to assemble the PICNIC firmware and generate a HEX file. First, let us try assembling the downloaded original file (v12.asm)as it is. (1)Start MPASM. (2)In the [Source File Name:] text box, specify the v12.asm file or click on [Browse...] and indicate the location of the v12.asm (Fig. 2).
<Fig. 2> Specifying the source file. (3)Default values can be used for each of the parameters in [Options:]. We will change these as necessary. (4)Press the [Assemble] button to start the assembling.
During MPASM assembly, a small dialog will appear to show the current
status of assembly (recent PCs are high speed and the assembly completes
instantly). Finally, Assembly Successful. is displayed and the assembly is completed. Clicking on the [OK] button ends MPASM.
<Figure 3> Dialog during MPASM assembly ※It is also possible to assemble files by dragging and dropping file icons (for example, v12.asm) in Windows Explorer (folders) on top of the MPASM shortcut icon. (The drag&drop capability is for MPASM. The PIC writer software is not built for drag&drop. Added April 29, 2005.) 4.3.3 Files generated from assembling When the above described assembling procedure completes normally, the following group of files is produced. The most important of these is the machine language file v12.hex which will be transferred to the PIC microcomputer using the PIC writer. v12.hex : Intel-HEX format machine language
file ●Writing with the PIC writerPIC microcomputer writer ver.3/ Writer software setup(PIC programmer ver.3)/PC ⇔ PIC writer connection/ Verification of communication state between PC と PIC programmer/Writing the HEX format file v12.hex to PIC16F877 4.4.1 PIC microcomputer writer ver.3 To write firmware to the PIC microcomputer PIC16F877, we will use
the Akizuki Denshi PIC microcomputer writer ver.3. For the writer power,
we will use an AC adapter (
<Picture 3> PIC microcomputer writer ver.3(JP2 unconfigured) 4.4.2 Writer software setup (ver2.9.5 for PIC programmer ver.3) To send a HEX format machine language file to the PIC writer, we need special PC writer software. By using the old version for Windows(ver2.9.5), the following arrangements can be used with the loan out PIC writer: port replicator with serial port, an often used option on notebook PCs; docking stations found on IBM ThinkPad series machines; use of COM5: through a USB⇔RS-232C serial conversion adapter, etc. Below, we will assume the setup for PIC programmer release 2.9.5 in explaining the procedure. 【Note of caution】On the Akizuki Denshi site, the ver2.9.21 version is available for download, but this cannot be used because the firmware of the PIC programmer is not compatible with this version. Please download and use the local copy of ver2.9.5 below(added April 25, 2004). (1)Get the setup ZIP file for PIC programmer release 2.9.5(download PIC
programmer ver.2.9.5 localcopy (picpgm_win_2.9.5.zip)
). Download to, for example, C:\TMP. (2)The downloaded setup file is compressed in ZIP format so use an extraction tool such as WinZIP and extract the files to a temporary folder. (3)If you are using the WinZIP tool, you can right click on the downloaded PIC programmer ZIP file icon(picpgm_cd.zip)and the setup executable files will be extracted to a temporary folder (right click→WinZip→extract here). (4)Double click setup.exe created in(3)and run the setup. Some of the questions can be answered with all of the default values. (5)When the setup is done, the PIC Programmer
ver.3 tools will be set up in [Programs]→[Akizuki].
If you can, it would be convenient to create a shortcut icon
on the desktop to PIC Programmer ver.3. 4.4.3 Connection between PC ⇔ PIC writer The connection between the PC and PIC writer has to be done using a serial cable(not Ethernet). It will be about the same arrangement as when the PC ⇔ PICNIC are configured for bootstrap mode. Connect the PC and PIC writer with an RS-232C D-Sub9pin male⇔female straight connection cable. If there is no serial port on the PC side, purchase a USB virtual serial port adapter (it will be assigned to COM5:, etc.) and connect/configure it on the PC (available for purchase at PC shops). Depending on the type of USB virtual serial port adapter used, there are situations in which it will not be recognized as a serial port. In that case, contact the instructor for advice.
<Picture 4> Connection of serial cable on PC side.
<Picture 5> Connection of serial cable on PIC writer side 4.4.4 Verification of the communication state between the PC and PIC programmer We will verify the states of various communications, for example whether or not the PC and PIC programmer are communicating correctly, whether or not the PIC writer software can recognize the target PIC writer, etc. (1)Insert the AC adapter to the DC plug of the PIC programmer and turn on the writer power. Verify that the Power(D1) LED at the top of the writer board is on. (2)On the PC, start up the PIC writer software. The following type of screen should appear (in the example below, the writer is detected at COM4).
<Figure 4> Startup screen of PIC writer software (3)Select [Option(O)]→[COM port configuration(C)], select the serial port connected to the programmer. For desktop machines that use the standard serial port or notebook PCs with port replicators or serial ports via a docking station, the connection should be at COM1: or COM2:. On the other hand, for connections using a USB virtual serial port adapter, in many cases COM5: or above is used. (4)When the PIC writer is correctly recognized (for example at COM2:), the following message will appear in the lower message area Writer detected at COM2. or COM2: selected. In the lower right yellow textbox, the currently connected serial port number and PIC programmer control firmware version number will be displayed. For example: COM2: AKIPIC-PGM V3.00
<Figure 5> PIC writer software detection error.
<Figure 6> Successful detection by PIC writer software(in this case connection is at COM2. Depending on the writer ROM revision, the display sometimes shows PGMV3.00--4.00). 4.4.5 Writing the HEX format file (v12.hex) to PIC16F877(added September 9, 2004, revised April 29, 2005) (1)Set the [Device setting] at the top right part of the PIC writer software window to PIC16F877(important).
<Figure 7> Setting writing device to PIC16F877.
(2)Change the selection jumper JP2 to 1-2 for the PIC microcomputer type to be written at the top right area of the PIC writer board (important). The setting information will also appear in the small window of「board information」in the PIC writer software.
<Picture 6> Change the selection jumper JP2 to 1-2 to select the PIC microcomputer type. (3)Insert the PIC16F877-20/P IC included in the peripheral extension options kit into the PIC writer 40 pin socket.※Do not use the PIC microcomputer PIC16F877A-1/P from the PICNIC board! Insert the chip so that the half moon cut on the IC
is at the top.If the PIC is not inserted in the
correct direction, it will break. Make sure
that the pins have been inserted completely and lower the zero
pressure IC socket lever to secure the pins.
<Picture 7> Lowering the IC socket lever to secure the PIC16F877-20/P.
(4)Click on the [Load Hex] button at the top left, and specify the hex format machine language file (v12.HEX). Pressing the [Open] button will update the program memory and EEPROM memory with the loaded contents(v12.hex)(verify that the memory is not filled with 3FFF, FF, etc.). ※Note, the PIC writer software is not designed for drag and drop operations. Added April 29, 2005. (5)Change [Config. Word setting] in the PIC writer software
righthand window to the following configuration values (important).
(6)Press the [Program] button in the top right window of the PIC writer software to begin the write operation (duration:approximately 3 minutes). Before the actual writing begins, the software will ask for permission to [Overwrite?] the current firmware so answer [Yes]. (7)During the write operation, the Busy(D2) LED on the PIC writer board will be lit. When the writing is completed, the written contents will automatically be checked against the actual PIC microcomputer memory contents (verification) and the result will be reported. ※If an error occurs during the write operation, a mismatch between the write software, the writer version, or the PIC microcomputer type can be the cause. Normal write operations can be done with the following combinations. ・write software ver2.9.5 + writer ver.3 + PIC16F877-20/P ●Operation testing following firmware updatesImplementation of zero pressure socket on top of the PICNIC side IC socket/Operation testing with program updated PIC 4.5.1 Implementation of zero pressure socket on top of PICNIC side IC socket ※Caution: When inserting or removing microcomputers on the PICNIC side IC socket, be sure to turn off the PICNIC power!! If you insert or remove ICs with the power on (with programs running), there is a high probability that the IC will be broken. Leave the PIC-IC socket on the PICNIC empty. We will implement the zero pressure socket here. ※DIP300mil 40pin zero pressure IC socket(TEXTOOL)(←included in the PICNIC peripheral extenstion options kit.) ※Advice for implementation: When placing the zero pressure socket on the PICNIC side IC socket, the half fixed resistor VR1 for LCD contrast adjustment at the bottom left of the PICNIC board will get in the way a bit. To solve this problem, slant the VR1 a bit with your finger toward the left side of the board before you begin. (Bend VR1 without breaking its pin legs. You will need a little courage for this.)
<Picture 8> Slant the half fixed VR1 resistor for LCD contrast adjustment a bit with your finger.
<Picture 9> Implement zero pressure socket on top of
PICNIC side IC socket. 4.5.2 Operation testing of program updated PIC With the PIC microcomputer used in the program updating procedure of §4.4.5 above, verify whether or not the board works correctly in the same manner as §3.4 Operation checks, and §3.5 Control via a browser. (Note of caution, the EEPROM state has been initialized.)
<Picture 10> Inserting the program updated PIC microcomputer
into the PICNIC side IC socket. ●Firmware updating exampleUpdate example 1: Modifying the version number/Update example 2: Displaying the firmware updater name 4.6.1 Update example 1: Modifying the version number The constant definitions for the version number are in lines 47 and 7272 of firmware v12.asm. These values will be saved in the actual PIC microcomputer as the write in value for the EEPROM and the default load value for web control, respectively. (When the hex file has been loaded, check the contents of the PIC writer software EEPROM data area and the program memory from location 0x1F00 on carefully. <Before modification> Line 47: DE 1,2,0,0 ; Firmware Version x,x,x,x Line 7272: DT 1,2,0,0 ; Firmware Version x,x,x,x In these sections, let us change 0→1 in the fourth word to modify the version number. <After modification> Line 47: DE 1,2,0,1 ; Firmware Version x,x,x,x Line 7272: DT 1,2,0,1 ; Firmware Version x,x,x,x ※Hint: In these quadruples, the first two numbers are the major version numbers, the last two numbers represent the minor version numbers. Therefore, if we imagine the situation in which a minor version of ver1.3 has been released, users will change only the last two bytes. Also, each number can be set as a byte value so minor version numbers can be set from 0.0 to 255.255. Let us save this version of the firmware with a name such as v12-0427.asm, assemble it with MPASM, update the firmware with the PIC writer, insert the updated PIC microcomputer onto the PICNIC board, and verify that the version number has been updated using a web browser.
<Figure 8> Example of PICNIC remote I/O web browser screen following version number update. 4.6.2 Update example 2: Displaying the firmware updater name The string definitions for displaying copyright information for this firmware are in lines 7255 and 7256 of firmware v12.asm. <Before modification> Line 7255: DA "<P><HR>Copyright (c) 2000-2001 by <A
HREF=\"http://www.tristate.ne.jp\">TriState Co.,Ltd.</A>
" ※Hint 1: By defining DB 06,8A, the [CR]+[LF] code will be generated during HTML message output and a line return will occur. On the web browser side, a 「line return」in HTML has no meaning as far as the display is concerned. ※Hint 2: Inside the double quotations "" for defining strings using the DA pseudocode, if you want to use double quotations for the HTML anchor tag, quote with \" . If this is a hassle, you can also use single quotes ’(fundamental trick). Let us try displaying the name of the person updating the firmware by adding a new line between lines 7255 and 7256 and using line 7255 as an example. For instance, for Mr. Nagano TARO, student ID number 02TA699X we can write the following. <After modification> Line 7256: DA "<BR>Firmware Modified by <A HREF=\"http://sugsi.jp/\">Nagano TARO (02TA699X)</A> " Line 7257: DB 06,8A ;,13,10 Save this version with a name such as v12-0427.asm, assemble the code, write it to the PIC, and verify using a web browser that the name of the firmware updater is displayed in the bottom part of the remote I/O screen.
<Figure 9> Display of the firmware updater name. ※Hint 3: In this way, we can create a variety of displays to be sent to a web browser by increasing the HTML portions. However, there are limitations to how much we can write because of (1)limits on the amount of memory usable on the PIC microcomputer and (2)limits on the number of bytes that can be sent in each single TCP/IP message (each of the steps ESTAB00~04).
|
|
wasaki@cs.shinshu-u.ac.jp |