To all our customers Regarding the change of names mentioned in the document, such as Hitachi Electric and Hitachi XX, to Renesas Technology Corp. The semiconductor operations of Mitsubishi Electric and Hitachi were transferred to Renesas Technology Corporation on April 1st 2003. These operations include microcomputer, logic, analog and discrete devices, and memory chips other than DRAMs (flash memory, SRAMs etc.) Accordingly, although Hitachi, Hitachi, Ltd., Hitachi Semiconductors, and other Hitachi brand names are mentioned in the document, these names have in fact all been changed to Renesas Technology Corp. Thank you for your understanding. Except for our corporate trademark, logo and corporate statement, no changes whatsoever have been made to the contents of the document, and these changes do not constitute any alteration to the contents of the document itself. Renesas Technology Home Page: http://www.renesas.com Renesas Technology Corp. Customer Support Dept. April 1, 2003 Cautions Keep safety first in your circuit designs! 1. Renesas Technology Corporation puts the maximum effort into making semiconductor products better and more reliable, but there is always the possibility that trouble may occur with them. Trouble with semiconductors may lead to personal injury, fire or property damage. Remember to give due consideration to safety when making your circuit designs, with appropriate measures such as (i) placement of substitutive, auxiliary circuits, (ii) use of nonflammable material or (iii) prevention against any malfunction or mishap. Notes regarding these materials 1. These materials are intended as a reference to assist our customers in the selection of the Renesas Technology Corporation product best suited to the customer's application; they do not convey any license under any intellectual property rights, or any other rights, belonging to Renesas Technology Corporation or a third party. 2. Renesas Technology Corporation assumes no responsibility for any damage, or infringement of any third-party's rights, originating in the use of any product data, diagrams, charts, programs, algorithms, or circuit application examples contained in these materials. 3. All information contained in these materials, including product data, diagrams, charts, programs and algorithms represents information on products at the time of publication of these materials, and are subject to change by Renesas Technology Corporation without notice due to product improvements or other reasons. It is therefore recommended that customers contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor for the latest product information before purchasing a product listed herein. The information described here may contain technical inaccuracies or typographical errors. Renesas Technology Corporation assumes no responsibility for any damage, liability, or other loss rising from these inaccuracies or errors. Please also pay attention to information published by Renesas Technology Corporation by various means, including the Renesas Technology Corporation Semiconductor home page (http://www.renesas.com). 4. When using any or all of the information contained in these materials, including product data, diagrams, charts, programs, and algorithms, please be sure to evaluate all information as a total system before making a final decision on the applicability of the information and products. Renesas Technology Corporation assumes no responsibility for any damage, liability or other loss resulting from the information contained herein. 5. Renesas Technology Corporation semiconductors are not designed or manufactured for use in a device or system that is used under circumstances in which human life is potentially at stake. Please contact Renesas Technology Corporation or an authorized Renesas Technology Corporation product distributor when considering the use of a product contained herein for any specific purposes, such as apparatus or systems for transportation, vehicular, medical, aerospace, nuclear, or undersea repeater use. 6. The prior written approval of Renesas Technology Corporation is necessary to reprint or reproduce in whole or in part these materials. 7. If these products or technologies are subject to the Japanese export control restrictions, they must be exported under a license from the Japanese government and cannot be imported into a country other than the approved destination. Any diversion or reexport contrary to the export control laws and regulations of Japan and/or the country of destination is prohibited. 8. Please contact Renesas Technology Corporation for further details on these materials or the products contained therein. F-ZTAT Reprogramming by On-Chip CAN Application Note ADE-502-084 Rev. 1.0 03/14/03 Hitachi, Ltd. Cautions 1. Hitachi neither warrants nor grants licenses of any rights of Hitachi’s or any third party’s patent, copyright, trademark, or other intellectual property rights for information contained in this document. Hitachi bears no responsibility for problems that may arise with third party’s rights, including intellectual property rights, in connection with use of the information contained in this document. 2. Products and product specifications may be subject to change without notice. Confirm that you have received the latest product standards or specifications before final design, purchase or use. 3. Hitachi makes every attempt to ensure that its products are of high quality and reliability. However, contact Hitachi’s sales office before using the product in an application that demands especially high quality and reliability or where its failure or malfunction may directly threaten human life or cause risk of bodily injury, such as aerospace, aeronautics, nuclear power, combustion control, transportation, traffic, safety equipment or medical equipment for life support. 4. Design your application so that the product is used within the ranges guaranteed by Hitachi particularly for maximum rating, operating supply voltage range, heat radiation characteristics, installation conditions and other characteristics. Hitachi bears no responsibility for failure or damage when used beyond the guaranteed ranges. Even within the guaranteed ranges, consider normally foreseeable failure rates or failure modes in semiconductor devices and employ systemic measures such as fail-safes, so that the equipment incorporating Hitachi product does not cause bodily injury, fire or other consequential damage due to operation of the Hitachi product. 5. This product is not designed to be radiation resistant. 6. No one is permitted to reproduce or duplicate, in any form, the whole or part of this document without written approval from Hitachi. 7. Contact Hitachi’s sales office for any questions regarding this document or Hitachi semiconductor products. Rev. 1.0, 03/03, page ii of vi General Precautions on Handling of Product 1. Treatment of NC Pins Note: Do not connect anything to the NC pins. The NC (not connected) pins are either not connected to any of the internal circuitry or are used as test pins or to reduce noise. If something is connected to the NC pins, the operation of the LSI is not guaranteed. 2. Treatment of Unused Input Pins Note: Fix all unused input pins to high or low level. Generally, the input pins of CMOS products are high-impedance input pins. If unused pins are in their open states, intermediate levels are induced by noise in the vicinity, a passthrough current flows internally, and a malfunction may occur. 3. Processing before Initialization Note: When power is first supplied, the product’s state is undefined. The states of internal circuits are undefined until full power is supplied throughout the chip and a low level is input on the reset pin. During the period where the states are undefined, the register settings and the output state of each pin are also undefined. Design your system so that it does not malfunction because of processing while it is in this undefined state. For those products which have a reset function, reset the LSI immediately after the power supply has been turned on. 4. Prohibition of Access to Undefined or Reserved Addresses Note: Access to undefined or reserved addresses is prohibited. The undefined or reserved addresses may be used to expand functions, or test registers may have been be allocated to these addresses. Do not access these registers; the system’s operation is not guaranteed if they are accessed. Rev. 1.0, 03/03, page iii of vi Preface This application note describes how to reprogram the flash memory using user program mode. The program data can be provided by using the on-chip HCAN (Hitachi Controller Area Network) of the H8S Series. For details on the flash memory and HCAN, refer to the following sections in the H8S/2612F Hardware Manual. • ROM • HCAN Although operations of programs and circuit examples, etc. described in this application note are confirmed, be sure to confirm them again before actual use. (Note that examples of programs in this application note are for the on-chip HCAN of the H8S/2612F.) Rev. 1.0, 03/03, page iv of vi Contents Section 1 Overview........................................................................................... 1 1.1 1.2 1.3 List of F-ZTAT™* Microcomputers (H8S Series) Including HCAN Unit ......................1 Overview of User Program Mode .....................................................................................2 Overview of Reprogramming Method in User Program Mode.........................................3 Section 2 Overview of Sample System............................................................. 5 2.1 2.2 2.3 2.4 2.5 Hardware List....................................................................................................................5 Software List .....................................................................................................................6 Items to be Customized for Sample Program....................................................................6 Installing Programs to be Used in Application Note.........................................................8 CAN Bus Interface (Example) ..........................................................................................9 Section 3 Procedure for Reprogramming Flash Memory in User Program Mode...................................................................... 11 3.1 3.2 3.3 3.4 Mapping Flash Memory for Application (Sample) Program ............................................13 Programming Programs to Target Board and SCI-HCAN Communication Conversion Board .............................................................................................................13 CAN Communication Settings in Application Note .........................................................14 Flash Memory Reprogramming Sequence in User Program Mode ..................................15 Section 4 Reprogramming Flash Memory in User Program Mode .................. 17 4.1 4.2 4.3 4.4 Initial State ........................................................................................................................17 Transferring Program/Erase Control Program ..................................................................18 Erasing Blocks of Flash Memory......................................................................................19 Programming New Application Program..........................................................................20 Section 5 Details of Software ........................................................................... 21 5.1 5.2 5.3 F-ZTAT Microcomputer H-CAN Program.......................................................................21 SCI-HCAN Communication Conversion Program ...........................................................21 Application (Sample) Program .........................................................................................22 Section 6 Example of Creating Application (Sample) Program ....................... 23 6.1 6.2 6.3 6.4 Functions and Variables....................................................................................................23 Example of Changing CAN Communication Settings......................................................24 Example of Changing Receive and Transmit Mailbox Numbers for CAN Communications ......................................................................................................26 Application (Sample) Program Flowchart ........................................................................30 Rev. 1.0, 03/03, page v of vi Section 7 Example of Creating Program/Erase Control Program .....................31 7.1 7.2 7.3 7.4 Overview........................................................................................................................... 31 Functions, Variables, and Constants ................................................................................. 35 Example of Changing Receive and Transmit Mailbox Numbers for CAN Communications...................................................................................................... 38 Program/Erase Program Flowchart ................................................................................... 42 Section 8 Functions and Operations of On-Board Programming Tool and SCI-HCAN Communication Conversion Program ...........................45 8.1 8.2 8.3 8.4 8.5 Installing On-Board Programming Tool ........................................................................... 45 First Programming of Application (Sample) Program to Target Board............................ 50 Programming SCI-HCAN Communication Conversion Program to SCI-HCAN Communication Conversion Board................................................................................... 56 Reprogramming Flash Memory in User Program Mode................................................... 59 Error Messages for FlashCAN.exe (Additional Messages for HCAN)............................. 73 Section 9 Supplementary Description ...............................................................75 9.1 9.2 9.3 Required Items for Reprogramming Flash Memory in User Program Mode.................... 75 Differences between User Program Mode and Boot Mode .............................................. 76 How to Measure Application Time for E and P Bits ........................................................ 77 Rev. 1.0, 03/03, page vi of vi Section 1 Overview This application note describes how to reprogram the H8S/2612F on-chip flash memory using user program mode. The program data can be provided by using the on-chip HCAN of the H8S/2612F. As a sample system, this application note describes how to reprogram the flash memory in the system configuration shown in figure 1.1. Also this application note describes how to customize the programs shown in the application note according to the operating frequency and the CAN bus specifications for the user system. CAN bus SCI Host (PC) Target board SCI-HCAN communication conversion H8S/2612F Reprogram data Reprograms the contents of the on-chip flash memory using user program mode. Figure 1.1 Sample System Configuration 1.1 List of F-ZTAT™* Microcomputers (H8S Series) Including HCAN Unit This application note applies to the following devices: • H8S/2612F • H8S/2623F • H8S/2626F • H8S/2636F When using this application note as a reference for using microcomputers other than the H8S/2612F, note the differences in: • Addresses, bit positions, and functionality of the on-chip registers • Control method for erasing and programming the flash memory (such as application time for E and P bits) Note: * F-ZTAT is a trademark of Hitachi, Ltd. Rev. 1.0, 03/03, page 1 of 78 1.2 Overview of User Program Mode User program mode enables on-board reprogramming of the flash memory. This mode allows the user to reprogram the contents of the on-chip flash memory with the F-ZTAT microcomputer mounted on the user’s board. Two modes are available for on-board reprogramming of the flash memory: boot mode and user program mode. In boot mode, a boot program included in the F-ZTAT microcomputer is executed to implement programming to the flash memory. In user program mode, an application program in the flash memory (on-chip ROM) is executed. For this reason, user program mode requires the reprogram processing to be installed in the application program in advance. Reset state MD1 = 1, MD2 = 1, FWE = 0 MD1 = 1, MD2 = 0, FWE = 1 MD1 = 1, MD2 = 1, FWE = 1 FWE = 1 Boot mode User program mode User mode FWE = 0 On-board program mode User mode with on-chip ROM enabled Figure 1.2 Transition of User Program Mode In boot mode, the on-chip boot program automatically erases the entire flash memory before new data is programmed. For this reason, a complete reprogramming of the application program is required even if the user only wants to reprogram it partially. User program mode allows the user to erase and program any data according to the user system, allowing a partial reprogram for individual erased blocks. Note: The word “program” of user program mode means “programming to” the flash memory. Rev. 1.0, 03/03, page 2 of 78 1.3 Overview of Reprogramming Method in User Program Mode Since the on-chip ROM is enabled in user program mode, the application program including the reprogram processing must be programmed to the on-chip flash memory in advance. Use boot mode or ROM programmer mode to perform this initial programming. If the reprogramming in user program mode is disabled due to accidental erasure of the application program including the reprogram processing, the user can forcibly program the data in boot mode. Initial programming in boot mode (Complete erasure) Application programming Reprogramming in user program mode The on-chip boot program in the F-ZTAT microcomputer automatically erases all the data. The reprogram processing must be included in advance in user program mode.* Any block can be erased. Application (Erasing blocks) Re-updating of application program Application Data can be programmed for the erased block. Partial reprogramming Note: * Contents of the reprogram processing that must be installed into the application The processing that detects the transition conditions for reprogram processing, and the processing that transfers the program/erase control program to RAM and then jumps to RAM must be installed into the application in advance. Figure 1.3 Reprogramming Method in User Program Mode (Overview) Rev. 1.0, 03/03, page 3 of 78 Rev. 1.0, 03/03, page 4 of 78 Section 2 Overview of Sample System 2.1 Hardware List The following lists the components which are required for executing the sample program described in this application note. Table 2.1 Hardware List No. Hardware Name Specifications Remarks 1 Executes FlashCAN.exe. Must have the serial interface. OS for DOS/V personal computers: Host (PC) Windows®*1 98(S), Windows® 2000, Windows® NT4.0, Windows® Me, or Windows® XP 2 SCI-CAN communication conversion board Converts serial communications from the host to CAN communications to communicate with the target board. It also converts CAN communications from the target board to serial communications. LIN-CAN Starter Kit (H8S/2612F) manufactured by Hokuto Denshi co., ltd. 3 Target board Contains on-board H8S/2612F that has the on-chip flash memory to which the data will be programmed. LIN-CAN Starter Kit (H8S/2612F) manufactured by Hokuto Denshi co., ltd. requires a switch for the FWE pin to support user program mode.*2 4 Serial cable Connects the 9-pin host to the J3 connector on the SCI-CAN communication conversion board Attached to the LIN-CAN Starter Kit (H8S/2612F) manufactured by Hokuto Denshi co., ltd.*2 5 CAN bus cable Connects the J7 connector on the Attached to the LIN-CAN Starter Kit 3-pin SCI-CAN communication (H8S/2612F) manufactured by Hokuto conversion board to the J7 Denshi co., ltd. connector on the target board Notes: 1. Windows® is a registered trademark of Microsoft Co., in the U.S. and other countries. 2. A transition to user program mode requires turning on and off the FWE pin. The LIN-CAN Starter Kit (H8S/2612F) manufactured by Hokuto Denshi co., ltd. uses the slide switch (SW11) on the board to turn on and off the FWE pin. For actual operations on changing modes for the LIN-CAN Starter Kit (H8S/2612F), see the attached manual. Rev. 1.0, 03/03, page 5 of 78 2.2 Software List Table 2.2 Software List No. File Name Program Name 1 FlashCAN.exe F-ZTAT Microcomputer This program runs in the host (PC). It is an H-CAN Program evaluation version for this application note. 2 SCI2612F3.sub Program control program (SCI communications) 3 HCAN2612F3.sub*1 Program/erase control program (HCAN communications) Use this program for the reprogramming in user program mode. When executing this program, it should be sent from FlashCAN.exe to the processing included in the application on the target board via serial transmission, and then store it in RAM. 4 SCItoCAN.mot SCI-CAN communication conversion program This program runs in the SCI-CAN communication conversion board. 5 Sample1.mot*1 Application (sample) program This program runs in the target board. This program includes the reprogram processing in user program mode. Note: 2.3 * Remarks Use this program for the initial programming in boot mode. When executing this program, it should be sent from FlashCAN.exe to the boot program in the target board via serial transmission, and then store it in RAM. To use the sample program provided in this application note according to the user system, you can customize the items listed below. Change the source files, and then compile and assemble them. You do not need to customize anything if you use the sample system without any changes. Items to be Customized for Sample Program No. Items Defaults 1 See the next page. • 2 CAN communication settings Mailbox numbers for Receive: MB4 transmission and Transmit: MB5 reception used by the on-chip HCAN Sections to Change Sample1.mot InitHCAN() function in the HCAN_up.c file • The following functions in the Sample1.motHCAN_up.src file: InitHCAN(), PowerON_Reset(), CAN_MB4_rcv1byte(), and CAN_MB5_trs1byte() • HCAN2612f3.mot RCV1BYTE() and TRS1BYTE() subroutines in the HCAN2612f3.src file Rev. 1.0, 03/03, page 6 of 78 To compile or assemble the program, use the batch file or Hew project of the DOS prompt. The attached batch file and Hew project found in the samples show an example of using the compiler package Ver. 5.0.02. Change the following files according to the version of your compiler package. • To change the HCAN2612f3.mot file, use the file HCAN2612f3.bat or Hew2.hws in the HCAN2612f3 folder. • To change the Sample1.mot file, use the file Sample1.bat or Hew2.hws in the Sample1 folder. Rev. 1.0, 03/03, page 7 of 78 2.4 Installing Programs to be Used in Application Note Execute setup.exe to install the programs. The following shows the directory configuration after installation. [Directory Configuration after Standard Installation] [c:\FlashCAN] FlashCAN.exe SCI2612F3.sub SCI2612F3.inf HCAN2612F3.sub HCAN2612F3.inf [HCAN2612F3] ; Program/erase control program HCAN2612F3.src . . . (*1) Program that can be customized HCAN2612F3.bat [Debug] [Hew2] [Release] Hew2.hws [SimDebug_H8S-2600A] Hew2.tws Hew2.hwp Hew2.hbp Hew2.pgs Hew2.tps DefaultSession.hsf SimSessionH8S-2600A.hsf [Sample1] ; Application (sample) program Sample1.mot . . . (*1) Program that can be customized HCAN_up.c Sample1.c io_2612.h Sample1.bat [Hew2] [Debug] Hew2.hws [Release] Hew2.tws [SimDebug_H8S-2600A] Hew2.hbp Hew2.hwp Data_00.mot Hew2.pgs Data_FF.mot [SCItoCAN] Debug.hdp Release.hdp HCAN2612f3.abs HCAN2612f3.h8a HCAN2612f3.hlk HCAN2612f3.obj Hew2.map Hew2.tps DefaultSession.hsf SimSessionH8S-2600A.hsf Debug.hdp Release.hdp Sample1.abs HCAN_up.h8c Sample1.h8c Sample1.hlk HCAN_up.obj Sample1.obj Hew2.map ; SCI-CAN communication conversion program SCItoCAN.mot You can start up the program tool (FlashCAN.exe) from the Windows® Start menu as follows: From the Start menu, select Programs, FlashCAN, and then FlashCAN. Rev. 1.0, 03/03, page 8 of 78 2.5 CAN Bus Interface (Example) A bus transceiver IC is necessary to connect this chip to a CAN bus. A Philips PCA82C250 transceiver IC is recommended. Any other product must be compatible with the PCA82C250. Figure 2.1 shows a sample connection diagram. 124 This LSI Vcc PCA82C250 RS Vcc HRxD RxD CANH HTxD TxD CANL Vref CAN bus GND NC 124 Note: NC: No Connection Figure 2.1 High-Speed Interface Using PCA82C250 Table 2.3 LED Pin Assignment Microcomputer Pin LED PD0 D1 PD1 D2 PD2 D3 PD3 D4 PD4 D5 PD5 D6 PD6 D7 PD7 D8 The LED port is turned on by the bit of 0. Rev. 1.0, 03/03, page 9 of 78 Rev. 1.0, 03/03, page 10 of 78 Section 3 Procedure for Reprogramming Flash Memory in User Program Mode This application note uses the following procedure for reprogramming the flash memory: 1. Use the reception of a command via HCAN communication as a trigger to start the reprogramming of the flash memory. 2. Transfer the program/erase control program from outside to RAM via HCAN communication. 3. Switch the FWE pin on the target board (set FWE = 1 to enter user program mode). 4. Transfer the program data from outside via HCAN communication. The hosts used in steps 1, 2, and 4 above are the host (PC) and SCI-HCAN communication conversion board. Rev. 1.0, 03/03, page 11 of 78 Target-board side Processing on host (PC) and SCI-HCAN communication conversion board Restart in user mode Initialize on-chip HCAN Execute application (sample controls lighting of LEDs) No [1] Issue command (0x48) via HCAN communication Is command (0x48) received? Yes [2] Transfer program/erase control program via HCAN communication Transfer program/erase control program to RAM Branch to program/erase control program on RAM User program mode (execute program on RAM) → FWE pin 1 Execute program/erase control program on RAM (reprogramming flash memory) → FWE pin 0 [3] [4] Provide erase blocks and program data via HCAN communication [3] End Note: The shaded section in the flowchart indicates the processing that must be installed into the application in advance. Rev. 1.0, 03/03, page 12 of 78 3.1 Mapping Flash Memory for Application (Sample) Program H'000000 EB0 (1 kbyte) Vector table Vector table H'0003FF H'000400 H'0007FF H'000800 EB1 (1 kbyte) Unused EB2 (1 kbyte) Main part of application H'000BFF H'000C00 Main part of program: Sample1.mot (programmed in boot mode) EB3 (1 kbyte) Sample program H'000BFF H'001000 EB4 (28 kbytes) Parameter data H'007FFF H'008000 H'01FFFF EB5 : Unused EB9 Parameter data: Data_FF.mot and Data_00.mot (for reprogramming in user program mode) This application note covers the reprogramming of these blocks. Note: Download Sample1.mot into the flash memory on the target board in boot mode beforehand. This application note describes the reprogramming of Data_FF.mot or Data_00.mot into the flash memory in user program mode. Since the application turns on or blinks the LEDs according to this data, you can visually check that the data has been reprogrammed. 3.2 Programming Programs to Target Board and SCI-HCAN Communication Conversion Board Before reprogramming the flash memory in user program mode, you need to program the programs in boot mode. Use ‘Standard Mode’ of FlashCAN.exe for programming in boot mode. Program the following programs in boot mode: • Program Sample1.mot into the target board. • Program SCItoCAN.mot into the SCI-HCAN communication conversion board. For details on how to use FlashCAN.exe, see section 8. Rev. 1.0, 03/03, page 13 of 78 3.3 CAN Communication Settings in Application Note The application note requires the following settings for CAN communication: CAN baud rate: 1000 kbps (CPU operating frequency = 20 MHz and BCR setting = H′0034.) • BRP setting: 0 (1 time quantum/ 2 system clocks) • TSEG1 setting: 4 (5 time quanta) • TSEG2 setting: 3 (4 time quanta) This results in: 1 Mbps = 20 MHz/{2 × ( 0 + 1) × (3 + 4 + 3 )} ↑ ↑ ↑ BRP TSEG1 TSEG2 Data frame ID (standard format: 11 bits) • Receive data ID on the communication conversion board: H′03F9 (11-bit display: 01111111001) • Receive data ID on the target board: H′0602 (11-bit display: 11000000010) Rev. 1.0, 03/03, page 14 of 78 3.4 Flash Memory Reprogramming Sequence in User Program Mode Host (PC) Set CAN communication SCI-CAN communication conversion board Target board Initialize SCI Initialize CAN communication Check boot button Blink all LEDs Press start button H command (0x48), transmit ID, receive ID, SJW, BRP, TMSEG2, and TMSEG1 Initialize CAN communication H command (0x48) (start reprogram processing) Enter flash memory reprogram processing ACK ACK Program/erase control program Program/erase control program Echoback Echoback Store program in RAM and jump to RAM Target board's clock Target board's clock * Wait loop calculation ACK ACK The shaded section indicates the operation by the user. Note: * The program/erase control program uses the software loop count to control the application time, etc. for bits E and P. Increment or decrement the loop count according to the operating frequency of the F-ZTAT microcomputer. Rev. 1.0, 03/03, page 15 of 78 SCI-CAN communication conversion board Host (PC) Target board Set FWE pin to 1 Check write button * Press start button W command (0x57), erase count, and erase address W command (0x57), erase count, and erase address Erase flash block Erase response Erase response Program data Program data Flash program Program response Program response Program is completed Program is completed Clear FWE pin to 0 Reset Blink LEDs Note: * Before pressing the start button for programming, set the FWE pin to 1 to enter user program mode. Remarks: The settings of SCI communication between the host (PC) and SCI-CAN communication conversion board should be as follows: • Mode: Asynchronous communication method • Data format: 8-bit data, without parity, one stop bit • Bit rate: 57.600 bit/sec Rev. 1.0, 03/03, page 16 of 78 Section 4 Reprogramming Flash Memory in User Program Mode 4.1 Initial State (Host) Program/erase control program Parameter data Data_00.mot (new data) H8S/2612F (MDO = 1, MD1 = 1, MD2 = 1, FWE = 0) CAN (Flash memory) (RAM) Application program Sample1.mot Parameter data: Erased (All data is set to H'FF) Description: 1. Restart the H8S/2612F in user mode (MD0 = 1, MD1 = 1, MD2 = 1, and FWE = 0). 2. The application program initializes the HCAN unit to accept the conditions for entering the program processing. 3. Since the parameter data area has been erased in boot mode, the data is set to H′FF. The application program lights all the LEDs. Note: For details on how the application program operates the LEDs, see section 5.3, Application (Sample) Program. Rev. 1.0, 03/03, page 17 of 78 4.2 Transferring Program/Erase Control Program (Host) Program/erase control program Parameter data Data_00.mot (new data) Start request for program processing Transfer of program/erase control program H8S/2612F (MDO = 1, MD1 = 1, MD2 = 1, FWE = 0 → 1) CAN (Flash memory) Application program Sample1.mot (RAM) Program/erase control program Parameter data: Erased (All data is set to H'FF) Description: 1. The host uses HCAN communication to issue a request to start the reprogram processing. 2. The application program accepts this request, and then enters the transfer processing of the program/erase control program. 3. The host transfers the program/erase control program. 4. The application program stores the program/erase control program to be transferred in RAM. After completion of the transfer, the application program jumps to the program/erase control program in RAM. 5. The user uses the switch on the target board to set the FWE pin to on (1). Setting FWE = 1 clears the hardware protect to enable erasing and programming of the flash memory. Rev. 1.0, 03/03, page 18 of 78 4.3 Erasing Blocks of Flash Memory (Host) Program/erase control program Parameter data Data_00.mot (new data) Erase request H8S/2612F (MDO = 1, MD1 = 1, MD2 = 1, FWE = 1) CAN (Flash memory) Application program Sample1.mot (RAM) Program/erase control program Erasing blocks Description: 1. The host uses HCAN communication to issue a request for erasing blocks in the area in which the new data is to be programmed. 2. The program/erase control program in RAM erases the requested blocks. However, the program in the initial state only executes erase-verify without executing erase because all blocks have been erased. Rev. 1.0, 03/03, page 19 of 78 4.4 Programming New Application Program (Host) Program/erase control program Parameter data Data_00.mot (new data) Parameter data Data_00.mot (new data) H8S/2612F (MDO = 1, MD1 = 1, MD2 = 1, FWE = 1 → 0) CAN (Flash memory) Application program Sample1.mot (RAM) Program/erase control program Parameter data Data_00.mot (new data) Description: 1. The host provides the program data (Data_00.mot) via HCAN communication. 2. The program/erase control program in RAM receives the program data and then programs it to the flash memory. 3. After the data has been programmed, set the FWE pin to off (0). 4. Restart the application program. Then, the application program refers to the parameter data (new data) and blinks the LEDs. Note: For details on how the application program operates the LEDs, see section 5.3, Application (Sample) Program. Rev. 1.0, 03/03, page 20 of 78 Section 5 Details of Software 5.1 F-ZTAT Microcomputer H-CAN Program The F-ZTAT Microcomputer H-CAN Program (FlashCAN.exe) runs in the host (PC). No. File Name Description 1 FlashCAN.exe Main section of the F-ZTAT Microcomputer H-CAN Program 2 SCI2612F3.inf Information file (for SCI communication) for the H8S/2612F microcomputer 3 SCI2612F3.sub Load module of the program control program 4 HCAN2612F3.inf Information file (for H-CAN communication) for the H8S/2612F microcomputer 5 HCAN2612F3.sub Load module of the program/erase control program 6 HCAN2612F3.src Source file of the program/erase control program 7 HCAN2612F3.bat DOS prompt batch file that assembles and links the program/erase control program 8 Hew2.hws Hew project file that assembles and links the program/erase control program Example of the FlashCAN.exe window (Main window) (Window for setting the CAN communication specifications) 5.2 SCI-HCAN Communication Conversion Program The SCI-HCAN communication conversion program (SCItoCAN.mot) runs in the SCI-HCAN communication conversion board. No. File Name Description 1 On-chip load module for the H8S/2612F on the SCI-HCAN communication conversion board. This module converts the interface between the SCI and HCAN. It uses the on-chip SCI and HCAN for the H8S/2612F on the SCI-HCAN communication conversion board. SCItoCAN.mot Note: Download the SCI-HCAN communication conversion program to the SCI-HCAN communication conversion board in boot mode in advance. Rev. 1.0, 03/03, page 21 of 78 5.3 Application (Sample) Program The application (sample) program (Sample1.mot) runs on the target board. No. File Name Description 1 Sample1.mot On-chip load module for the H8S/2612F on the target board. This module includes the flash-memory reprogram processing in user program mode. It provides the sample function that lights and blinks the LEDs to let you visually check the operation of the application. 2 Data_FF.motData_00.mot Parameter data of the pattern by which the Sample1.mot lights and blinks the LEDs. H′FF (erased): Lights all the LEDs. H′00: Blinks the LEDs at one-second intervals. 3 HCAN_up.c Sample1.mot source file that includes the flash-memory reprogram processing 4 Sample1.c Sample1.mot source file that includes the function for lighting and blinking the LEDs 5 io_2612.h Include file that defines the on-chip I/O register. This file has been included from HCAN_up.c and Sample.c. 6 Sample1.bat DOS prompt batch file that compiles and links the program. 7 Hew2.hws Hew project file that compiles and links the program. Rev. 1.0, 03/03, page 22 of 78 Section 6 Example of Creating Application (Sample) Program 6.1 Functions and Variables 1. List of Functions Source name: HCAN_up.c Abbreviation Module Name Description PowerON_Reset Power-on reset processing Performs initialization. This function checks whether the H command (0x48) is received, and then switches the user program processing and sample program. UserProgramMode_Main User program processing Transfers the program/erase control program. InitHCAN Initializes HCAN communication. HCAN initialization CAN_MB5_trs1byte Transmitting CAN one-byte Transmits data (HCAN communication). CAN_MB4_rcv1byte Receiving CAN one-byte Receives data (HCAN communication). Abbreviation Module Name Description UserApli LED display switching Checks the parameters and controls the LEDs (lights or blinks all LEDs). Source name: Sample1.c 2. Variables All the variables in use are internal variables. Rev. 1.0, 03/03, page 23 of 78 6.2 Example of Changing CAN Communication Settings 1. Change the bit rate from 1000 kbit/s to 500 kbit/s. In (1) HCAN.BCR.WORD = 0x0034;, change 0x0034 to 0x0134;. The baud rate prescaler is set to 4 system clocks, and the bit rate is set to 500 kbit/s. See the register description for BCR in the hardware manual. 2. Change the data length from 1 byte to 8 bytes. In (2) HCAN.MC[4][1-1] = 0x01;, change 0x01; to 0x08;. The receive data length is set to 8 bytes. In (5) HCAN.MC[5][1-1] = 0x01;, change 0x01; to 0x08;. The transmit data length is set to 8 bytes. See the register description for MC0 to MC15 in the hardware manual. 3. Change the receive mailbox ID from 0x0602 to 0x0005. In (3) HCAN.MC[4][5-1] = 0x20;, change 0x20; to 0xA0;. In (4) HCAN.MC[4][6-1] = 0x7F;, change 0x7F; to 0x00;. The receive mailbox ID (ID28 to ID18) is set to 0x0005. In (6) HCAN.MC[5][5-1] = 0x40;, change 0x40; to 0x80;. In (7) HCAN.MC[5][6-1] = 0xC0;, change 0xC0; to 0x00;. The transmit mailbox ID (ID28 to ID18) is set to 0x0004. See the register description for MC0 to MC15 in the hardware manual. Rev. 1.0, 03/03, page 24 of 78 Program lists (1) to (3) Source name: HCAN_up.c Module name: InitHCAN /*****************************************************************************************/ /* HCAN initialization */ /* • Baud rate 1000kbps, TSEG1=4,TSEG2=3,BRP=0,SJW=0 */ /* • MB4: Receiving “flash-memory reprogram request” [ID(11bit):03F9] */ /* • MB5: Transmitting “flash-memory reprogram response” [ID(11bit):0602] */ /* Remarks: Since communication will take place during operation in RAM, set program to */ /* prohibit any interrupt. */ /*****************************************************************************************/ void InitHCAN( void ) { int i, j; /* Loop counter */ /* Clear HCAN module stop bit (MSTPCRC) */ System.MSTPCRC.BIT.HCANCKSTP = 0; (1) HCAN.BCR.WORD = 0x0034; →0x0134; /* 1000-kbps (at 20 MHz) baud rate setting HCAN.MBCR.WORD MB4=Rcv */ = 0x1100; */ /* Transmission and reception setting for mailboxes /* Clear MC [4-5] [0-7] and MD [4-5] [0-7] to all 0 */ for ( j = 4; j <= 5; j++ ) { for ( i = 0; i < 8; i++ ) { HCAN.MC[j][i] = 0x00; /* MC[4][0] to MC[5][7] */ HCAN.MD[j][i] = 0x00; /* MD[4][0] to MD[5][7] */ } } HCAN.MCR.BYTE = 0x04; /* Transmission method: Order of mailboxes */ while ( HCAN.GSR.BIT.GSR3 == 1 ); /* While not in HCAN normal mode */ /* Enter HCAN normal mode */ /* Settings for mailbox 4 (receive: flash-memory reprogram request) */ (2) HCAN.MC[4][1-1] = 0x01; →0x08; HCAN.MC[4][5-1] = 0x00; /* MB4 data length = 1 byte */ /* */ Data frame, standard format (3) HCAN.MC[4][5-1] = 0x20; →0xA0; /* ID: x xxxx xxx0 01-- ---- ---- ---- ---- */ (4) HCAN.MC[4][6-1] = 0x7F; →0x00; /* ID: 0 1111 111x xx-- ---- ---- ---- ---- */ /* Settings for mailbox 5 (transmit: flash-memory reprogram response) */ (5) HCAN.MC[5][1-1] = 0x01; →0x08; HCAN.MC[5][5-1] = 0x00; /* MB5 data length = 1 byte */ /* */ Data frame, standard format (6) HCAN.MC[5][5-1] = 0x40; →0x80; /* ID: x xxxx xxx0 10-- ---- ---- ---- ---- */ (7) HCAN.MC[5][6-1] = 0xC0; →0x00; /* ID: 1 1000 000x xx-- ---- ---- ---- ---- */ } Rev. 1.0, 03/03, page 25 of 78 6.3 Example of Changing Receive and Transmit Mailbox Numbers for CAN Communications Change the receive and transmit mailbox numbers (change [4] to [14] for the receive mailbox, and [5] to [15] for the transmit mailbox). 1. Change the transmit/receive direction of the mailbox. In (1) HCAN.MBCR.WORD = 0x1100; change 0x1100; to 0x0140;. Only MBCR14 is set to 1, and only mailbox 14 is set for reception. See the register description for MBCR in the hardware manual. 2. Change the initialization for the mailbox. In (2), change for(j=4;j<=5;j++) to for(j=14;j<=15;j++){. Only mailboxes 14 and 15 will be initialized. See the register description for MC0 to MC15 and MD0 to MD15 in the hardware manual. 3. Change the settings for the mailbox. In (3) to (6), change HCAN.MC[4] to HCAN.MC[14]. In (7) to (10), change HCAN.MC[5] to HCAN.MC[15]. The receive mailbox [14] and transmit mailbox [15] are set. See the register description for MC0 to MC15 in the hardware manual. 4. Change the trigger receive processing. In (11), change if(HCAN.RXPR.BIT.RXPR4==1){ to if(HCAN.RXPR.BIT.RXPR14==1){. See the register description for RXPR in the hardware manual. 5. Change the receive processing. In (12), change while(HCAN.RXPR.BIT.RXPR4==0); to while(HCAN.RXPR.BIT.RXPR14==0);. In (13) HCAN.RXPR.WORD=0x1000;, change 0x1000; to 0x0040;. In (14), change return HCAN.MD[4][0] to return HCAN.MD[14][0];. See the register description for RXPR and MD0 to MD15 in the hardware manual. 6. Change the transmit processing. In (15), change HCAN.MD[5][0] to HCAN.MD[15][0]. In (16), change HCAN.TXPR.BIT.TXPR5 to HCAN.TXPR.BIT.TXPR15. In (17), change while(HCAN.TXPR.BIT.TXPR5==0); to while(HCAN.TXPR.BIT.TXPR15==0);. In (18) HCAN.TXACK.WORD=0x2000;, change 0x2000; to 0x0080;. See the register description for MD0 to MD15, TXPR, and TXACK in the hardware manual. Rev. 1.0, 03/03, page 26 of 78 Program lists (1) to (3) Source name: HCAN_up.c Module name: InitHCAN /*****************************************************************************************/ /* HCAN initialization */ /* • Baud rate: 1000kbps, TSEG1=4,TSEG2=3,BRP=0,SJW=0 */ /* • MB4: Receiving “flash-memory reprogram request” [ID(11bit):03F9] */ /* • MB5: Transmitting “flash-memory reprogram response“ [ID(11bit):0602] */ /* Remarks: Since communication will take place during operation in RAM, set program to */ /* prohibit any interrupt. */ /*****************************************************************************************/ void InitHCAN( void ) { int i, j; /* Loop counter */ /* Clear HCAN module stop bit (MSTPCRC)*/ System.MSTPCRC.BIT.HCANCKSTP = 0; HCAN.BCR.WORD = 0x0034; /* 1000-kbps (at 20 MHz) baud rate setting */ (1) HCAN.MBCR.WORD = 0x1100; →0x0140; /* Transmission and reception setting for mailboxes MB4=Rcv */ /* Clear MC [4-5] [0-7] and MD [4-5] [0-7] to all 0 */ (2) for ( j = 4; j <= 5; j++ ) { →for ( j = 14; j <= 15; j++ ) for ( i = 0; i < 8; i++ ) { HCAN.MC[j][i] = 0x00; /* MC[4][0] to MC[5][7] */ HCAN.MD[j][i] = 0x00; /* MD[4][0] to MD[5][7] */ } } HCAN.MCR.BYTE = 0x04; /* Transmission method: Order of mailboxes */ while ( HCAN.GSR.BIT.GSR3 == 1 ); /* While not in HCAN normal mode */ /* Enter HCAN normal mode */ /* Settings for mailbox 4 (receive: flash-memory reprogram request) */ (3) HCAN.MC[4] → [14] [1-1] = 0x01; /* MB4 data length = 1 byte */ (4) HCAN.MC[4] → [14] [5-1] = 0x00; /* */ (5) HCAN.MC[4] → [14] [5-1] = 0x20; /* ID: x xxxx xxx0 01-- ---- ---- ---- ---- */ (6) HCAN.MC[4] → [14] [6-1] = 0x7F; /* ID: 0 1111 111x xx-- ---- ---- ---- ---- */ Data frame, standard format /* Settings for mailbox 5 (transmit: flash-memory reprogram response) */ (7) HCAN.MC[5] → [15] [1-1] = 0x01; /* MB5 data length = 1 byte */ (8) HCAN.MC[5] → [15] [5-1] = 0x00; /* */ (9) HCAN.MC[5] → [15] [5-1] = 0x40; /* ID: x xxxx xxx0 10-- ---- ---- ---- ---- */ (10)HCAN.MC[5] → [15] [6-1] = 0xC0; /* ID: 1 1000 000x xx-- ---- ---- ---- ---- */ Data frame, standard format } Rev. 1.0, 03/03, page 27 of 78 Program list (4) Source name: HCAN_up.c Module name: PowerOn_Reset /*****************************************************************************************/ /* Power-on reset processing */ /* Waiting for trigger for entering user program mode (receiving H command) */ /* Switching between sample program and user program mode */ /*****************************************************************************************/ #pragma section _BOOT /* Section name "P_BOOT" */ void PowerON_Reset(void){ /* Power-on reset (vector number 0) handler */ volatile unsigned char LatchMDCR; unsigned char Data; LatchMDCR = System.MDCR.BYTE; /* Latch MD2 to MD0 */ /* Prohibit interrupt */ set_imask_ccr(1); set_imask_exr(7); HCAN.IRR.WORD = 0x0100; /* Write 1 to IRR0 and clear to 0 */ InitHCAN(); /* User program */ Data = 0x00; PORT.PDDDR.BYTE = 0xFF; /* Initialize LEDs */ PORT.PDDR.BYTE = 0xFF; while(Data != 'H'){ /* H command? */ (11) if(HCAN.RXPR.BIT.RXPR4 →RXPR14 == 1){ /* Has any data been received? */ Data = CAN_MB4_rcv1byte(); }else{ UserApli(); /* Sample program */ } } PORT.PDDR.BYTE = 0xFF; /* Turn off LEDs */ UserProgramMode_Main(); sleep(); } Rev. 1.0, 03/03, page 28 of 78 /* (Do not come here) */ Program list (5) Source name: HCAN_up.c Module name: CAN_MB4_rcv1byte /*****************************************************************************************/ /* Receive CAN one-byte */ /*****************************************************************************************/ unsigned char CAN_MB4_rcv1byte( void ){ (12) while( HCAN.RXPR.BIT.RXPR4 →RXPR14 == 0 ); /* Wait for MB4 to complete receiving */ if( (HCAN.IRR.WORD & 0x1802) != 0 ){ while(1); /* Infinite loop */ } (13) HCAN.RXPR.WORD = 0x1000; →0x0040; /* Clear receive flag */ (14) return HCAN.MD[4] → [14] [0]; /* Receive one byte from MD4 */ } Program list (6) Source name: HCAN_up.c Module name: CAN_MB5_trs1byte /*****************************************************************************************/ /* Receive CAN one-byte */ /*****************************************************************************************/ void CAN_MB5_trs1byte( unsigned char TrsData ){ (15) HCAN.MD[5] → [15] [0] = TrsData; /* Set one byte of transmit data to MD5 */ (16) HCAN.TXPR.BIT.TXPR5 →TXPR15 /* Start transmission */ |= 1; (17) while( HCAN.TXPR.BIT.TXPR5 →TXPR15 == 0 );/* Wait for completion of transmission */ if( (HCAN.IRR.WORD & 0x1802) != 0 ){ while(1); /* Infinite loop */ } (18) HCAN.TXACK.WORD = 0x2000; →0x0080; /* Transmission completed */ } Rev. 1.0, 03/03, page 29 of 78 6.4 Application (Sample) Program Flowchart Restart Mode latch processing Prohibit interrupts Initialize H-CAN communication settings Initialize LEDs Is receive data H command? Yes No Has data been received? Data receive processing No Is receiving completed? Yes Sample program No Does IRR error occur? User program processing Is parameter 0x00? Yes Yes Infinite loop No ACK transmission Receive upper one byte of program size Turn on all LEDs No Turn off all LEDs Echoback processing Wait processing Receive lower one byte of program size Turn on all LEDs Echoback processing Is transfer of program size completed? No Yes Receive program RAM transfer processing Echoback processing Jump to RAM Rev. 1.0, 03/03, page 23 of 78 Section 7 Example of Creating Program/Erase Control Program 7.1 Overview The following describes the calculation of the application time for the erase (E) and program (P) bits, and the wait time for the SWE bit. The parenthesized value indicates the unit. ! Calculation methods 1. Time required for one cycle = 1 (sec) ÷ target clock (MHz) 2. Time required for one loop = Time required for one cycle (µs) × number of cycles required for one loop 3. Wait time = Target clock (MHz) × stipulated wait time (µs) 4. Wait loop count = Wait time ÷ time required for one loop 5. Wait time other than after setting of the P or E bit = Wait loop count + 1 (Since this wait time must be equal to or greater than the stipulated wait time, add 1 to the wait loop count obtained by the calculation.) 6. Wait time after setting of the P or E bit = Wait loop count (Since this wait time must be equal to or smaller than the stipulated wait time, use the wait loop count obtained by the calculation.) ! Expressions The following shows examples of calculating the wait time: Prerequisites: Target clock = 20 (MHz) Number of cycles required for one loop = 4 (cycles) Example 1: Obtain the wait time after the clearing of the SWE bit (100 µs or longer). 1. 20 (MHz) × 1000* = 20000 (kHz) 2. 20000 (kHz) × 100 (µs) = 2000000 3. 2000000 ÷ 4 (cycles) × 1000* = 500 (times) 4. 500 (times) + 1 (time) = 501 (times) 5. WLOOP100 = 501 6. Time required for one cycle: 1 (sec) ÷ 20 (MHz) = 0.05 (µs) 7. Time required for one loop: 0.05 (µs) × 4 (cycles) = 0.2 (µs) 8. Wait loop time: 0.2 (µs) × 501 (times) = 100.2 (µs) Example 2: Obtain the wait time after the setting of the E bit (within 10 ms). 1. 20 (MHz) × 1000* = 20000 (kHz) 2. 10000 (µs) ÷ 1000* = 10 (ms) Rev. 1.0, 03/03, page 31 of 78 3. 20000 (kHz) × 10 (ms) = 200000 4. 200000 ÷ 4 (cycles) = 50000 (times) 5. WTIME10000 = 50000 6. Time required for one cycle: 1 (sec) ÷ 20 (MHz) = 0.05 (µs) 7. Time required for one loop: 0.05 (µs) × 4 (cycles) = 0.2 (µs) 8. Wait loop time: 0.2 (µs) × 50000 (times) = 10000 (µs) = 10 (ms) Note: * To minimize error, the above examples convert the unit of frequency from MHz to kHz to use the thousandfold values in calculation. Then, the results are divided by 1000 to obtain the correct count. 1. Erasing Flash Memory (1) Erase Erase functionality erases the flash memory block by block. To use erase, set 1 to the SWE bit in the flash memory control register (FLMCR), and then use the erase block register (EBR) to set one bit of the area in the flash memory to be erased. Then, set the ESU bit in FLMCR to prepare for erase mode (erase mode setup), and set the E bit in FLMCR to shift the operating mode to erase mode. The period of time during which the E bit is set is the erase time. After the erase time has elapsed, clear the E, ESU, and SWE bits in FLMCR to cancel erase mode. (2) Erase-Verify Erase-verify functionality verifies whether the flash memory has been erased successfully. To use erase-verify, set the SWE bit and then the EV bit in FLMCR to shift the operating mode to erase-verify mode. Before the flash memory is read in erase-verify mode, a dummy writing of data (H′FF) is performed on the address to be read. When the flash memory is subsequently read (the verify data is read in 16-bit units), the data at the latched address is read. If the read data has been erased (that is, all data is 1), a dummy writing of the next data is performed. Then erase-verify is performed for the next data. Upon completion of the verify operation, clear the EV and SWE bits in FLMCR to cancel eraseverify mode. The following shows the wait time for each bit in FLMCR for erasing the flash memory. Rev. 1.0, 03/03, page 32 of 78 Table 7.1 FLMCR Bits and Wait Time for Erasing Flash Memory Set or Clear Each Bit Wait Time (Standard Value) Wait Time at 20 MHz SWE set 1 µs or greater 1.2 µs ESU set 100 µs or greater 100.2 µs E set Up to 10 ms 10.0 ms E cleared 10 µs or greater 10.2 µs ESU cleared 10 µs or greater 10.2 µs EV set 20 µs or greater 20.2 µs Dummy write 2 µs or greater 2.2 µs EV cleared 4 µs or greater 4.2 µs SWE cleared 100 µs or greater 100.2 µs Maximum count 100 times 100 times 2. Programming Flash Memory (1) Program Program functionality programs data to the flash memory. One program is performed in 128-byte units. To use program, set 1 to the SWE bit in the flash memory control register (FLMCR). Then, the system stores the 128-byte program data in the program data area and reprogram data area, and then sequentially programs 128 bytes of data from the program data area in RAM to the target address (that is, byte-by-byte data transfer is sequentially performed 128 times). Note that the lower eight bits of the target start address must be H′00 or H′80. The program address and program data are latched in the flash memory. A program of data of less than 128 bytes also requires a transfer of 128-byte data, for which data H′FF must be programmed to unnecessary address. Then, set the PSU bit in FLMCR to prepare for program mode (program mode setup), and set the P bit in FLMCR to shift the operating mode to program mode. The period of time during which the P bit is set is the program time for the flash memory. After the program time has elapsed, clear the P, PSU, and SWE bits in FLMCR to cancel program mode. (Note that an additional program is performed for the programmed bits for up to the sixth initial program.) (2) Program-Verify Program-verify functionality verifies whether the flash memory has been programmed successfully. Set the SWE bit and then the PV bit in FLMCR to shift the operating mode to program-verify mode. Rev. 1.0, 03/03, page 33 of 78 Before the flash memory is read in program-verify mode, a dummy writing of data (H′FF) is performed on the address to be read. When the flash memory is subsequently read (the verify data is read in 16-bit units), the data at the latched address is read. Then, the system compares the programmed data with the verify data, calculates the reprogram data, and then transfers the reprogram data to the reprogram data area. Upon completion of the verification of the data of 128 bytes, clear the PV and SWE bits in FLMCR to cancel program-verify mode. The following shows the wait time for each bit in FLMCR for programming the flash memory. (Note that additional program data is calculated and transferred to the additional program data area for up to the sixth initial program.) Table 7.2 FLMCR Bits and Wait Time for Programming Flash Memory Set or Clear Each Bit Wait Time (Standard Value) Wait Time at 20 MHz SWE set 1 µs or greater 1.2 µs PSU set 500 µs or greater 50.2 µs P set (1st to 6th) (1st to 6th) additional (7th to 1000th) Up to 30 µs Up to 10 µs Up to 200 µs 30.0 µs 10.0 µs 200.0 µs P cleared 5 µs or greater 5.2 µs PSU cleared 5 µs or greater 5.2 µs PV set 20 µs or greater 20.2 µs Dummy write 2 µs or greater 2.2 µs PV cleared 2 µs or greater 2.2 µs SWE cleared 100 µs or greater 100.2 µs Maximum count 1000 times 1000 times Rev. 1.0, 03/03, page 34 of 78 7.2 1. Functions, Variables, and Constants Functions Source name: HCAN2612f3.src Abbreviation Module Name Description MAIN Main processing Receives the initialization target clock for the stack, receives a check command, and performs check. (W and C commands) WLOOP_INI Wait loop initialization processing Initializes the wait loop. WAITLOOP_CAL Wait loop calculation main Calculates and sets the wait loop. processing WLOOP_CAL Wait loop calculation processing Calculates the wait loop. WCMD W command processing Performs erase processing, program processing, and checksum processing GET_EADR Erase address receive processing Receives the start address of the erase block. BLK_CHECK Specified block check processing Checks the specified block. GET_WADR Program address receive Receives the program address (four bytes). processing GET_BUFFER Program data receive processing Receives the program data (128 bytes). RCVNBYTE N-byte receive processing Receives N bytes of data. RCV1BYTE One-byte receive processing Receives one byte of data. TRS1BYTE One-byte transmit processing Transmits one byte of data. XON_CHECK XON check processing Checks a response during program processing. FWRITE128 Flash memory 128-byte program processing Performs: Initial program and verify (for the first to the sixth program). Initial program, and program-verify (before the program). Additional program (for the first to the sixth program). Reprogram and program-verify (for the 7th to the 1000th program). Rev. 1.0, 03/03, page 35 of 78 Abbreviation Module Name Description FWRITEVF Program-verify processing Performs program-verify, creates reprogram data, and creates additional program data. FWRITE Flash memory program processing Programs data to the flash memory. BLK1_ERASE One-block erase processing Checks the specified block. Performs initial erase-verify (before the erasing). Erases data, and performs erase-verify (for the first to the 100th erase). FERASEVF Erase-verify processing Performs erase-verify. FERASE Flash memory erase processing Erases the flash memory. CHECKSUM Checksum processing Calculates and transmits the checksum value (four bytes). Abbreviation Variable Name Description Size W_ADR Program address Stores the program address. 4 bytes W_BUF Program buffer Stores the program data. 128 bytes BUFF Buffer Stores the reprogram data. 128 bytes OWBUFF Additional program buffer Stores the additional program data. 128 bytes COUNT Counter Counter for the number of times the erase count is programmed to the counter 2 bytes EVF_ST Erase start address Stores the start address of the erase block. 4 bytes EVF_ED Erase end address Stores the end address of the erase block. 4 bytes BLK_NO Erase specification block Stores the erase specification block No. number. VF_RET Verification result flag Result of erase-verify and program-verify 1 byte RESTSIZE Program data size Stores the program data size. 4 bytes E_ADR Erase block address Stores the erase block address. 64 bytes E_ADR_PTR Erase block address pointer Pointer to the erase block address. 4 bytes WORKCLK Clock Stores the target clock. 4 bytes ERASEBLOCK Erase block count Stores the number of erase blocks. 1 byte WLOOP1 Wait 1 µ Stores the loop count for the 1 µs wait. 2 bytes WLOOP2 Wait 2 µ Stores the loop count for the 2 µs wait. 2 bytes 2. Variables Rev. 1.0, 03/03, page 36 of 78 1 byte Abbreviation Variable Name Description Size WLOOP4 Wait 4 µ Stores the loop count for the 4 µs wait. 2 bytes WLOOP5 Wait 5 µ Stores the loop count for the 5 µs wait. 2 bytes WLOOP10 Wait 10 µ Stores the loop count for the 10 µs wait. 2 bytes WLOOP20 Wait 20 µ Stores the loop count for the 20 µs wait. 2 bytes WLOOP50 Wait 50 µ Stores the loop count for the 50 µs wait. 2 bytes WLOOP100 Wait 100 µ Stores the loop count for the 100 µs wait. 2 bytes WTIME10 Program wait 10 µ Stores the loop count for the 10 µs wait during an additional program. 4 bytes WTIME30 Program wait 30 µ Stores the loop count for the 30 µs wait during an initial program. 4 bytes WTIME200 Program wait 200 µ Stores the loop count for the 200 µs wait 4 bytes during a reprogram. WTIME1000 Erase wait loop 10 m Stores the loop count for the 10 ms wait during erasing. 4 bytes Rev. 1.0, 03/03, page 37 of 78 7.3 Example of Changing Receive and Transmit Mailbox Numbers for CAN Communications Change the receive and transmit mailbox numbers (change [4] to [14] for the receive mailbox, and [5] to [15] for the transmit mailbox). 1. Change the registers and bits. Add the following definitions for the registers and bits in (1) to (9): (1) RXPR14_MOV .EQU H′0040 (2) RXPR_L .EQU H′FFF80F (3) RXPR14 .EQU 6 (4) MD14_0 .EQU H′FFF920 (5) MD15_0 .EQU H′FFF928 (6) TXPR_L .EQU H′FFF807 (7) TXPR15 .EQU 7 (8) TXACK15 .EQU 7 (9) TXACK15_MOV .EQU H′0080 See the register description for RXPR, TXPR, TXACK, and MD0 to MD15 in the hardware manual. 2. Change the settings of receive processing. In (10) and (11), change RXPR4 to RXPR14. In (10), change RXPR to RXPR_L. In (12), change MD4_0 to MD14_0. In (13), change RXPR4_MOV to RXPR14_MOV. See the register description for RXPR and MD0 to MD15 in the hardware manual. 3. Change the settings of transmit processing. In (14), change MD5_0 to MD15_0. In (15) and (17), change TXPR to TXPR_L. In (16), (18), and (19), change TXPR5 to TXPR15. In (20), change TXACK5_MOV to TXACK15_MOV. See the register description for TXPR, TXACK, and MD0 to MD15 in the hardware manual. Rev. 1.0, 03/03, page 38 of 78 Program list (1) Source name: HCAN2612f3.src Module name: Data ; HCAN RXPR RXPR4: RXPR4_MOV: .EQU H'FFF80E .EQU 4 .EQU H'1000 (1) RXPR14_MOV .EQU H’0040 (2) RXPR_L .EQU H’FFF80F (3) RXPR14 .EQU 6 MD4_0 .EQU H'FFF8D0 MD5_0 .EQU H'FFF8D8 (4) MD14_0 .EQU H’FFF920 (5) MD15_0 .EQU H’FFF928 TXPR .EQU H'FFF806 .EQU 5 (6) TXPR_L .EQU H’FFF807 (7) TXPR15 .EQU 7 TXPR5: TXACK .EQU H'FFF80A TXACK5: .EQU 5 TXACK5_MOV: .EQU H'2000 (8) TXACK15 .EQU 7 (9) TXACK15_MOV .EQU H’0080 IRR .EQU H'FFF812 .EQU H'1802 IRR_ERR: ; Receive complete register (16 bits) ; Receive complete register (lower 8 bits) ; Transmit wait register (lower 8 bits) ; Transmit acknowledge register Rev. 1.0, 03/03, page 39 of 78 Program list (2) Source name: HCAN2612f3.src Module name: RCV1BYTE ;***************************************************************************************** ; * TITLE / H-CAN 1 BYTE DATA RECEPTION * ; * FUNCTION / RECEIVE 1 BYTE DATA * ; * INPUT / - * ; * OUTPUT / R2L = RECEIVED DATA * ;***************************************************************************************** RCV1BYTE .EQU $ SUB.W R0,R0 (10) BLD.B #RXPR4,@RXPR →#RXPR14,@RXPR_L (11) BST.B #RXPR4 →#RXPR14,R0L MOV.W R0,R0 BEQ RCV1BYTE MOV.W @IRR,R0 AND.W #IRR_ERR,R0 BNE RCV_ERR MOV.B @MD4_0 →@MD14_0,R2L MOV.W #RXPR4_MOV →#RXPR14_MOV,R0 MOV.W R0,@RXPR ; ; ERROR CHECK ; (12) ; RECEIVE DATA TO R0H ; (13) ; RXPR4 CLEAR RTS ; RCV_ERR BRA RCV_ERR ; Rev. 1.0, 03/03, page 40 of 78 ; INFINITE LOOP Program list (3) Source name: HCAN2612f3.src Module name: TRS1BYTE ;***************************************************************************************** ; * TITLE / H-CAN 1 BYTE DATA TRANSMISSION * ; * FUNCTION / SEND 1 BYTE DATA * ; * INPUT / R2L = SEND DATA * ; * OUTPUT / - * ;***************************************************************************************** TRS1BYTE. EQU $ (14) MOV.B R2L,@MD5_0 →@MD15_0 (15) MOV.W @TXPR →@TXPR_L,R0 (16) BSET.B #TXPR5 →#TXPR15,R0H (17) MOV.W R0,@TXPR →@TXPR_L TRS_WAIT SUB.W R0,R0 (18) BLD.B #TXPR5, →#TXPR15 @TXPR (19) BST.B #TXPR5, →#TXPR15 R0H MOV.W R0,R0 BNE TRS_WAIT MOV.W @IRR,R0 AND.W #IRR_ERR,R0 BNE TRS_ERR MOV.W #TXACK5_MOV →#TXACK15_MOV,R0 MOV.W R0,@TXACK ; TRANSMIT R2L DATA TO MD5_0 ; ; SET TXPR5 ; ; ; ERROR CHECK ; (20) ; CLEAR TXACK5 RTS ; TRS_ERR BRA TRS_ERR ; INFINITE LOOP ; Rev. 1.0, 03/03, page 41 of 78 7.4 Program/Erase Program Flowchart Restart Set stack Receive target clock Is clock smaller than minimum? (4 bytes) Yes No Is clock smaller than maximum? Yes No BELL transmission (1 byte) Infinite loop Receive command (1 byte) Is received data W command? Yes No See the W command processing next page. Is received data C command? Yes No Checksum calculation Has calculation been done for all blocks? No Yes Checksum transmission Rev. 1.0, 03/03, page 42 of 78 (4 bytes) W command processing Receive number of erase blocks (1 byte) Is number of erase blocks 0? No Flash memory erase processing Receive erase block address Yes (4 bytes × erase block count) Check blocks Does block check error occur? Yes No Erase one block Does erase error occur? Yes No Is processing completed for number of erase blocks? Yes No Flash memory program processing Transmit ACK Receive program address and program size Is address or size error found? (1 byte) (Program address: 4 bytes) (Program size: 4 bytes) Yes No BELL transmission One-block program processing See the next page. (1 byte) Infinite loop Rev. 1.0, 03/03, page 43 of 78 One-block program processing XON transmission Data reception Is received data ACK? (1 byte) (1 byte) Yes No Is received data XON? No Yes Receive program data (128 bytes) Program 128 kbytes Does program error occur? Yes No Is processing completed for program size? No Yes XON transmission Data reception Is received data ACK? (1 byte) (1 byte) Yes No Is received data XON? No Yes Checksum reception (one block) (1 byte) (1 byte) BELL transmission Sumcheck processing Does sumcheck error occur? No Return Rev. 1.0, 03/03, page 44 of 78 Yes Infinite loop Section 8 Functions and Operations of On-Board Programming Tool and SCI-HCAN Communication Conversion Program For details on the on-board programming tool, see the F-ZTAT Microcomputer On-Board Writing Program Manual. 8.1 Installing On-Board Programming Tool 1. Start Setup.exe. 2. Select the language you want to use and click the OK button. (Click the Cancel button to cancel the installation of the tool.) (Click the Cancel button to cancel the installation of the tool.) Rev. 1.0, 03/03, page 45 of 78 3. Click the Next button to continue the installation of the tool. (Click the Cancel button to display the Confirm dialog box to cancel the installation of the tool.) 4. Select the destination folder where you want to install the tool. (To change the destination folder, click the Browse button to select another folder.) Rev. 1.0, 03/03, page 46 of 78 5. Click the Next button. (Click the Back button to return to step 3.) (Click the Cancel button to display the Confirm dialog box to cancel the installation of the tool.) 6. Select a program folder and click the Next button. (Click the Back button to return to step 3.) (Click the Cancel button to display the Confirm dialog box to cancel the installation of the tool.) Rev. 1.0, 03/03, page 47 of 78 7. The setup status of the tool appears. (Click the Cancel button to display the Confirm dialog box to cancel the installation of the tool.) 8. The wizard appears to indicate the completion of the installation. Click the Finish button. Now, the on-board programming tool is installed completely. Rev. 1.0, 03/03, page 48 of 78 Select the Start, Programs, and FlashCAN menu, and then the FlashCAN shortcut menu to start the on-board programming tool. • Confirm dialog box to cancel the installation of the tool Click the Yes button to cancel the installation of the tool. Click the No button to continue the installation. • Confirm dialog box to uninstall the tool Start Setup.exe to uninstall the installed tool. Click the OK button and follow the wizard to uninstall the tool. Click the Cancel button to cancel the uninstallation of the tool. Rev. 1.0, 03/03, page 49 of 78 8.2 First Programming of Application (Sample) Program to Target Board 1. Use the serial cable to connect the personal computer to the target board. (In this application note, the serial cable is connected to COM1.) 2. Turn the target board on. 3. Place the target board in boot mode. 4. Start FlashCAN.exe. The version information (for a working sample) appears. 5. Click the OK button to display the main window. 6. Click the Select button to select a microcomputer in the Select File dialog box. Rev. 1.0, 03/03, page 50 of 78 7. Select the SCI2612f3.inf file. 8. Click the Open button to return to the main window. (Click the Cancel button to return to the main window without selecting a file.) Rev. 1.0, 03/03, page 51 of 78 9. Click the Change/Set button for the clock and bit rate to make settings. 10. Set the input clock to 20.0000 MHz. The input clock can be set between 4 MHz and 20 MHz as specified in the SCI2612F3.inf file. 11. Select 1 for the clock ratio. The clock ratio can be selected from among 1, 2, and 4 as specified in the SCI2612F3.inf file. 12. Select 57600 bit/s (bit rate) for the serial communication. The bit rate can be selected from among 2400, 4800, 9600, 19200, 38400, 57600, 115200, and None. 13. Select COM1 for the serial port. Either COM1 or COM2 can be selected. Alternatively, you can directly enter any serial port name. 14. Set the timeout value to 5. The timeout value can be set between 1 and 300. Rev. 1.0, 03/03, page 52 of 78 15. Click the OK button to return to the main window. (Click the Cancel button to return to the main window without changing the settings.) 16. Click the Change/Set button for Erase before write to make settings. Rev. 1.0, 03/03, page 53 of 78 17. Select the write data file Sample1.mot. Click the Search button to select a file in the Select File dialog box. 18. Select 0x00000000 for the start address. The start address can be selected from among 000000, 000400, 000800, 000C00, 001000, 008000, 00C000, 00E000, 010000, and 018000 as specified in the SCI2612F3.inf file. Alternatively, you can directly enter the start address between 000000 and 01FFFE. 19. Select 0x0001FFFF for the end address. The end address can be selected from among 0003FF, 0007FF, 000BFF, 000FFF, 007FFF, 00BFFF, 00DFFF, 00FFFF, 017FFF, and 018FFF as specified in the SCI2612F3.inf file. Alternatively, you can directly enter the end address between 000001 and 01FFFF. 20. Set the offset to 0x00000000. The offset can be set between 000000 and 01FFFF as specified in the SCI2612F3.inf file. 21. Click the OK button to return to the main window. (Click the Cancel button to return to the main window without changing the settings.) 22. Now, all the settings are made completely. Click the Start button. Rev. 1.0, 03/03, page 54 of 78 23. The Start dialog box appears. Restart the target board. 24. Click the OK button to start processing. (Click the Cancel button to return to the main window.) 25. The status of the boot processing appears. (Click the Stop button to stop the boot processing and return to the main window.) 26. The status of the write processing appears. (Click the Stop button to stop the write processing and return to the main window.) 27. The processing completes and the checksum appears. Rev. 1.0, 03/03, page 55 of 78 28. Confirm the checksum and click the OK button to return to the main window. Now, the application (sample) program is completely programmed into the target board for the first time. Restarting the target board initiates the application (sample) program. Since the parameter is set to 0xFF, all the LEDs light up. 8.3 Programming SCI-HCAN Communication Conversion Program to SCI-HCAN Communication Conversion Board 1. Use the serial cable to connect the personal computer to the SCI-HCAN communication conversion board. (In this application note, the serial cable is connected to COM1.) 2. Turn the SCI-HCAN communication conversion board on. 3. Place the SCI-HCAN communication conversion board in boot mode. 4. Follow steps 4 to 16 in section 8.2, First Programming of Application (Sample) Program to Target Board. 5. Select the write data file SCItoCAN.mot in step 17 in section 8.2. Rev. 1.0, 03/03, page 56 of 78 6. Follow steps 18 to 21 in section 8.2. 7. Now, all the settings are made completely. Click the Start button. 8. The Start dialog box appears. Restart the SCI-HCAN communication conversion board. Rev. 1.0, 03/03, page 57 of 78 9. Click the OK button to start processing. (Click the Cancel button to return to the main window.) 10. The status of the boot processing appears. (Click the Stop button to stop the boot processing and return to the main window.) 11. The status of the write processing appears. (Click the Stop button to stop the write processing and return to the main window.) 12. The processing completes and the checksum appears. 13. Confirm the checksum and click the OK button to return to the main window. Now, the SCI-HCAN communication conversion program is completely programmed into the SCI-HCAN communication conversion board. Restarting the SCI-HCAN communication conversion board initiates the SCI-HCAN communication conversion program. Rev. 1.0, 03/03, page 58 of 78 8.4 Reprogramming Flash Memory in User Program Mode 1. Use the serial cable to connect the personal computer to the SCI-HCAN communication conversion board. (In this application note, the serial cable is connected to COM1.) 2. Use the CAN cable to connect the target board to the SCI-HCAN communication conversion board. 3. Turn the SCI-HCAN communication conversion board on. 4. Turn the target board on. 5. Place the SCI-HCAN communication conversion board in user mode. 6. Place the target board in user mode (by resetting the target board). 7. Start FlashCAN.exe. The version information (for a working sample) appears. 8. Click the OK button to display the main window. The preset contents appear in the main window. Rev. 1.0, 03/03, page 59 of 78 9. Click the Select button to select a microcomputer in the Select File dialog box. 10. Select the HCAN2612f3.inf file. 11. Click the Open button to return to the main window. (Click the Cancel button to return to the main window without selecting a file.) 12. Click the Change/Set button for the clock and bit rate to make settings. Rev. 1.0, 03/03, page 60 of 78 13. Set the input clock of the target board to 20.0000 MHz. The input clock can be set between 4 MHz and 20 MHz as specified in the HCAN2612F3.inf file. 14. Set the transmit mailbox ID to 0x03F9. The transmit mailbox ID can be set between 0000 and 07EF. Rev. 1.0, 03/03, page 61 of 78 15. Set the receive mailbox ID to 0x0602. The receive mailbox ID can be set between 0000 and 07EF. 16. Select COM1 for the serial port. Either COM1 or COM2 can be selected. Alternatively, you can directly enter any serial port name. Rev. 1.0, 03/03, page 62 of 78 17. Set the timeout value to 5. The timeout value can be set between 1 and 300. 18. Select 2 (system clock) for the baud rate prescalor. The value can be set between 2 and 128. Rev. 1.0, 03/03, page 63 of 78 19. Select 1 (time quanta) for the synchronization segment. Only 1 can be selected for this value. 20. Select 5 (time quanta) for time segment 1. The value can be set between 4 and 16. Rev. 1.0, 03/03, page 64 of 78 21. Select 4 (time quanta) for time segment 2. The value can be set between 3 and 8. 22. Select 1 (time quanta) for the resynchronization jump width. The value can be set between 1 and 4. Rev. 1.0, 03/03, page 65 of 78 23. Click the OK button to return to the main window. (Click the Cancel button to return to the main window without changing the settings.) The bit rate for the HCAN communication appears. This value is based on the settings of the input clock, serial port, timeout, transmit mailbox ID, and receive mailbox ID. 24. Click the Change/Set button for erase before write to make settings. 25. Click the Search button to select a write data file. Rev. 1.0, 03/03, page 66 of 78 26. Select the write data file Data_00.mot. 27. Click the Open button to return to the Write and Erase Setting dialog box. (Click the Cancel button to return to the Write and Erase Setting dialog box without selecting a file.) Rev. 1.0, 03/03, page 67 of 78 28. Select 0x00001000 for the start address. The start address can be selected from among 000000, 000400, 000800, 000C00, 001000, 008000, 00C000, 00E000, 010000, and 018000 as specified in the HCAN2612F3.inf file. Alternatively, you can directly enter the start address between 000000 and 01FFFE. 29. Select 0x00007FFF for the end address. The end address can be selected from among 0003FF, 0007FF, 000BFF, 000FFF, 007FFF, 00BFFF, 00DFFF, 00FFFF, 017FFF, and 018FFF as specified in the HCAN2612F3.inf file. Alternatively, you can directly enter the end address between 000001 and 01FFFF. Rev. 1.0, 03/03, page 68 of 78 30. Set the offset to 0x00000000. The offset can be set between 000000 and 01FFFF as specified in the HCAN2612F3.inf file. 31. Place a checkmark (on) in the Erase before write checkbox. Place a checkmark (on) in the checkbox to erase blocks before the write processing. Uncheck the checkbox (off) not to erase blocks before the write processing. Rev. 1.0, 03/03, page 69 of 78 32. Click the OK button to select the blocks to be erased in the Erase Block Selection dialog box. The blocks between the selected start address and the end address are set for erasure. 33. Click the OK button to return to the main window. (Click the Cancel button to return to the Write and Erase Setting dialog box.) 34. Now, all the settings are made completely. Click the Start button. Rev. 1.0, 03/03, page 70 of 78 35. The Start dialog box appears. Restart the SCI-HCAN communication conversion board. 36. Click the OK button to start processing. (Click the Cancel button to return to the main window.) 37. The status of the boot processing appears. (Click the Stop button to stop the boot processing and return to the main window.) 38. The boot processing completes and then the completion message appears. Rev. 1.0, 03/03, page 71 of 78 39. Click the OK button to return to the main window. 40. Uncheck the Boot checkbox (off). Place a checkmark in the Write checkbox (on). Place a checkmark in the Sumcheck checkbox (on). 41. Place the target board in user program mode. 42. Now, all the settings are made completely for writing. Click the Start button. 43. The Start dialog box appears. Rev. 1.0, 03/03, page 72 of 78 44. Click the OK button to start processing. (Click the Cancel button to return to the main window.) 45. The status of the write processing appears. (Click the Stop button to stop the write processing and return to the main window.) 46. The processing completes and the checksum appears. 47. Confirm the checksum and click the OK button to return to the main window. Now, the flash memory is completely reprogrammed in user program mode. Restarting the target board initiates the application (sample) program. Since the parameter is set to 0x00, all the LEDs blink. 8.5 Error Messages for FlashCAN.exe (Additional Messages for HCAN) 1. Error dialog box The Error dialog box appears if an error occurs. Check an error message, and then click the OK button. Rev. 1.0, 03/03, page 73 of 78 2. List of error messages No. 319 Information file: Incorrect specification of H-CAN. Description An incorrect HCAN is specified in the information (INF) file. No. 650 Transmit-ID was illegally specified. Description An illegal transmit ID (transmit mailbox ID) is specified. No. 651 Receive-ID was illegally specified. Description An illegal receive ID (receive mailbox ID) is specified. No. 652 Transmit-ID/Receive-ID was illegally specified. Description The transmit ID (transmit mailbox ID) and receive ID (receive mailbox ID) are identical. No. 653 TSEG2 was illegally specified. Description An illegal TSEG2 (time segment 2) is specified. No. 654 TSEG1 was illegally specified. Description An illegal TSEG1 (time segment 1) is specified. No. 800 H-CAN Setup error. Description An error is detected during communication of the H command. The host side received NAK (0x07) and this caused the HCAN setup error. No. 801 H-CAN Setup error. (confirmation error) Description An error is detected during communication of the H command. The host side received a signal other than ACK (0x06) and NAK (0x07) and this caused the HCAN setup error. No. 802 H-CAN Setup error. (time out) Description An error is detected during communication of the H command. The host side could not receive any signal and this caused the timeout. The HCAN setup failed. No. 803 H-CAN Send clock error. Description An error is detected during transmission with the HCAN frequency. The host side received NAK (0x07) and this caused the transmission error. No. 804 H-CAN Send clock error. (confirmation error) Description An error is detected during transmission with the HCAN frequency. The host side received a signal other than ACK (0x06) and NAK (0x07) and this caused the transmission error. No. 805 H-CAN Send clock error. (time out) Description An error is detected during transmission with the HCAN frequency. The host side could not receive any signal and this caused the timeout. The transmission failed. Rev. 1.0, 03/03, page 74 of 78 Section 9 Supplementary Description 9.1 Required Items for Reprogramming Flash Memory in User Program Mode To reprogram the flash memory in user program mode, the user must provide the following methods. The shaded section in the table indicates the method used in this application note. 1. Items required for user board No. User Must Provide: Method Examples 1 Method for programming in boot mode: Mode switch and SCI_2 connector This method switches user mode to boot mode, and vice versa. It also provides program data from the SCI_2. 2 Method for switching the FWE pin by hardware: Mode switch This method switches user mode to user program mode, and vice versa. Note: Do not always apply a high level voltage to the FWE pin. Be sure to switch the FWE pin when the CPU is not accessing the flash memory. 2. Items that application must include No. User Must Provide: Method Examples 1 Method for transition to the flash-memory reprogram processing: This method accepts a trigger for starting the flashmemory reprogram processing, and then jumps to the reprogram processing. FWE pin level sense, external interrupt, command reception by SCI, or command reception by HCAN, etc. 2 Method for transferring the program/erase control Transfer from ROM to RAM, transfer from outside using SCI, or transfer program to RAM: A program in RAM must control the programming and from outside using HCAN, etc. erasing of the flash memory. To satisfy this condition, this method transfers the program/erase control program to RAM, and then jumps to the transferred program. Rev. 1.0, 03/03, page 75 of 78 3. Items required by host No. User Must Provide: Method Examples 1 Program/erase control program: The program added to FDT.exe, added to FlashCAN.exe, or created This program is a Motorola-type load module. Use the program/erase algorithm that is recommended by by the user, etc. the hardware manual. The user must also install the transfer function that matches the host to receive instruction or response for erase blocks, or the program data. 2 Method for providing the program data (host): A host that controls the sequences shown in the above table and transfers the program data is necessary. 9.2 FDT.exe, FlashCAN.exe, or usercreated tool, etc. Differences between User Program Mode and Boot Mode Two types of modes are available for on-board reprogramming of the flash memory: the user program mode and boot mode. The following shows the differences between these modes. Item User Program Mode Boot Mode Execution of application program The application program downloaded in the flash memory is executed. Reprogramming the flash memory in user program mode requires the reprogram processing to be included in this application program in advance. The application program downloaded in the flash memory is not executed. Instead, the onchip boot program in the F-ZTAT microcomputer is executed. Interface used for The user can select the interface according to Use the SCI. The F-ZTAT reprogramming of the user system. Examples of available microcomputer automatically flash memory interfaces are the SCI and HCAN. adjusts the communication rate. The protocol is fixed. Transfer destination of program/erase control program The whole RAM area from H′FFE000 to H′FFEFBF (4032 bytes) are available. Transfer the program to RAM address from H′FFE800 to H′FFEFBF (1984 bytes). Erase block The user can select any block to erase. The user must provide the program that controls the erasing of the flash memory (erase control program) and transfer it to RAM. The F-ZTAT microcomputer automatically erases all the blocks. Programming Reprogramming is possible in units of erase blocks. Data can be programmed only for the erased blocks. The user must provide the program that controls the programming of the flash memory (program control program) and transfer it to RAM. Since all the blocks are erased, the user must program data to the entire flash memory. The user must provide the program that controls the programming of the flash memory (program control program) and transfer it to RAM. Rev. 1.0, 03/03, page 76 of 78 Item User Program Mode Method of mode transition Two methods are available: Reset the system with the Reset the system with the settings MD0 = 1, settings MD0 = 1, MD1 = 1, MD2 MD1 = 1, MD2 = 1, and FWE = 1; = 0, and FWE = 1. or During execution with MD0 = 1, MD1 = 1, MD2 = 1, and FWE = 0 in user mode, switch the setting to FWE = 1. This method enables reprogramming the flash memory without resetting the user system. 9.3 Boot Mode How to Measure Application Time for E and P Bits Erasing and programming the flash memory is implemented by setting the E and P bits in FLMCR to apply a voltage. The hardware manual describes the voltage application time. Setting too short application time for the E or P bit disables the erasing or programming. Setting too long application time causes excessive erasing or excessive programming, which leads to the permanent damage on the device. When setting the E and P bits, set up the on-chip watchdog timer to prevent a program runaway. The sample program in this application note controls the application time for the E and P bits by adjusting the software loop count. Therefore, you need to increase or reduce the loop count according to the operating frequency. You can obtain the time required for the software loop by using calculation and simulator debugger. However, the application time for the E and P bits is so important that we recommend you actually measure these bits from outside. To measure the E and P bits, output high/low voltage for the E and P bits to the on-chip I/O port. Output a signal to the on-chip I/O port at the same timing as setting the E and P bits to high and low. Use an oscilloscope or logic analyzer to measure the output signal of the on-chip I/O port from outside. Source example: Output on/off of the P bit to the on-chip I/O port P00. ;======= WRITE pulse application ======================= BSET.B #0,@PORT0 ; Set bit 0 in port 0 to measure P bit BSET.B #P,@ER6 FWRT40 DEC.L BNE ; Set P bit (programming) ; Program time: 10 µS, 30 µS, or 200 µS #1,ER3 FWRT40:16 ;======================================================= MOV.W @WLOOP5,E0 BCLR.B #P,@ER6 BCLR.B #0,@PORT0 ; Clear bit 0 in port 0 to measure P bit ; Clear P bit Rev. 1.0, 03/03, page 77 of 78 Rev. 1.0, 03/03, page 78 of 78 F-ZTAT Reprogramming by On-Chip CAN Application Note Publication Date: 1st Edition, March 2003 Published by: Business Operation Division Semiconductor & Integrated Circuits Hitachi, Ltd. Edited by: Technical Documentation Group Hitachi Kodaira Semiconductor Co., Ltd. Copyright © Hitachi, Ltd., 2003. All rights reserved. Printed in Japan.