REN - User Manual
REN - User Manual
On April 1st, 2010, NEC Electronics Corporation merged with Renesas Technology
Corporation, and Renesas Electronics Corporation took over all the business of both
companies. Therefore, although the old company name remains in this document, it is a valid
Renesas Electronics document. We appreciate your understanding.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation and also includes its majority-
owned subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.
Application Note
Revision 1.0
ii
4.4 User Program Mode ....................................................................................................... 43
4.4.1 Starting the Flash Development Toolkit................................................................................ 43
4.4.2 Selecting an Option ................................................................................................................. 43
4.4.3 Connecting the Device............................................................................................................. 45
4.4.4 Writing a Program in the User Area ...................................................................................... 46
4.4.5 Disconnecting the Device ........................................................................................................ 47
4.4.6 Configuring the Project ........................................................................................................... 48
4.4.7 Setting User Program Mode ................................................................................................... 50
4.4.8 Completion of Setting.............................................................................................................. 54
4.4.9 Connecting the Device............................................................................................................. 55
4.4.10 Timeout .................................................................................................................................... 56
4.4.11 Programming ........................................................................................................................... 57
4.4.12 Blank Check and Checksum................................................................................................... 58
iii
6.9.5 Programming Kernel............................................................................................................... 77
6.9.6 Erasing Kernel......................................................................................................................... 77
iv
8.2 Erasing ........................................................................................................................... 99
8.2.1 Used Files ................................................................................................................................ 99
8.2.2 Module Specifications.............................................................................................................. 99
v
1. Introduction
This application note describes the following items with respect to the use of the Flash Development Toolkit and the use
of the user program mode (user mode) of the H8/3694F (H8/300H Tiny Series) using the Flash Development Toolkit:
(1) Boot mode (programming the user area)
(2) User program mode (user mode)
Read the explanation of these items to understand differences between the boot mode and the user program mode and
understand the user program mode.
This application note describes the above items using a sample program created by referencing a boot mode control
program. This sample program programs and erases on-chip flash memory. To program or erase flash memory in the
user program mode, refer to this sample program.
1
2. H8/3694F (H8/300H Tiny Series)
2.1 Flash Memory Configuration
The flash memory version of the H8/3694F incorporates 32-Kbyte flash memory. In addition, it has an area for
containing a flash memory programming and erasing control program. This application note calls the area containing
the control program the boot area and flash memory the user area. The flash memory configuration is shown in Table
2-1.
2
2.3 On-Board Programming Modes
There are two on-board programming modes: The boot mode and the user boot mode. On-board programming modes
are listed in Table 2-3.
The entire user area is erased in the boot mode. Then, the user area can be programmed by commands. However, the
contents of the area cannot be read until the entire erasing is done.
3
3. Functions of the Flash Development Toolkit
The Flash Development Toolkit is an on-board flash programming tool for Renesas F-ZTAT microcomputers, which
offers a sophisticated and easy-to-use graphical user interface.
When it is used with Renesas High-performance Embedded Workshop (HEW), it allows users who develop embedded
application software using Renesas F-ZTAT microcomputers to use an integrated environment.
The Flash Development Toolkit can also be used as an editor for S-record and hexadecimal files.
Note: F-ZTAT (Flexible-Zero Turn Around Time) is a trademark of Renesas Technology Corp.
4
The graphical user interface screen of the Flash Development Toolkit is shown in Figure 3-1.
5
4. Operating the Flash Development Toolkit
4.1 Connecting the Adapter Board
On-board programming adapter board for F-ZTAT* microcomputers HS0008EAUF1H (called the adapter board
hereafter), which is connected between a host computer and user system, has a function which can write a user
application program in flash memory built into an F-ZTAT microcomputer on the user system (on-board) and erase it
from the flash memory using the Flash Development Toolkit.
The adapter board connection is shown in Figure 4-1.
Note: F-ZTAT (Flexible-Zero Turn Around Time) is a trademark of Renesas Technology Corp.
Note: FDM (flash development module) is a former name of the adapter board.
USB cable
Adapter board
Host computer
User system
F-ZTAT
microcomputer
6
The pin numbers and corresponding signals of the user system interface cable used for connecting the adapter board and
user system are listed in the following table.
Table 4-1 Pin Numbers and Corresponding Signals of the HS0008EAUF1H User System Interface
Cable
No. Signal Name No Signal Name
1 RES 2 GND
3 FWx 4 GND
5 MD0 6 GND
7 MD1 8 GND
9 MD2 (IO0) 10 GND
11 MD3 (IO1) 12 GND
13 MD4 (IO2) 14 GND
15 RXD (TXD on the user system side) 16 GND*1
17 TXD (RXD on the user system side) 18 VIN (Vcc or PVcc)*2
19 SCK (NC) 20 VIN (PVcc)*2
Notes: 1. Be sure to connect pin No. 16 to GND to detect that the user system is connected properly.
2. For a device with Vcc and PVcc, be sure to supply Vcc or PVcc (pin No. 18) and PVcc (pin No. 20) to the VIN pins of
the user interface connector, respectively. To use a device under condition Vcc = PVcc or when PVcc is not present in
the device, be sure to supply Vcc to both VIN pins Vcc or PVcc (pin No. 18) and PVcc (pin No. 20).
7
Adapter board
(HS0008EAUF1H) Vcc Pulled up at 47 kΩ
or more.
18,20
VIN(Vcc)
RXD 15 TxD
TXD 17 RxD3
MD0 5 NMI
RE 1 RES
S
GND
2,4,6,8,10,
12,14,16
Connector*1 Note: 1. Manufacturer: 3M Corporate
3428-6002LCSC
8
4.1.1 Setting Pins on the Adapter Board
An example of setting pins for the boot mode when the H8/3694F user system and Renesas adapter board
(HS0008EAUF1H) is shown in Table 4-2.
Table 4-2 Example of Setting Pins on the H8/3694F and Adapter Board (for the Boot Mode)
Pin No. Pin on the Adapter Pin on the Input/Output Output Level
Board Device
1 RES RES Output (default) Adapter board
3 FWx NC NC -
5 MD0 NMI Output Low (0)
7 MD1 NC NC -
9 MD2 (IO0) P85 Output High (1)
11 MD3 (IO1) NC NC -
13 MD4 (IO2) NC NC -
15 RXD TXD Input (default) Adapter board
17 TXD RXD Output (default) Adapter board
19 SCK (NC) NC NC (default) -
Note: NC: Means no connection.
9
When you have selected an option, click "OK."
10
4.2.3 Setting a New Project Workspace
Set a new project workspace. Use "Browse..." and select a directory, and specify the device name in "Workspace
Name." Specify a project name if required. In this example, specify the same name in "Workspace Name:" and "Project
Name:."
11
4.2.4 Selecting the Device and Kernel
Select the target device from the pull-down menu. In this example, select H8/3694F.
12
4.2.5 Selecting a Communications Port
Select the adapter board (FDM) from the pull-down menu.
13
4.2.6 Device Settings (Setting the Input Clock)
In the first column enter the frequency of the clock used for the board in MHz. For example, enter 9.8 (MHz).
The input clock is the frequency of the clock directly input to the microcomputer. Enter the frequency of the crystal or
ceramic resonator connected to the user system with three significant digits. The input clock differs from the operating
frequency (PLL output).
14
4.2.7 Selecting the Connection Type (Communication Speed)
Set the baud rate. For example, select "Use Default."
15
4.2.8 Selecting Programming Options (Protection Level and Messaging Level)
Select the protection level and messaging level. For example, select "Automatic" for "Protection" and "Advanced" for
"Messaging."
16
4.2.9 Adapter Board Pin Settings
Set the pins on the adapter board (FDM) for the boot mode.
In the H8/3694F boot mode, set the output of P85 to high (1) and that of NMI to low (0). On the H8/3694F user system,
MD2 (IO0) is connected to P85 and MD0 is connected to NMI. For this reason, set the output of MD2 (IO0) to high (1)
and that of MD0 to low (0). No FWE pin setting is required because no FWE pin is given.
17
An example of connecting the H8/3694F and Renesas adapter board (HS0008EAUF1H) is shown in Figure 4-3. The
pull-up and pull-down resistor values shown are only examples. Evaluate the microcomputer to determine the actual
values on the user system.
Adapter board
(HS0008EAUF1H) Vcc Pulled up at 47 kΩ
or more.
18,20
VIN (Vcc)
RXD 15 TxD
TXD 17 RxD3
MD0 5 NMI
RES 1 RES
GND
2,4,6,8,10,
12,14,16
Connector*1 Note: 1. Manufacturer: 3M Corporate
3428-6002LCSC
An example of setting pins for the boot mode when the H8/3694F user system and Renesas adapter board
(HS0008EAUF1H) is shown in Table 4-4.
Table 4-4 Example of Setting Pins on the H8/3694F and Adapter Board (for the Boot Mode)
Pin No. Pin on the Adapter Pin on the Input/Output Output Level
Board Device
1 RES RES Output (default) Adapter board
3 FWx NC NC -
5 MD0 NMI Output Low (0)
7 MD1 NC NC -
9 MD2 (IO0) P85 Output High (1)
11 MD3 (IO1) NC NC -
13 MD4 (IO2) NC NC -
15 RXD TXD Input (default) Adapter board
17 TXD RXD Output (default) Adapter board
19 SCK (NC) NC NC (default) -
Note: NC: Means no connection.
18
4.2.10 Reset Mode Pin Settings
Set pins on the adapter board for restarting the device in the reset mode. These settings are not required for this
procedure.
19
4.2.11 Completion of Setting
The H8/3694F board has been set to the Flash Development Toolkit in the boot mode.
20
4.2.12 Connecting the Device
Connect the adapter board (FDM) to a PC and the H8/3694F board to the adapter board and turn on the power.
After the completion of the connection, click "Device" to open the pull-down menu and click "Connect to Device."
21
4.2.13 Completion of Connection
The H8/3694F board has been connected to the Flash Development Toolkit in the boot mode.
At this time, the contents of the user area have been erased.
22
4.3 Boot Mode (Programming the User Area)
Write a program in the user area in the boot mode. The program to be written is the sample test program supplied with
the Flash Development Toolkit (files 3694Test.mot and uGenU.mot (S-type files)). The bit rate in this program must be
modified according to the frequency. For how to modify the bit rate, refer to section 7.1.1, Bit Rate Setting (GenTest.h).
The program is contained in the Renesas\FDT3.4\Kernels\ProtB folder for the Flash Development Toolkit. The
following is the full pathname of the Flash Development Toolkit programs when they are installed in the Program Files
folder:
C:\Program Files\Renesas\FDT3.4\Kernels\ProtB\3694\Renesas\1_2_00
23
In the "Add Files" dialog box, add file 3694Test.mot.
24
In the same way, add uGenU.mot.
25
4.3.2 Building the Image
Build the user area device image because more than one file is to be programmed. From the "Project" pull-down menu,
select "Rebuild Image" then "User Area."
26
Image file 3694.fpr is created.
27
4.3.3 Programming
Program the user area.
Click the right mouse button on file 3694.fpr to display the pop-up menu. Click "Download User Image" to download
file 3694.fpr to the user area.
28
You can check that the program has been downloaded to the user area.
29
4.3.4 Blank Check
To confirm that the user boot area has been programmed, perform a blank check.
Click "Device" to open the pull-down menu and click "Blank Check."
30
The result of the blank check for the selected area is displayed.
The user area is not blank.
31
4.3.5 Checksum
To confirm that the user boot area has been programmed, display a checksum.
Click "Device" to open the pull-down menu and click "FLASH Checksum."
32
The result of the checksum calculation is displayed.
When the user area is blank, the following value is displayed as the result:
Calculating device checksum
Flash Checksum: 0x00FF0000 (User Area)
33
4.3.6 Disconnecting the Device
After the completion of programming, disconnect the device.
Click "Device" to open the pull-down menu and click "Disconnect."
34
The device is disconnected.
35
4.3.7 Removing Files
Remove files.
Click "Project" to open the pull-down menu and click "Remove Files...."
36
The project files are desplayed.
Click "OK."
37
The files are removed.
38
4.3.8 Removing Folders
Remove folders.
Click the right mouse button on a folder to display the pop-up menu and click "Remove Folder."
39
The folder is removed.
40
In the same way, remove the Device Image and FDT Image Files folders.
41
4.3.9 Exiting
Save the work folder and exit the Flash Development Toolkit.
Click "File" to open the pull-down menu and click "Exit."
42
4.4 User Program Mode
In the user program mode, the user area can be programmed or erased.
43
Project 3694 is displayed.
The Flash Development Toolkit can also be activated by directly opening (or double-clicking on) project workspace file
3694.AWS.
44
4.4.3 Connecting the Device
Connect the adapter board (FDM) to a PC and the H8/3694F board to the adapter board and turn on the power.
After the completion of the connection, click "Device" to open the pull-down menu and click "Connect to Device."
45
4.4.4 Writing a Program in the User Area
Add files 3694Test.mot and uGenU.mot and build the image to create file 3694.fpr. Then, download file 3694.fpr to
write the program in the user area.
46
4.4.5 Disconnecting the Device
Click "Device" to open the pull-down menu and click "Disconnect."
47
4.4.6 Configuring the Project
Click "Device" to open the pull-down menu and click "Configure Flash Project."
48
The configure project window appears.
49
4.4.7 Setting User Program Mode
Select the "Device" tab in the configure project window and double-click "Connection" and "Boot."
50
Set the connection type.
Select "USER Program Mode" in "Select Connection:."
Set the baud rate to 9600 bps.
51
Set the pins on the adapter board (FDM) for the user program mode.
In the H8/3694F user program mode, set the output of NMI to high (1). On the H8/3694F user system, MD0 is
connected to NMI. For this reason, set the output of MD0 to high (1). No FWE pin setting is required because no FWE
pin is given.
52
An example of connecting the H8/3694F and Renesas adapter board (HS0008EAUF1H) is shown in Figure 4-4. The
pull-up and pull-down resistor values shown are only examples. Evaluate the microcomputer to determine the actual
values on the user system.
Adapter board
(HS0008EAUF1H) Vcc Pulled up at 47 kΩ
or more.
18,20
VIN(Vcc)
RXD 15 TxD
TXD 17 RxD3
MD0 5 NMI
RES 1 RES
GND
2,4,6,8,10,
12,14,16
Connector*1 Note: 1. Manufacturer: 3M Corporate
3428-6002LCSC
An example of setting pins for the user program mode when the H8/3694F user system and Renesas adapter board
(HS0008EAUF1H) is shown in Table 4-5.
Table 4-5 Example of Setting Pins on the H8/3694F and Adapter Board (for the User Program Mode)
Pin No. Pin on the Adapter Pin on the Input/Output Output Level
Board Device
1 RES RES Output (default) Adapter board
3 FWx NC NC -
5 MD0 NMI Output High (1)
7 MD1 NC NC -
9 MD2 (IO0) P85 Input -
11 MD3 (IO1) NC NC -
13 MD4 (IO2) NC NC -
15 RXD TXD Input (default) Adapter board
17 TXD RXD Output (default) Adapter board
19 SCK (NC) NC NC (default) -
Note: NC: Means no connection.
53
4.4.8 Completion of Setting
The user program mode has been set.
54
4.4.9 Connecting the Device
After the completion of the setting, click "Device" to open the pull-down menu and click "Connect to Device."
The connection in the user program mode is completed.
55
4.4.10 Timeout
A timeout error may occur during an attempt to connect the device.
There are several possible causes. Either of the following operations may not be performed. Check them.
(1) Modify the bit rate in the sample program to 9600 bps.
For how to modify the bit rate, refer to section 7.1.1, Bit Rate Setting (GenTest.h).
(2) Connect the serial input to the I/O bus (26P) (J2).
For details on connection to the I/O bus, refer to section エラー! 参照元が見つかりません。, エラー! 参
照元が見つかりません。.
56
4.4.11 Programming
Write a program in the user area in the user program mode.
Click the right mouse button on file 3694.fpr to display the pop-up menu. Click "Download User Image" to download
file 3694.fpr to the user area.
You can check that the program has been downloaded to the user area.
57
4.4.12 Blank Check and Checksum
To confirm that the user area has been programmed, perform a blank check and calculate a checksum.
Click "Device" to open the pull-down menu and click "Blank Check."
Click "Device" to open the pull-down menu and click "FLASH Checksum."
The results of the blank check and checksum calculation are displayed.
58
5. Flash Development Toolkit Processing
The Flash Development Toolkit can be connected in either of the following two modes: the boot mode and user
program mode. In both modes, the continuation of the execution from a previous session (direct connection to the main
kernel) can be specified. The connection modes of the Flash Development Toolkit are listed in Table 5-1. Usually, use
new connection processing. The hexadecimal codes are the command codes of the Flash Development Toolkit.
59
6. Sample Program
This section describes the sample program in the user program mode of the H8/3694F.
60
6.2 File Configuration
The program files are contained in the C:\Program Files\Renesas\FDT3.4\Kernels\ProtB\3694\Renesas\1_2_00 folder.
The file configuration of each program module is shown below. These program modules are provided as a sample of a
program in the user program mode that is to be created uniquely by the user.
61
6.2.2 Micro Kernel
62
6.2.3 Main Kernel
63
6.2.4 Programming Kernel
64
6.3 Relationships between Program Modules and Files
The relationships between program modules and files are given in Table 6-7.
65
6.4 Build Operation
Build operation is not required when the provided program is used. When re-creation is required due to such as the use
of a different operating frequency, build operation is required.
Executing build operation deletes all generated files. Create a copy, then execute build operation because a current file
may be required.
66
6.5 Modules
The modules are listed in Table 6-9.
67
6.6 Module Hierarchical Structure
The module hierarchical structure is shown in Figure 6-1.
68
(Continued)
⏐⎯RAMStartAddress (0xF780) RAM start address
⏐⎯Kernelmain (FDTUMain.c) Main kernel
⏐⎯ProcessCommand Command processing
⏐ ⏐⎯Get Reception
⏐ ⏐⎯RequestBootPrgSts Program status
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐⎯SumcheckUserArea User area checksum
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐⎯SendAck ACK transmission
⏐ ⏐⎯GetCmdData Command read
⏐ ⏐ ⏐⎯Get Reception
⏐ ⏐ ⏐⎯ErrorCode Error code macro
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐⎯ReadMemory Memory read
⏐ ⏐ ⏐⎯ErrorCode Error code macro
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐⎯CheckBlank Blank check
⏐ ⏐ ⏐⎯ErrorCode Error code macro
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐ ⏐⎯SendAck ACK transmission
⏐ ⏐⎯Put Transmission
⏐⎯CopyFunction (CopyFunc.c) Copy function
⏐⎯Get Reception
⏐⎯ErrorCode Error code macro
⏐⎯Put Transmission
⏐⎯SendAck ACK transmission
⏐⎯FLASHFunc (0xFB10) Flash function
(To be continued)
Figure 6-2 Module Hierarchical Structure (2)
69
(To be continued)
⏐⎯FLASHFunc (0xFB10) Flash function
⏐⎯EraseFLASH (FDTErase.c) Flash erasing (Erasing kernel)
⏐ ⏐⎯EraseWaitTime Erasing wait time
⏐ ⏐ ⏐⎯CalCount (F3694e.src) Time calculation
⏐ ⏐⎯Get Reception
⏐ ⏐⎯RequestBootPrgSts Program status
⏐ ⏐⎯GetEraseData Erase data reception
⏐ ⏐ ⏐⎯Get Reception
⏐ ⏐ ⏐⎯ErrorCode Error code macro
⏐ ⏐ ⏐⎯Put Transmission
⏐ ⏐⎯block_erase (F3694e.src) Block erasing
⏐ ⏐⎯Put Transmission
⏐ ⏐⎯SendAck ACK transmission
⏐⎯WriteFLASH (FDTWrite.c) Flash programming (Programming kernel)
⏐⎯WriteWaitTime Programming wait time
⏐ ⏐⎯CalCount (F3694w.src) Time calculation
⏐⎯Get Reception
⏐⎯RequestBootPrgSts Program status
⏐⎯GetWriteData Programming data reception
⏐ ⏐⎯Get Reception
⏐ ⏐⎯ErrorCode Error code macro
⏐ ⏐⎯Put Transmission
⏐⎯flash_write (F3694w.src) Data programming
⏐⎯Put Transmission
⏐⎯SendAck ACK transmission
70
6.7 Program Processing Flow
The processing flow of the sample program is shown in Figure 6-4.
In the user program mode, bit rate adjustment and user area erase processing, which are performed during boot
operation, are not performed. Accordingly, the program and data written in flash memory can be saved.
Reset
Bit-rate-adjustment status
Bit rate
Note: The sample program does
adjustment
not contain this processing.
Inquiry/selection status
Inquiry Selection
Inquiry Selection
Transition to the processing processing
programming/
erasing status
Programming/erasing status
User MAT/user
boot MAT erase Note: The sample program
processing does not contain this program.
Wait for
programming or
erasing to be
selected Programming Erasing
71
6.8 Command Sequence in the User Program Mode
The sequence of the commands between the Flash Development Toolkit and microcomputer when a device is connected,
when flash memory is programmed, and when flash memory is erased in the user program mode is shown in Figure 6-5,
Figure 6-6, and Figure 6-7.
ACK
ACK
Micro
H’3F: New baud rate setting kernel
ACK
ACK
ACK
ACK
ACK
ACK
72
Host (PC) Microcomputer
ACK
ACK
.
.
.
. Programming
.
kernel
.
ACK
73
Host (PC) Microcomputer
ACK
ACK
.
.
.
. Erasing
. kernel
.
ACK
74
6.9 Program Sequence
This section describes the program sequence of the sample program. An outline of the program sequence is given in
Table 6-10.
6.9.1 Preparation
The flow of preparation is shown below:
(1) To use the Flash Development Toolkit in the user program mode, program the main processing module and
micro kernel in flash memory in advance.
When the entire flash memory can be erased with no problems, they can be programmed using the boot mode
of the Flash Development Toolkit. Alternatively, they can be programmed in the programmer mode using a
PROM programmer.
(2) After programming the main processing module and micro kernel in the flash memory, set the pins on the
microcomputer to the user program mode, perform a reset, and initiate the user program mode.
75
6.9.2 Main Processing Module
The flow of the main processing module is shown below. The main processing module runs in ROM.
(1) The reset vector causes a branch to start (startup).
(2) Start (startup) sets the stack pointer and calls main processing (main).
(3) Main processing (main) calls watchdog timer stop (WDTStop) and SCI initial setting (InitSCI) and causes a
branch to branch to copy (JumpCopy).
Watchdog timer stop (WDTStop) stops the watchdog timer and SCI initial setting (InitSCI) sets the SCI bit
rate.
(4) Micro kernel copy (CopyFDT) sets the addresses and sizes of the SCI interface functions (Get and Put) in the
variable area and branches to start micro kernel (StartFDTUserKernel) via micro kernel copy (CopyFDT).
76
6.9.4 Main Kernel
The flow of the main kernel is shown below. The main kernel runs in RAM.
(1) Command processing (ProcessCommand) processes commands. The following commands are to be processed:
Memory read (ReadMemory)
User area sum check (SumcheckUserArea)
User area blank check (CheckBlank)
Boot program status inquiry (RequestBootPrgSts)
(2) When command processing receives the user area programming selection command or erasing selection
command, it calls copy function (CopyFunction).
(3) Copy function (CopyFunction) receives the programming kernel (WriteFLASH) or erasing kernel
(EraseFLASH) corresponding to the command, stores it in RAM, and calls the programming kernel
(WriteFLASH) or erasing kernel (EraseFLASH).
77
6.10 Memory Map
The memory map corresponding to the program sequence of the sample program is shown in Table 6-11.
78
7. Source Files of the Sample Program
This section describes the functions and processing of the following main source files of the sample program.
Table 7-1 Operating Frequencies and BRR Register Settings (When the Bit Rate Is 9600 (bit/s))
Operating Frequency φ (MHz) BRR Setting Error (%)
8 25 0.16
9.8304 31 0.00
10 32 -1.36
12 38 0.16
12.288 39 0.00
14 45 -0.93
14.7456 47 0.00
16 51 0.16
17.2032 55 0.00
18 58 -0.69
19.6608 63 0.00
20 64 0.16
The MA_BRR_SCI value is set according to the operating frequency of the board and perform a build with a batch file
or HEW to create an S-type file program.
79
7.1.2 I/O Register Definition (io3694.h)
The registers and bits related to the SCI module and WDT are defined.
/************************************************************************/
/* H8/3694F,36014F,36024F,36064F Internal I/O Include File */
/************************************************************************/
/************************************************************************/
/* SCI */
/*----------------------------------------------------------------------*/
/* CHANNEL 3 */
/************************************************************************/
#define SCI_SMR (*(volatile unsigned char *)0xFFA8)
#define SCI_BRR (*(volatile unsigned char *)0xFFA9)
#define SCI_SCR3 (*(volatile unsigned char *)0xFFAA)
#define TE (unsigned char)0x20
#define RE (unsigned char)0x10
#define TE_RE (unsigned char)(TE | RE)
#define SCI_TDR (*(volatile unsigned char *)0xFFAB)
#define SCI_SSR (*(volatile unsigned char *)0xFFAC)
#define TDRE (unsigned char)0x80
#define RDRF (unsigned char)0x40
#define ERR_CLR (unsigned char)0xC7
#define TEND (unsigned char)0x04
#define SCI_RDR (*(volatile unsigned char *)0xFFAD)
/************************************************************************/
/* I/O Port */
/*----------------------------------------------------------------------*/
/* Port 1 (in use : TXD) */
/************************************************************************/
#define PMR1 (*(volatile unsigned char *)0xFFE0)
#define TXD (unsigned char)0x02
/************************************************************************/
/* I/O Port */
/*----------------------------------------------------------------------*/
/* Port 2 (in use : P22/TXD at SCI Break) */
/************************************************************************/
#define PCR2 (*(volatile unsigned char *)0xFFE5)
#define PCR22 (unsigned char)0x04
80
#define PDR2 (*(volatile unsigned char *)0xFF5D)
#define P22 (unsigned char)0x04
/************************************************************************/
/* WDT */
/*----------------------------------------------------------------------*/
/* */
/************************************************************************/
#define TCSRWD (*(volatile unsigned char *)0xFFC0)
81
7.2 Main Processing Module (Strt3694.src and GenTest.c)
7.2.1 Module Hierarchical Structure
The module hierarchical structure of the main processing module is shown in Figure 7-1.
82
7.2.4 Main Processing (main)
WDTStop();
InitSCI();
JumpCopy();
The watchdog timer is stopped, SCI initial setting is performed, and control branches to the micro kernel.
ParamFDT.RAMStartAddress = RAM_START_ADDRESS;
/* Jump to CopyFDT */
(*CopyFDT)((paramFDT *)&ParamFDT);
(2) GenTest.h
/*
These defines relate to the USER kernel.
In order to call the user kernel we must know the address it was
linked at.
*/
#define USER_KERNEL_LINK_ADDRESS 0x7600
The addresses and sizes of the SCI interface functions (Get and Put) are set in ParamFDT and control branches to
CopyFDT. The address of CopyFDT is H'7600, which is indicated by USER_KERNEL_LINK_ADDRESS. Start micro
kernel (StartFDTUserKernel) of the micro kernel is programmed at H'7600.
83
7.3 Micro Kernel (uGenu.c and CmdFunc.c)
7.3.1 Module Hierarchical Structure
The module hierarchical structure of the micro kernel is shown in Figure 7-2.
Prepare micro kernel is called and the module stored at RAMStartAddress in RAM is called. Prepare micro kernel
stores the main kernel in the area starting at RAMStartAddress in RAM. RAMStartAddress is set to H'F780.
84
7.3.3 Prepare Micro Kernel (PrepareFDTUserKernel)
while(1){
/* Command Function */
CmdFunc(parameters->PutFuncPtr, parameters->GetFuncPtr);
/*Prepare RAM */
if(!PrepareRAM(parameters, &ParamFDT)){
break;
}
}
Command function is called. When command function terminates (on receiving the command for a transition to the
programming/erasing status), prepare RAM is called. When prepare RAM terminates (the main kernel has been
received and stored normally), prepare micro kernel terminates.
85
7.3.4 Command Function (CmdFunc and CmdFunc.c)
The structure of command function is shown below.
while(1){
/* Acquisition of a command ID */
add_sum = Get(&commandID, 1);
switch(commandID)
{
case finishDataSet:
return;
case supportDevice:
ReferFunc(commandID, deviceData, sizeof(deviceData), Put);
break;
case selectDevice:
SelectDevice(cmdBuf.bdata, Put);
break;
case referClockMode:
ReferFunc(commandID, clockModeData, sizeof(clockModeData), Put);
break;
case selectClockMode:
SelectClockMode(cmdBuf.bdata, Put);
break;
case referRatio:
ReferFunc(commandID, ratioData, sizeof(ratioData), Put);
break;
case setNewBaudRate:
SetNewBaudRate(commandID, (BaudRate *)cmdBuf.bdata, Put, Get);
break;
case referUserRomInfo:
ReferFunc(commandID, usrRomData, sizeof(usrRomData), Put);
break;
case referEraseBlockInfo:
ReferFunc(commandID, eraseBlkData, sizeof(eraseBlkData), Put);
break;
case referWriteSystem:
ReferFunc(commandID, writeSysData, sizeof(writeSysData), Put);
break;
case referFrequency:
ReferFunc(commandID, frequencyData, sizeof(frequencyData), Put);
break;
86
case referWriteSize:
ReferFunc(commandID, writeSizeData, sizeof(writeSizeData), Put);
break;
case requestBootPrgSts:
RequestBootPrgSts(Put);
break;
default:
cBuff[0] = COMMAND_ERROR;
cBuff[1] = commandID;
Put(cBuff, 2);
break;
}
}
When command function receives the command for a transition to the programming/erasing status, it terminates
processing. When command function receives another command, it processes the command, then enters the command
reception wait state.
The processing module for each command is contained in CmdFunc.c. CmdFunc.c contains both the command
processing modules for the micro kernel, as well as those for the main kernel. #ifdef is used to determine whether a
command processing module is for the micro kernel or main kernel.
These command processing modules are used not only in the user program mode, but also in the boot mode. In the user
program mode, the SCI interface functions (Get and Put) have arguments, but in the boot mode, they have no
arguments.
87
7.3.5 Prepare RAM (PrepareRAM)
kernelPos = (BYTE *)parameters->RAMStartAddress;
/* Receive size of User Kernel module from host */
add_sum = Get((BYTE *)&kernelSize, sizeof(kernelSize));
/* Download kernel to beginning of allowable RAM */
add_sum+= Get(kernelPos, kernelSize);
/* Adjust start position of RAM */
parameters->RAMStartAddress += kernelSize;
/*
Copy the Get and Put functions into memory, first Get() then Put()
*/
pSrc = (BYTE *)parameters->GetFuncPtr;
pDest = (BYTE *)parameters->RAMStartAddress;
/* Now perform the copy */
for(i = 0; i < parameters->GetSize; i++, pSrc++, pDest++)
{
*pDest = *pSrc;
}
parameters->RAMStartAddress += parameters->GetSize;
pSrc = (BYTE *)parameters->PutFuncPtr;
pDest = (BYTE *)parameters->RAMStartAddress;
/* Now perform the copy */
for(i = 0; i < parameters->PutSize; i++, pSrc++, pDest++)
{
*pDest = *pSrc;
}
Prepare RAM performs the following processing:
(1) Receives the main kernel and stores it in RAM.
(2) Copies the Get function into RAM.
(3) Copies the Put function into RAM.
Prepare RAM sets the starting address of each function and stores it in RAM. Prepare RAM also stores the size of each
function in RAM. The functions are executed in RAM to erase or program flash memory.
88
7.4 Main Kernel (FDTUMain.c, CmdFunc.c, and CopyFunc.c)
7.4.1 Module Hierarchical Structure
The module hierarchical structure of the main kernel is shown in Figure 7-3.
The main kernel executes command processing (ProcessCommand) repeatedly. Command processing receives and
processes commands. Copy function (CopyFunction) is called only when the user area programming selection or
erasing selection command is received. It receives the erasing or programming kernel corresponding to the command
and stores it in RAM. The erasing kernel erases data and the programming kernel programs data. When programming or
erasing terminates, command processing is called again.
89
7.4.3 Command Processing (ProcessCommand)
The structure of command processing is shown below:
/* Acquisition of a command ID */
add_sum = Get(commandID, 1);
switch(*commandID)
{
case requestBootPrgSts:
RequestBootPrgSts(Put);
break;
case sumcheckUserArea:
SumcheckUserArea(Put);
break;
case prepareErase:
case prepareUserAreaWrite:
return(TRUE);
case readMemory:
ReadMemory(cmdBuf.bdata, Put);
break;
case checkBlank:
CheckBlank(Put);
break;
default:
cBuff[0] = COMMAND_ERROR;
cBuff[1] = *commandID;
Put(cBuff, 2);
break;
}
return(FALSE);
When command processing receives the erasing or programming selection command, it returns TRUE. Other
commands are processed by the relevant command processing modules and command processing returns FALSE.
90
7.4.4 Copy Function (CopyFunction)
(1) CopyFunction
BYTE *funcAddress = (BYTE *)FUNC_START, add_sum;
FLASHFuncPtr FLASHFunc = (FLASHFuncPtr)FUNC_START;
Copy function receives the erasing or programming kernel and stores it in a RAM area starting at H'FB10 indicated by
FUNC_START. After storing the kernel, copy function calls FUNC_START to execute erasing or programming.
Erasing or programming is determined according to the command received by command processing
(ProcessCommand).
91
7.5 Erasing Kernel (FDTErase.c, EraseTime.c, and F3694e.src)
7.5.1 Module Hierarchical Structure
The module hierarchical structure of the erasing kernel is shown in Figure 7-4.
do{
/* Acquisition of a command ID */
add_sum = Get(&commandID, 1);
/* Is it a demand of boot status command? */
if (commandID == requestBootPrgSts){
RequestBootPrgSts(Put);
}else{
/* Acquisition of command data */
if(GetEraseData(&blk_no, add_sum, Put, Get)){
return;
}
if (blk_no != ERASE_END){
/* Erase start */
rsts = block_erase(blk_no);
if(rsts){
if (rsts == BLOCK_NO_ERROR){
cBuff[1] = ERASE_BLOCK_NO_ERROR;
}else{
cBuff[1] = ERASE_ERROR;
}
return;
92
}
}else{
end_flg = LOOP_END;
}
}
}while(!end_flg);
Flash erasing (EraseFLASH) calculates the erasing wait time using erasing wait time (EraseWaitTime).
Then, it receives a command. When the command is program status inquiry, flash erasing responds with the status using
program status (RequestBootPrgSts).
When the command is block erasing and the data is not erasing end, flash erasing specifies the block number and calls
block erasing (block_erase).
When the data is erasing end, flash erasing terminates erasing and returns control to the main kernel.
93
Examples of calculated erasing wait time values are listed in Table 7-2.
Table 7-2 Examples of Erasing Wait Time Values (Operating Frequency: 20 MHz)
Erasing Wait Time Variable Time (μs) Software Loop Count
After the SWE bit is set SWES_W 1 4
After the SWE bit is cleared SWEC_W 100 334
After the ESU bit is set ESUS_W 100 334
After the ESU bit is cleared ESUC_W 10 34
After the E bit is set ES_W 10000 (10 ms) 33333
After the E bit is cleared EC_W 10 34
After the EV bit is set EVS_W 20 67
After the EV bit is cleared EVC_W 4 14
After dummy data is DLCH_W 2 7
programmed
94
7.6 Programming Kernel (FDTWrite.c, WriteTime.c, and F3694w.src)
7.6.1 Module Hierarchical Structure
The module hierarchical structure of the programming kernel is shown in Figure 7-5.
do{
/* Acquisition of a command ID */
add_sum = Get(&commandID, 1);
/* Is it a demand of boot status command? */
if (commandID == requestBootPrgSts){
RequestBootPrgSts(Put);
}else{
/* Acquisition of command data */
if(GetWriteData(&pAddress, add_sum, Put, Get)){
return;
}
if (pAddress != WRITE_END){
/* Write-in start */
rsts = flash_write((BYTE *)WRITE_DATA, (BYTE *)pAddress);
if(rsts)
{
if (rsts == ADDRESS_ERROR ||
rsts == ADDRESS_BOUNDARY_ERROR)
{
cBuff[1] = WRITE_ADDRESS_ERROR;
}else{
95
cBuff[1] = WRITE_ERROR;
}
return;
}
}else{
end_flg = LOOP_END;
}
}
}while(!end_flg);
Flash memory programming (WriteFLASH) calculates the programming wait time using programming wait time
(WriteWaitTime).
Then, it receives a command. When the command is program status inquiry, flash memory programming responds with
the status using program status (RequestBootPrgSts).
When the command is 128-byte programming and the data is not programming end, flash memory erasing specifies the
programming address and programming data and calls data programming (flash_write).
When the data is programming end, flash memory programming terminates programming and returns control to the
main kernel.
Programming wait time (WriteWaitTime) calculates the wait time (μs) after each bit of the relevant register is set to 1 or
cleared to 0 when programming is executed. Time calculation (CalCount) calculates the wait time with the number of
96
instructions based on the given frequency, assuming that one instruction requires 6 cycles. The frequency is the
operating frequency calculated based on the value given by new bit rate selection. The frequency in 10 kHz is stored at
H'FF10.
To program flash memory using a dedicated interface without using the Flash Development Toolkit, create a program,
referring to the user manual for how to set the operating frequency and how to calculate the programming wait time.
Examples of calculated programming wait time values are listed in Table 7-3.
Table 7-3 Examples of Programming Wait Time Values (Operating Frequency: 20 MHz)
Programming Wait Time Variable Time (μs) Software Loop Count
After the PSU bit is set PSUS_W 50 166
After the PSU bit is cleared PSUC_W 5 16
Programming time for P10S_W 10 33
additional programming
Programming time for P30S_W 30 100
programming after the P bit is
set
(Programming count: 1 to 6)
Programming time for P200S_W 200 666
programming
(Programming count: 7 to
1000)
After the SWE bit is cleared SWEC_W 100 34
After the P bit is cleared PC_W 5 16
After the PV bit is set PVS_W 5 16
After dummy data is DLCH_W 5 16
programmed
97
8. Using Programming/Erasing Kernels (Supplied Programs)
You can use the flash memory programming/erasing logical modules by connecting them to your own developed
program without the Flash Development Toolkit interface section (main processing module and micro kernel). This
section describes the logical modules which are part of the programming/erasing kernels.
8.1 Programming
8.1.1 Used Files
File Name Description Language
F3694w.src Source file of 128-byte programming Assembly language
F3694asm.inc Header file common to 128-byte programming and Assembly language
block erasing
98
8.2 Erasing
8.2.1 Used Files
File Name Description Language
F3694e.src Source file of block erasing Assembly language
F3694asm.inc Header file common to 128-byte programming and Assembly language
block erasing
99
Flash Development Toolkit Application Note (Applications)
User Program Mode (H8/3694F)