REN R01us0050ej0105 rl78 MAT 20181031
REN R01us0050ej0105 rl78 MAT 20181031
REN R01us0050ej0105 rl78 MAT 20181031
User s Manual
RL78 Family
Flash Self-Programming Library Type 01
16 Japanese Release
All information contained in these materials, including products and product specifications,
represents information on the product at the time of publication and is subject to change by
Renesas Electronics Corp. without notice. Please review the latest information published by
Renesas Electronics Corp. through various means, including the Renesas Electronics Corp.
website (http://www.renesas.com).
The following usage notes are applicable to all MPU/MCU products from Renesas. For detailed usage notes on the
products covered by this document, refer to the relevant sections of the document as well as any technical updates that
have been issued for the products.
Readers This manual is intended for user engineers who wish to understand the functions of the
Flash Self-Programming Library Type 01 for the RL78 microcontrollers and design and
develop application systems and programs for these devices.
Refer to the following list for the target MCUs.
Purpose This manual is intended to give users an understanding of the methods (described in the
Organization below) for using flash self-programming library Type 01 to rewrite the code
flash memories.
• Overview
• Programming Environment
• Interrupts During Execution of Flash Self-programming
• Security Setting
• Boot Swap Function
• Flash Self-Programming Function
How to Read This Manual It is assumed that the readers of this manual have general knowledge of electrical
engineering, logic circuits, and microcontrollers.
• To gain a general understanding of functions:
→ Read this manual in the order of the CONTENTS.
• To know details of the RL78 Microcontroller instructions:
→ Refer to CHAPTER 6 FLASH FUNCTION.
Conventions Data significance: Higher digits on the left and lower digits on the right
Active low representations: ××× (overscore over pin and signal name)
Note: Footnote for item marked with Note in the text
Caution: Information requiring particular attention
Remark: Supplementary information
Numerical representations: Binary ...×××× or ××××B
Decimal ...××××
Hexadecimal ...××××H or ‘0x’xxxx
All trademarks and registered trademarks are the property of their respective owners.
EEPROM is a trademark of Renesas Electronics Corporation.
CONTENTS
CHAPTER 1 OVERVIEW .............................................................................................. 1
1. 1 Overview ....................................................................................................................................... 1
1. 2 Calling Flash Self-Programming Library ....................................................................................... 3
3. 1 Overview ..................................................................................................................................... 33
3. 2 Interrupts During Execution of Flash Self-Programming ............................................................ 33
3. 3 Cautions on Interrupts ................................................................................................................. 34
5. 1 Overview ..................................................................................................................................... 36
5. 2 Boot Swap Function .................................................................................................................... 36
5. 3 Boot Swapping Procedure .......................................................................................................... 37
5. 4 Cautions on Boot Swapping ........................................................................................................ 42
Index-1
6. 7 Description of Flash Functions.................................................................................................... 55
FSL_Init .................................................................................................................................... 56
FSL_Open ................................................................................................................................ 59
FSL_Close................................................................................................................................ 60
FSL_PrepareFunctions ............................................................................................................ 61
FSL_PrepareExtFunctions ....................................................................................................... 62
FSL_ChangeInterruptTable ...................................................................................................... 63
FSL_RestoreInterruptTable ...................................................................................................... 65
FSL_BlankCheck ..................................................................................................................... 67
FSL_Erase ............................................................................................................................... 69
FSL_IVerify............................................................................................................................... 71
FSL_Write ................................................................................................................................ 73
FSL_GetSecurityFlags ............................................................................................................. 76
FSL_GetBootFlag..................................................................................................................... 78
FSL_GetSwapState .................................................................................................................. 80
FSL_GetBlockEndAddr ............................................................................................................ 82
FSL_GetFlashShieldWindow ................................................................................................... 84
FSL_SwapBootCluster ............................................................................................................. 86
FSL_SwapActiveBootCluster ................................................................................................... 88
FSL_InvertBootFlag ................................................................................................................. 90
FSL_SetBlockEraseProtectFlag ............................................................................................... 92
FSL_SetWriteProtectFlag ........................................................................................................ 94
FSL_SetBootClusterProtectFlag .............................................................................................. 96
FSL_SetFlashShieldWindow .................................................................................................... 98
FSL_StatusCheck .................................................................................................................. 101
FSL_StandBy ......................................................................................................................... 103
FSL_WakeUp ......................................................................................................................... 105
FSL_ForceReset .................................................................................................................... 107
FSL_GetVersionString ........................................................................................................... 108
Index-2
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01
CHAPTER 1 OVERVIEW
1. 1 Overview
The flash self-programming library is software to rewrite data in the code flash memory with the firmware
installed on the RL78 microcontroller.
The content of the code flash memory can be rewritten by calling the flash self-programming library from the
user program, which can significantly shorten the software development period.
Use this Flash Self-Programming Library User's Manual along with the manual of the target device.
Terms The meanings of the terms used in this manual are described below.
Flash self-programming
Write operation to the code flash memory by the user program itself.
Flash self-programming library
Library for code flash memory operation with the functions provided by the RL78 microcontroller.
Operation to the data flash memory cannot be done.
Flash environment
State in which operation to the code flash memory is available. There are restrictions different from those in
the execution of normal programs. Operation to the data flash memory cannot be done.
Block number
Number indicating a block of flash memory. Operation unit for erasure, blank check, and verification (internal
verification).
Boot cluster
Boot area used for boot swapping. For the availability of the boot swap function, refer to the user's manual of
the target RL78 microcontroller.
Internal verification
To check if the signal level of the flash memory cell is appropriate after writing to the flash memory. If an error
is detected in internal verification, the device is determined as failed. However, if data erasure, data writing,
and internal verification are performed and completed normally after the internal verification error, the device is
determined as normal.
FSL
Abbreviation of "Flash Self-Programming Library."
FSW
Abbreviation of "Flash Shield Window."
Flash function
Function comprising the flash self-programming library.
R01US0050EJ0105 Rev.1.05 Page 1 of 112
Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01
Sequencer
The RL78 microcontroller has a dedicated circuit for controlling the flash memory. In this document, this circuit
is called the "sequencer."
BGO (background operation)
State in which rewriting of the flash memory can be done while operating the user program by letting the
sequencer to control the flash memory.
Status check
When the sequencer is used, the processing to check the state of the sequencer (state of control for the flash
memory) with the program controlling the flash memory is required. In this document, the processing to check
the state of the sequencer is called "status checking."
ROMization (program)
In flash self-programming of the RL78 microcontroller, user programs and flash self-programming library need
to be allocated in the RAM to perform the processing depending on the control method. In this document,
allocating the program for operating on the RAM in the code flash memory to use it is called "ROMization."
To perform ROMization, the functions such as the development tools need to be used.
EEPROM emulation library
Software library that provides the function to store data in the installed flash memory like an EEPROM.
Data flash library
Software library to perform operation to the data flash memory.
To perform flash self-programming, the initialization processing for flash self-programming and the functions
corresponding to the functions used need to be executed from the user program in the C language or assembly
language.
In Flash Self-Programming Library Type 01, the code flash memory cannot be referred to while it is being
rewritten. Therefore, some segments of the flash self-programming library or the user program need to be
allocated on the RAM depending on the usage.
Figure 1-1 shows the state transition diagram of flash self-programming. Figure 1-2 shows an example of the
code flash memory rewriting flow by using the flash self-programming library. Figure 1-3 shows an example of
the code flash memory rewriting flow during background operation (BGO).
FSL_SwapBootCluster
FSL_ForceReset
return closed
FSL_Open() FSL_Close()
FSL_PrepareFunctions
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
FSL_RestoreInterruptTable
FSL_Get*** opened FSL_Wakeup()
FSL_ForceReset
Busy extprepared prepaerd
Status: OK
FSL_StandBy()
Status: ERROR
FSL_SwapBootCluster
FSL_BlankCheck
FSL_SwapActiveBootCluster
Status: OK FSL_Erase
FSL_InvertBootFlag standby
FSL_IVerify
FSL_Set*** Status: ERROR FSL_Write
FSL_StatusCheck
FSL_StandBy()
Sequencer busy
(1) uninitialized
State at Power ON and Reset. A transition to this state occurs also when the EEPROM emulation library or
the data flash library is executed.
(2) closed
State in which the FSL_Init() function has been executed and the data to execute the flash self-programming
has been initialized (operation to the code flash memory is stopped). To execute the EEPROM emulation
library, the data flash library, STOP mode, or HALT mode after operating flash self-programming, execute
FSL_Close from the opened state to make a transition to this state.
(3) opened
State in which the FSL_Open() function has been executed from the closed state and flash
self-programming can be executed. This state is called the "flash environment." In the period from the
execution of FSL_Close to the transition to the closed state, the EEPROM emulation library, the data flash
library, STOP mode, or HALT mode cannot be executed.
(4) prepared
State in which the FSL_PrepareFunctions() function has been executed from the opened state and
operations to the code flash memory such as writing, and erasure are enabled.
(5) extprepared
State in which the FSL_PrepareFunctions() and FSL_PrepareExtFunctions() function have been executed
from the opened state in that order and rewriting of the security flag and boot swap processing can be
executed.
(6) busy
State in which the specified processing is being executed. The resulting transition may change depending
on the executed function and end state.
(8) standby
State in which flash self-programming is paused by the FSL_StandBy function. Flash self-programming
can be restarted by using the FSL_WakeUp function. When a pause occurred during the execution of the
FSL_Erase function, the processing of the FSL_Erase function is restarted.
Figure 1-2. Example of Flow of Flash Self-Programming (Rewriting of Code Flash Memory)
<1> FSL_Init
No
Normal completion?
Yes
<2> FSL_Open
Pre-processing
<3> FSL_PrepareFunctions
No
Use an interrupt?
Yes
<4> FSL_ChangeInterruptTable
<5> FSL_BlankCheck
* When rewriting the code flash memory is
performed in status check internal mode.
Status check
Blank check error Other error
Normal completion <6> FSL_Erase
Error
Status check
Normal completion
<7> FSL_Write
Error
Status check
Normal completion
FSL_IVerify
<8>
Error
Status check
Normal completion
Processing end
No
Changed the interrupt destination?
Yes
Ending processing
<9> FSL_RestorInterruptTable
<10> FSL_Close
Figure 1-3. Example of Flow of Code Flash Memory Rewriting During Background Operation
Error
Status check
In execution
<11> FSL_StatusCheck
Normal completion
<6> FSL_Erase
Error
Status check
In execution
<11> FSL_StatusCheck
In execution Error
Status check
Normal completion
<7> FSL_Write
Error
Status check
In execution
<11> FSL_StatusCheck
In execution Error
Status check
Normal completion
<8> FSL_IVerify
Error
Status check
In execution
<11> FSL_StatusCheck
In execution
Status check
Processing complete
<7> Writing 1 word to 64 words (4 bytes to 256 bytes) data to the specified address
The FSL_Write function is called to write 1 word to 64 words (4 bytes to 256 bytes) data to the specified
address.
If writing to the specified block cannot be completed at one time, the FSL_Write function is executed multiple
times to complete writing all data to the specified block before a transition to the next processing. Data can be
written only to blank or erased blocks; data cannot be written again (overwritten) to an area that has been
written to.
Note: Internal verification checks if the signal levels of the flash memory cells are correct. It does not compare
data.
This chapter describes the hardware environment and software environment required to rewrite the code flash
memory using the flash self-programming library.
2. 1 Hardware Environment
Flash self-programming of the RL78 microcontroller uses the sequencer to control rewriting of the flash memory.
During the control of the sequencer, the code flash memory cannot be referred to. Therefore, if the user program
needs to be operated during sequencer control such as an interruptNote, some segments of the flash
self-programming library and the user program must be allocated in the RAM to control erasure and writing to the
code flash memory or setting of the security flag. If it is not necessary to operate the user program during
sequencer control, the flash self-programming library and user program can be allocated on the ROM for
operation.
Figure 2-1 shows the state during a rewrite of the code flash memory. Figure 2-2 and Figure 2-3 show
examples of execution of flash functions for rewriting of the code flash memory.
Note. Some RL78 microcontrollers do not support an interrupt during the execution of flash self-programming.
Refer to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to be
used supports an interrupt during the execution of the flash self-programming.
After a request of the desired processing execution is made to the sequencer of the RL78 microcontroller, the
control is immediately returned to the user program. Because the sequencer controls the code flash memory, the
user program can operate during the rewrite of the code flash memory. This is called BGO (background
operation). To use this mode, select the status check user mode when initializing the Flash Self-Programming
Library Type 01.
However, the code flash memory cannot be referred to while the sequencer is controlling the code flash memory.
Therefore, the user program that operates during code flash memory operation, the branch destination of the
interrupt, the interrupt processing, and some segments of the flash self-programming library need to be allocated
on the RAM.
For the result of the control of the code flash memory, the status check function (FSL_StatusCheck function)
must be called from the user program to check the control state of the code flash memory.
Figure 2-2. Example 1 Rewrite Control of Flash (When User Program Operates during Rewrite)
Call
Execute
On going
Ret (BUSY)
Call
Execute
Code flash memory
On going cannot be referred to
during this period.
Ret (BUSY)
Call
Execute
Finish
Ret (OK)
After a request of the desired processing execution is made to the sequencer of the RL78 microcontroller, the
control is not returned to the user program until the corresponding processing of the sequencer is completed.
Because the control returns to the user program after the control of the code flash memory is completed, the user
program and flash self-programming can be allocated on the ROM. To use this mode, select the status check
internal mode when initializing the Flash Self-Programming Library Type 01.
However, if it is required to receive an interrupt during the control of the code flash memory, the branch
destination of the interrupt and interrupt processing must be allocated on the RAM. If they are allocated on the
ROM, part of the flash functions cannot be used. For details of the flash functions, refer to CHAPTER 6 FLASH
FUNCTIONS.
Figure 2-3. Example 2 Rewrite Control of Flash (When User Program Does Not Operate during Rewrite)
Call
Execute
On going
Execute
Code flash memory
On going cannot be referred to
during this period.
Execute
Finish
Ret
2. 1. 1 Initialization
When rewriting the code flash memory by using the flash self-programming library, make the following
settings.
Notes 1. The CPU operating frequency is used as a parameter for the calculation of internal timing in the flash
self-programming library. This setting does not affect the CPU operating frequency. This is not the
operating frequency for the high-speed on-chip oscillator.
2. For details of the flash memory programming mode, see the target RL78 microcontroller user’s
manual.
2. 1. 2 Blocks
The flash memory of the RL78 microcontroller is divided into 1 Kbyte blocks. In flash self-programming,
erasure processing, blank check processing, and verification (internal verification) processing are performed for
the code flash memory in the units of the blocks. To call these flash self-programming library functions, specify
a block number.
The boot clusterNote is the area provided to prevent the user program from being unable to boot up due to
destruction of the vector table data or program basic functions caused by an instantaneous power interruption or
resetting during a rewrite while the area including the vector area is being rewritten. For details, refer to
CHAPTER 5 BOOT SWAP FUNCTIONNote.
Figure 2-4 shows block numbers and boot clusters.
Note To use this function, the RL78 microcontroller supporting the boot swap function is required.
To find if your RL78 microcontroller supports the boot swap function, refer to the user's manual of the
target RL78 microcontroller.
Figure 2-4. Example of Block Numbers and Boot Clusters (RL78/G13: When Code Flash Memory Is 32
07FFFH Kbytes)
07C00H
Block 31
07800H
Block 30
07400H
Block 29
07000H
Block 28
06C00H
Block 27
06800H
Block 26
06400H
Block 25
06000H
Block 24
05C00H
Block 23
05800H
Block 22
05400H
Block 21
05000H
Block 20
04C00H
Block 19
04800H
Block 18
04400H
Block 17
04000H
Block 16
03C00H
Block 15
03800H
Block 14
01FFFH
03400H
Block 13
03000H
Block 12
02C00H
Block 11
Boot swap
02800H
Block 10 target area
02400H
Block 9
02000H
Block 8
01FFFH
01C00H
Block 7 01000H
00FFFH
01800H
Block 6
Boot cluster 1
Block 5 Program area
01400H
01000H
Block 4 000CEH
00FFFH 000CDH On-chip debug security ID
00C00H
Block 3 000C4H setting area 10 bytes
000C3H
Block 2 Option byte
00800H Boot cluster 0 000C0H
000BFH
00400H
Block 1 00080H
CALLT table 64 bytes
0007FH
00000H
Block 0 00000H 00000H Vector table 128 bytes
(1) Flash self-programming library function processing time in status check user mode
The flash self-programming library function processing time is the time required from when a user-created
program calls a flash function until the processing ends and control returns to the user-created program. The
flash function processing time differs depending on the status check mode.
This section shows the flash function processing time in the status check user mode.
FSL_Write
Status = BUSY
Status = BUSY
FSL_StatusCheck
Status = BUSY
FSL_StatusCheck
Status = OK
Table 2-1. Flash Function Processing Time in Status Check User Mode (Full Speed Mode)
FSL_Open 10 / fCLK
FSL_Close 10 / fCLK
FSL_ForceReset
FSL_GetVersionString 10 / fCLK
Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
Table 2-2. Flash Function Processing Time in Status Check User Mode (Wide Voltage Mode)
FSL_Open 10 / fCLK
FSL_Close 10 / fCLK
FSL_ForceReset
FSL_GetVersionString 10 / fCLK
Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
(2) Flash self-programming library function processing time in status check internal mode
This section shows the flash function processing time in the status check internal mode.
Figure 2-6. Overview of Flash Function Processing Time in Status Check Internal Mode
FSL_Write
Status = OK
Table 2-3. Flash Function Processing Time in Status Check Internal Mode (Full Speed Mode)
FSL_Open 10 / fCLK
FSL_Close 10 / fCLK
FSL_StatusCheck
FSL_StandBy
FSL_WakeUp
FSL_ForceReset
FSL_GetVersionString 10 / fCLK
Remarks 1. fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
2. W: The number of words to be written (1 word = 4 bytes)
(For example, when specifying 2 words = 8 bytes, W is 2.)
Table 2-4. Flash Function Processing Time in Status Check Internal Mode (Wide Voltage Mode)
FSL_Open 10 / fCLK
FSL_Close 10 / fCLK
FSL_Write
3121 / fCLK + 66 3121 / fCLK+ 66
+ (591 / fCLK + 112) × W + (1108 / fCLK + 1085) × W
FSL_StatusCheck
FSL_StandBy
FSL_WakeUp
FSL_ForceReset
FSL_GetVersionString 10 / fCLK
Remarks 1. fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
2. W: The number of words to be written (1 word = 4 bytes)
(For example, when specifying 2 words = 8 bytes, W is 2.)
When writing 12 bytes in the status check user mode, the sequencer writes data in a 4-byte unit. Therefore,
when 4-byte is written, the FSL_StatusCheck function must trigger the next write. If the FSL_StatusCheck
function is not executed while there are still bytes to be written, the next write does not start, and thus the write
process does not end.
Figure 2-7. Overview of Interval for Checking Status When Using FSL_Write (When Writing 12 bytes)
FSL_Write
Write trigger
Status = BUSY
4-byte write
Call interval
FSL_StatusCheck
1st write ends
Write trigger
Status = BUSY
4-byte write
Call interval
FSL_StatusCheck 2nd write ends
Write trigger
Status = BUSY
4-byte write
Call interval
FSL_StatusCheck
3rd write ends
Status = OK
When a process is executed by a function other than FSL_Write in the status check user mode, the
sequencer is in the busy state until all processes end. A trigger by the FSL_StatusCheck function is therefore
not required.
Figure 2-8. Overview of Interval for Checking Status When Using a Function Other Than FSL_Write
(When Erasing Flash Memory)
FSL_Erase
Erase trigger
Status = BUSY
1-block erase
Call interval
FSL_StatusCheck
Erase ends
Status = OK
Table 2-5. Recommended Interval of Status Check in Status Check User Mode (Full Speed Mode)
FSL_Init
FSL_Open
FSL_Close
FSL_PrepareFunctions
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
FSL_RestoreInterruptTable
FSL_GetSecurityFlags
FSL_GetBootFlag
FSL_GetSwapState
FSL_GetBlockEndAddr
FSL_GetFlashShieldWindow
FSL_SwapBootCluster
FSL_SwapActiveBootCluster
FSL_InvertBootFlag
FSL_SetBlockEraseProtectFlag
6431 / fCLK + 7053
FSL_SetWriteProtectFlag
FSL_SetBootClusterProtectFlag
FSL_SetFlashShieldWindow
FSL_StatusCheck
FSL_StandBy
FSL_ForceReset
FSL_GetVersionString
Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
Note The value shown for the FSL_Write function indicates the recommended interval per 4-byte.
Table 2-6. Recommended Interval of Status Check in Status Check User Mode (Wide Voltage Mode)
FSL_Init
FSL_Open
FSL_Close
FSL_PrepareFunctions
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
FSL_RestoreInterruptTable
FSL_GetSecurityFlags
FSL_GetBootFlag
FSL_GetSwapState
FSL_GetBlockEndAddr
FSL_GetFlashShieldWindow
FSL_SwapBootCluster
FSL_SwapActiveBootCluster
FSL_InvertBootFlag
FSL_SetBlockEraseProtectFlag
5728 / fCLK + 8445
FSL_SetWriteProtectFlag
FSL_SetBootClusterProtectFlag
FSL_SetFlashShieldWindow
FSL_StatusCheck
FSL_StandBy
FSL_ForceReset
FSL_GetVersionString
Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)
Note The value shown for the FSL_Write function indicates the recommended interval per 4-byte.
2. 2 Software Environment
Because the flash self-programming library program needs to be allocated to a user-created program area,
the size of the program code will be consumed in the program area.
To run the flash self-programming library, the CPU, stack, and data buffer are used.
Flash Self-Programming Library Type 01 has two versions: one is for the CA78K0R compiler (V2.20) and the
other is for the CC-RL compiler (V2.21). In some tables below, the library for the CA78K0R compiler (V2.20) is
abbreviated to CA78 and that for the CC-RL compiler (V2.21) is abbreviated to CCRL.
Tables 2-7 lists the software resources requiredNote1, 2, and Figures 2-9 and 2-10 show examples of
arrangement in RAM.
Size (byte)
Item Restrictions on Allocation and UsageNotes1,2
CA78 CCRL
The self-RAM area used by RL78 Family Flash
Self-Programming Library Type 01 differs depending on the
Self-RAMNote3 0 to 1024Note3 0 to 1024Note3
device. For details, refer to "RL78 Family Self RAM list of Flash
Self Programming Library(R20UT2944)".
Notes: 1. For devices not shown in the RL78 Family Self RAM list of Flash Self Programming Library (R20UT2944),
contact your Renesas sales agency.
2. The R5F10266 product does not support the self-programming function.
3. An area used as the working area by the flash self-programming library is called self-RAM in this manual
and the Release Note. The self-RAM requires no user settings because it is an area that is not mapped
and automatically used at execution of the flash self-programming library (previous data is discarded).
When the flash self-programming library is not used, the self-RAM can be used as a normal RAM space.
4. The data buffer is used as the working area for flash self-programming library internal processing or the
area where the data to be set is allocated by the FSL_Write function. The required size depends on the
function to be used.
No allocation restriction
RAM
4 Kbytes
FF300H
FF2FFH
Mirror
RAM
2 Kbytes
No allocation restriction
FF700H
FF6FFH
Mirror
Note Each size does not include the stack size used by the caller to call the FSL function.
Note The FSL_Write function requires an amount of memory equal to the data to be written (in words).
For example, when writing 2 words (1 word = 4 bytes), the required amount of memory is: 2 × 4 = 8 bytes
(2) Code size when allocating some functions to RAM (when using BGO)
Table 2-11 shows the code size required when using the background operation (BGO) feature during flash
self-programming. When using the BGO feature, the FSL_RCD segment must be allocated to RAM. To
copy the FSL_RCD segment to RAM, the program must be ROMized. Therefore, an additional ROM
capacity equivalent to the FSL_RCD segment size is required.
Remark The above table only describes the code size of the flash self-programming library. When using BGO,
the user-created program must be allocated to RAM, and therefore a RAM capacity equivalent to the
user-created program is also required. Moreover, a RAM capacity equivalent to the program ROMized
and copied to RAM is required. For details about ROMization, see user's manual of the development
tools to be used.
2. 2. 1 Self-RAM
The flash self-programming library may use a RAM area of 1 Kbyte as the working area. This area is called
the "self-RAM." The data used in the self-RAM is defined within the library, so no user definition is required.
When a flash self-programming library function is called, the data in the self-RAM area is rewritten.
The self-RAM area used for flash self-programming varies depending on the microcontroller, and the user
RAM may be used in some devices. In such a device, the user needs to allocate the self-RAM area to the user
RAM; be sure to allocate the self-RAM area at linkage. (In the CA78K0R compiler, the self-RAM area can be
specified in the link directive file. In the CC-RL compiler, leave a space unallocated to any section so that the
area can automatically be used as the self-RAM area.)
For the settings in the link directive file, refer to the section "Defining the Internal RAM Area" in the Release
Note.
2. 2. 2 Register bank
The flash self-programming library uses the general registers, ES/CS registers, SP, and PSW of the register
bank selected by the user.
Remark To allocate the stack and data buffer to the user-specified addresses, use the link directive in the
CA78K0R compiler, or make section allocation settings through a linker option in the CC-RL compiler.
Stack
In addition to the stack used by the user program, the stack space required for flash functions must be
reserved in advance, and they must be allocated so that the RAM used by the user will not be destroyed in
stack processing during flash self-programming operation. The available range for stack specification is
the internal RAM excluding the self-RAM and addresses FFE20H-FFEFFH.
Data buffer
The data buffer is used as the working area used for flash self-programming library internal processing or
the area where the data to be set is allocated in the FSL_Write function.
The available range for the start address of the data buffer is the internal RAM excluding the self-RAM and
addresses FFE20H-FFEFFH., as in the stack.
Note For the assembly language, delete unnecessary flash functions from the include file to link only the
functions to be used.
2. 2. 5 Program area
This is the area in which the flash self-programming library and the user program using the flash
self-programming library are allocated.
In flash self-programming of the RL78 microcontroller, the user program can operate during rewriting of the
code flash memory because the code flash memory is rewritten by using the sequencer (background operation).
However, the program allocated in the code flash memory cannot be referred to during rewriting of the code
flash memory, so some segments used by the user program and flash functions need to be allocated on the
RAM depending on usage.
For details, refer to the sections of CHAPTER 6 FLASH FUNCTIONS.
2. 2. 6 ROMization of programs
To allocate the user program and library using flash self-programming on the RAM, the target program must
be ROMized and allocated to the code flash memory, and the program must be copied to the RAM before it is
used in flash self-programming.
For the ROMization function of the program allocated on the RAM, refer to the user's manual attached to the
development tool used.
(1) Do not execute the EEPROM emulation library or data flash library during the execution of flash
self-programming. When using the EEPROM emulation library or data flash library, always execute up to
FSL_Close to close the flash self-programming library.
When using the flash self-programming library after the execution of the EEPROM emulation library or data flash
library, the flash self-programming processing must be started from the initialization function (FSL_Init).
(2) Do not execute the STOP or HALT instruction during the execution of flash self-programming. If the STOP or
HALT instruction needs to be executed, pause flash self-programming with the FSL_StandBy function, or
execute processing up to the FSL_Close function to close flash self-programming.
(3) The watchdog timer does not stop during the execution of self-programming. In the status check internal mode,
do not make the watchdog timer interrupt interval shorter than the execution time of FSL_SetXXX,
FSL_SwapActiveBootCluster, and FSL_InvertBootFlag.
(4) The code flash memory cannot be read during code flash memory operation by flash self-programming.
(5) Do not allocate the data buffer (arguments) or stack used in the flash function to an area starting from address
0xFFE20 (0xFE20).
(6) When using the data transfer controller (DTC) during the execution of flash self-programming, do not allocate the
RAM area used by the DTC to the self-RAM or an area starting from address FFE20H(FE20H).
(7) Do not destroy the RAM area (including self-RAM) used by flash self-programming until flash self-programming
is complete.
(8) Do not execute a flash function within interrupt processing. The flash function does not support nested
execution of functions. If a flash function is executed within interrupt processing, operation cannot be
guaranteed.
(9) When executing flash self-programming on the operating system, do not execute flash functions from multiple
tasks. The flash function does not support multiple executions of functions. If a flash function is executed in
multiple tasks, operation cannot be guaranteed.
(10) Before starting flash self-programming, the high-speed on-chip oscillator needs to be started. (The RL78
microcontroller hardware uses it during flash programming.)
(11) Note the following regarding the operating frequency of the CPU and the operating frequency value set with the
initialization function (FSL_Init).
- When a frequency below 4 MHzNote is used as the operating frequency of the CPU, 1 MHz, 2 MHz, or 3 MHz
can be used (a frequency such as 1.5 MHz that is not an integer value cannot be used). Also, set an integer
value such as 1, 2, or 3 as the operating frequency value with the initialization function.
- When 4 MHzNote or a higher frequency is used as the operating frequency of the CPU, a frequency with decimal
places can be used. However, set a rounded up integer value as the operating frequency with the
initialization function (FSL_Init).
(Example: For 4.5 MHz, set "5" with the initialization function.)
- This operating frequency is not the frequency of the high-speed on-chip oscillator (when the high-speed
on-chip oscillator is not used to generate the operating frequency of the CPU).
Note For the range of the maximum operating frequency of the CPU, refer to the user's manual of the target
RL78 microcontroller.
(12) Initialize the arguments (RAM) that are used by the flash self-programming library functions. When they are not
initialized, a RAM parity error is detected and the RL78 microcontroller might be reset.
For a RAM parity error, refer to the user’s manual of the target RL78 microcontroller.
(13) In the code flash memory, only an area in the blank state or the area that has been erased can be written to. An
area that has been written cannot be rewritten (overwritten) unless it has been erased. When rewriting is
performed without erasing data, the code flash memory might be damaged.
(14) The R5F10266 product cannot use the flash self-programming function.
(15) Some RL78 microcontrollers do not support an interrupt during the execution of flash self-programming. Refer
to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to be used
supports an interrupt during the execution of the flash self-programming.
(16) Some RL78 microcontrollers do not support the boot swap function. Refer to the user’s manual of the target
RL78 microcontroller to see whether the RL78 microcontroller to be used supports the boot swap function.
(17) Some RL78 microcontrollers do not support the security setting function by the flash self-programming. Refer
to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to be used
supports the security setting function by the flash self-programming.
(18) Do not arrange the segments FSL_BCD and FSL_BECD in the final address at a 64 Kbytes boundary (?FFFEH
to ?FFFFH) when using the flash self-programming library. (This applies only to V2.20 and older versions of flash
self-programming library; it does not apply to V2.21 and later versions because the issue regarding this
restriction has been resolved.)
(19) Each segment (FSL_FCD, FSL_FECD, FSL_RCD, FSL_BCD, or FSL_BECD) of the Flash Self-Programming
Library for the CC-RL compiler for the RL78 family cannot be allocated to extend across the 64 Kbytes boundary.
Be sure to allocate segments so that they do not extend across the 64 Kbytes boundary.
(20) When using an assembler of the CC-RL compiler from Renesas Electronics, the hexadecimal prefix
representation (0x..) cannot be mixed together with the suffix representation (..H). Specify the representation
method by editing the symbol definition in fsl.inc to match the user environment.
fsl.inc
; FSL_INC_BASE_NUMBER_SUFFIX .SET 1
When symbol "FSL_INC_BASE_NUMBER_SUFFIX" is not defined (initial state), the prefix representation will be
selected.
fsl.inc
FSL_INC_BASE_NUMBER_SUFFIX .SET 1
When symbol "FSL_INC_BASE_NUMBER_SUFFIX" is defined, the suffix representation will be selected.
3. 1 Overview
Interrupt processing can be used even in the flash environment stateNote. However, when the code flash
memory is controlled, the interrupt vector of a normal user application cannot be used. The interrupt vector needs
to be set to the RAM by using the interrupt vector change function (FSL_ChangeInterruptTable). Also, the
interrupt routine needs to be allocated on the RAM. After the setting, execution branches to one vector on the
RAM when any interrupt occurs. Therefore, if there are multiple interrupt sources for which you want to execute
different processing, the interrupt sources need to be identified.
To restore the interrupt to the original vector state after the completion of the rewrite of the code flash memory,
use the interrupt vector restoration function (FSL_RestoreInterruptTable) to restore the interrupt destination to the
original state.
Note. Some RL78 microcontrollers do not support an interrupt during the execution of flash self-programming.
Refer to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to
be used supports an interrupt during the execution of the flash self-programming.
Interrupts during code flash memory control cannot be received through the normal interrupt vector because the
code flash memory cannot be referred to. Therefore, to receive interrupts, they need to be received on the RAM.
On-chip RAM ・
Interrupt processing for the RAM Address of the RAM specified as the interrupt
destination = Beginning address of the interrupt
function allocated
3. 3 Cautions on Interrupts
- When changing the interrupt vector with the interrupt vector change function in the application, disable
interrupts from the start to the end of the switching procedure.
- Do not specify a value over FFE20H as the changed destination of the interrupt vector address.
- Access to the code flash memory area is prohibited in interrupt processing during the execution of flash
self-programming.
- The interrupt source can be determined by referring to SFR (interrupt request flag IF) when an interrupt
occurs on the RAM. After the determination, clear the interrupt request flag (set to 0).
- The response time for interrupt processing on the RAM increases by a maximum of 20 clock cycles compared
to the normal interrupt response time.
- To restore the original interrupt vector after the interrupt destination is changed with the interrupt vector
change function, the interrupt vector restoration function must be executed. If the interrupt vector restoration
function is not executed, the interrupt destination will remain changed even when flash self-programming is
finished.
- When a reset is done after the interrupt destination is changed with the interrupt vector change function, the
system starts up with the interrupt destination recovered.
- Some RL78 microcontrollers do not support an interrupt during the execution of flash self-programming.
Refer to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to be
used supports an interrupt during the execution of the flash self-programming.
The security function that prohibits rewriting of the user program written in the code flash memory is supported to
prevent falsification of programs by a third party.
For details of security settings, refer to the manual of the target device.
Note. Some RL78 microcontrollers do not support the security setting function provided by the flash
self-programming.
Refer to the user’s manual of the target RL78 microcontroller to see whether the RL78 microcontroller to be
used supports the security setting function by the flash self-programming.
4. 1 Security Flags
The flash self-programming library has functions to set the security flags (for details of the API of the functions,
refer to CHAPTER 6 FLASH FUNCTION).
FSL_SetBootClusterProtectFlag Sets the boot area (boot cluster 0) rewrite protection flag to protected.
One of the security functions that can be used during the execution of flash self-programming is the flash shield
window function. The flash shield window function is a security function that prohibits writing and erasure outside
the specified window range only during the execution of flash self-programming. The window range can be set by
specifying the start block and end block. The areas other than the window range are write-protected and
erasure-protected during the execution of flash self-programming.
5. 1 Overview
When rewriting fails due to an instantaneous power interruption or resetting caused by an external factor while
the area in which the vector table data, program basic functions, and the flash self-programming library are
allocated is being rewritten, the data being rewritten is destroyed, so restart or rewrite of the user program due to
the subsequent reset cannot be done. The boot swap function avoids this situationNote.
Note To use this function, the RL78 microcontroller supporting the boot swap function is required. To find if
your RL78 microcontroller supports the boot swap function, refer to the user's manual of the target RL78
microcontroller.
The boot swap function replaces the boot program area Boot Cluster 0Note with the boot swap target area Boot
Cluster 1Note.
Before performing rewrite processing, a new boot program is written to Boot Cluster 1 in advance. Boot Cluster
1 and Boot Cluster 0 are swapped to make Boot Cluster 1 the boot program area.
As a result, the program operates normally because booting is done from Boot Cluster 1 in the next reset start
even when an instantaneous power interruption occurs during rewriting of the boot program area. After that,
erasure or write processing to Boot Cluster 0 can be performed if necessary.
Figure 5-1 shows an example of the flow of boot swapping using the flash self-programming library.
<1> Pre-processing
<2> FSL_Erase
No
Normal completion?
Yes
<3> FSL_Write
No
Normal completion?
Yes
<4> FSL_IVerify
No
Normal completion?
Yes
<5> FSL_GetSecurityFlags
No
Rewritable?
Yes
<6> FSL_InvertBootFlag
No
Normal completion?
Yes
<7> Reset
No
<8> Rewrite Cluster 0? A
Yes
<9> Pre-processing
<10> FSL_Erase
No
Normal completion?
Yes
<11> FSL_Write
No
Normal completion?
Yes
<12> FSL_IVerify
No
Normal completion?
Yes
<1> Preprocessing
Boot swap preprocessing
- Setting of the software environment (reserving data buffer, etc.)
- Initialization of flash self-programming (execution of the FSL_Init function)
- Start of the flash environment (execution of the FSL_Open function)
- Preparation processing of the flash function (execution of the FSL_PrepareFunctions function)
- Preparation processing of the flash function (extension function) (execution of the
FSL_PrepareExtFunctions function)
- RAM expansion processing of the ROMization code if the rewrite program is ROMized
Boot Boot
Program area Erase
cluster 1 cluster 1
Boot Boot
cluster 0 On-chip debug security ID cluster 0 On-chip debug security ID
setting area setting area
Remark The FSL_Write function performs writing in units of words (1 word = 4 bytes, up to 64 words (256
bytes))
On-chip RAM
Boot Boot
cluster 0 On-chip debug security ID cluster 0 On-chip debug security ID
setting area setting area
Remark If the (Boot Cluster 0) rewrite protection flag is 0 (protected), an error occurs when the
FSL_InvertBootFlag function is called in <6>.
Program area
Boot Boot
New boot program
cluster 1 cluster 0 On-chip debug security ID
setting area
Option byte
CALLT table
Vector table
Program area
CALLT table
Vector table
<9> Preprocessing
The same processing as <1> is performed.
Program area
Boot
Boot
cluster 0 Erase
On-chip debug security ID cluster 0
setting area
Option byte
CALLT table
Vector table
Boot Boot
cluster 1 New boot program cluster 1 New boot program
Boot Boot
Already erased New program
cluster 0 cluster 0
- Boot swapping cannot be executed when the boot area (Boot Cluster 0) rewrite protection flag is set to 0
(protected).
- After a function for boot swapping is executed, control returns to the area from which the function was called.
Therefore, the program that calls boot swap functions must not be stored in either Boot Cluster 0 or 1.
Remark Applicable function: FSL_SwapBootCluster and FSL_SwapActiveBootCluster
- Specific cautions should be taken for each flash function providing the boot swap function. For details, refer
to CHAPTER 6 FLASH FUNCTIONS.
This chapter describes the details of the flash functions (functions in the flash self-programming library).
<R> Note For the RL78/G12, L12, and G1G groups, only basic functions are supported and the other functions are not
supported. For the RL78/G11 group, only the status check internal mode is supported as the status check mode.
The codes of the flash functions are divided into some groups and must be allocated to specified areas. These
groups are used as segments for memory allocation in the CA78K0R compiler. They are used as sections in the
CC-RL compiler.
The segments (sections) are classified as follows.
• FSL_FCD: A group of functions that initialize the environment. They can be allocated to the ROM or RAM.
• FSL_FECD: A group of functions that read security information, etc. They can be allocated to the ROM or
RAM.
• FSL_RCD: A group of functions required to rewrite the flash. They can be allocated to the RAM. There
Note
are some usage restrictions when they are allocated to the ROM.
• FSL_BCD: Area used by the FSL_PrepareFunctions function. They can be allocated to the ROM or RAM.
• FSL_BECD: Area used by the FSL_PrepareExtFunctions function. They can be allocated to the ROM or
RAM.
When using the flash self-programming library for the CC-RL compiler, read "segment" as "section" in the
following descriptions.
FSL_Init FSL_FCD ○ ○
FSL_Open FSL_FCD ○ ○
FSL_Close FSL_FCD ○ ○
FSL_PrepareFunctions FSL_FCD / FSL_BCD ○ ○
FSL_PrepareExtFunctions FSL_FCD / FSL_BECD ○ ○
FSL_ChangeInterruptTable FSL_FCD ○ ○
FSL_RestoreInterruptTable FSL_FCD ○ ○
FSL_BlankCheck FSL_RCD △Note ○
FSL_Erase FSL_RCD △ Note
○
FSL_IVerify FSL_RCD △ Note
○
FSL_Write FSL_RCD △ Note
○
FSL_GetSecurityFlags FSL_FECD ○ ○
FSL_GetBootFlag FSL_FECD ○ ○
FSL_GetSwapState FSL_FECD ○ ○
FSL_GetBlockEndAddr FSL_FECD ○ ○
FSL_GetFlashShieldWindow FSL_FECD ○ ○
FSL_SwapBootCluster FSL_RCD △ Note
○
FSL_SwapActiveBootCluster FSL_RCD × ○
FSL_InvertBootFlag FSL_RCD △ Note
○
FSL_SetBlockEraseProtectFlag FSL_RCD △ Note
○
FSL_SetWriteProtectFlag FSL_RCD △Note ○
FSL_SetBootClusterProtectFlag FSL_RCD △Note ○
FSL_SetFlashShieldWindow FSL_RCD △Note ○
FSL_StatusCheck FSL_RCD △Note ○
FSL_StandBy FSL_RCD △ Note
○
FSL_WakeUp FSL_RCD △ Note
○
FSL_ForceReset FSL_RCD △ Note
○
FSL_GetVersionString FSL_FCD ○ ○
Note There are the following usage restrictions when they are allocated to the ROM.
• Do not use the FSL_SwapActiveBootCluster() function.
• Set the status check mode to the status check internal mode with the FSL_Init() function.
The flash functions can be divided into processing that does not use the sequencer and processing that uses the
sequencer, and they differ in the interrupt reception methods. For the processing that uses the sequencer, BGO
(background operation) can be performed.
The following table shows a list of the flash functions with the presence of sequencer control and their interrupt
reception areas.
Table 6-3. List of Interrupt Reception Areas and BGO of Flash Functions
Interrupt
Function name Sequencer control BGO function
receptionNote1
FSL_Init
FSL_Open
ROM: Allowed
FSL_Close
RAM: Allowed
FSL_PrepareFunctions No No
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
Not allowed
FSL_RestoreInterruptTable
FSL_BlankCheck
FSL_Erase ROM: Not allowed Yes
Yes
FSL_IVerify RAM: Allowed Only on the RAMNote2
FSL_Write
FSL_GetSecurityFlags
FSL_GetBootFlag
ROM: Allowed
FSL_GetSwapState
No RAM: Allowed No
FSL_GetBlockEndAddr
FSL_GetFlashShieldWindow
FSL_SwapBootCluster Not allowed
FSL_SwapActiveBootCluster
FSL_InvertBootFlag
FSL_SetBlockEraseProtectFlag Yes
FSL_SetWriteProtectFlag Only on the RAMNote2
ROM: Not allowed
FSL_SetBootClusterProtectFlag Yes
RAM: Allowed
FSL_SetFlashShieldWindow
FSL_StatusCheckNote3
FSL_StandByNote3
FSL_WakeUpNote3 No
FSL_ForceReset ROM: Allowed
No
FSL_GetVersionString RAM: Allowed
Notes 1. Whether or not interrupt reception during the execution of the function or during sequencer
control is allowed
ROM: Normal vector interrupt; RAM: Interrupt on the RAM
2. To execute BGO, the user program and part of the library must be allocated on the RAM.
3. This function does not have the BGO function because it checks the state of the sequencer
or stops and restarts the sequencer control during block erasure.
For the functions that can perform background operation by using the sequencer, a status check must be
performed to check the control state of the code flash memory.
There are the following two status check modes, which can be set with the FSL_Init() function. They have
different status check methods.
Function closed
It doesn't return during
Because it returns the write, but control is
immediately, other easy.
Writing Writing
processing can be executed. Status check Interrupts must be
processing processing
However, the ROM cannot received by the RAM
* ROM cannot * ROM cannot
be referred to until writing is until the processing is
be referred to be referred to
complete. complete as in the user
Status check
Also, the status must be mode.
checked until it is complete. Function end
Status check
The user can check
completion here.
Note Only the status check internal mode can be used for the segment (FSL_RCD) of some flash functions
with restrictions on the allocation on the ROM or when the user program is allocated on the ROM.
FSL_Init
FSL_Open
FSL_Close
FSL_PrepareFunctions No Not required
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
FSL_RestoreInterruptTable
FSL_BlankCheck
FSL_Erase
Yes Required
FSL_IVerify
FSL_Write
FSL_GetSecurityFlags
FSL_GetBootFlag
FSL_GetSwapState
No Not required
FSL_GetBlockEndAddr
FSL_GetFlashShieldWindow
FSL_SwapBootCluster
FSL_SwapActiveBootCluster
FSL_InvertBootFlag
FSL_SetBlockEraseProtectFlag
Required
FSL_SetWriteProtectFlag
FSL_SetBootClusterProtectFlag Yes
FSL_SetFlashShieldWindow
FSL_StatusCheckNote1
FSL_StandByNote1
FSL_WakeUpNote1,2 Not required
FSL_ForceReset
No
FSL_GetVersionString
Notes 1. The processing of this function does not require status checking because it is the function to perform
status checking or the function to stop or restart the sequencer control during block erasure.
2. To restart the block erasure processing (FSL_Erase), status checking is required to check the erasure
state of the block.
Figure 6-2 Example 1 of Status Check User Mode (FSL_Write: When writing 12 bytes data)
Figure 6-3 Example 2 of Status Check User Mode (Other than FSL_Write)
User Library
FSL_Erase function
executed
FSL_Erase function
ended
(Return value:
FSL_BUSY)
FSL_StatusCheck
Other processes can be function executed Sequencer
executed because the function executing
results are immediately returned. FSL_StatusCheck
However, the status should be function ended
verified until the functions are (Return value:
executed. FSL_BUSY)
FSL_StatusCheck
function executed
FSL_StatusCheck
function ended
(Return value:
End of FSL_OK)
processing
When you need to pause the sequencer control during block erasure while the flash function is being executed
in the status check user mode, the stand-by function (FSL_StandBy) can be used to pause the erasure processing
to put flash self-programming to the pause state. When the stand-by function is executed in a state other than
block erasure state, it waits until the previous processing is completed, and makes a transition to the pause state
after the completion.
When a transition to the pause state occurs, the code flash memory cannot be controlled. To return from the
pause state, the wakeup function (FSL_WakeUp) needs to be executed. If the block erasure is suspended, the
pause state is released to restart the block erasure. In other cases, only the pause state is released.
Erasure
processing
Pause instruction * ROM cannot Pause instruction Writing
be referred to processing
A transition to the pause
* ROM cannot
Pause state state occurs after waiting
be referred to
for the completion of
processing.
Pause state * A transition to the
* ROM can be pause state occurs
referred to immediately if no waiting Pause state
Restart instruction
is required.
Status check
End of
processing
Function name Sequencer control State when the stand-by function is executed
FSL_Init
FSL_Open
FSL_Close
FSL_PrepareFunctions No Not available
FSL_PrepareExtFunctions
FSL_ChangeInterruptTable
FSL_RestoreInterruptTable
FSL_BlankCheck Waits until the processing is completed,
and makes a transition to the pause state.
FSL_Erase Pauses the erasure processing, and
Yes
makes a transition to the pause state.
FSL_IVerify Waits until the processing is completes,
FSL_Write and makes a transition to the pause state.
FSL_GetSecurityFlags
FSL_GetBootFlag
FSL_GetSwapState
No Not available
FSL_GetBlockEndAddr
FSL_GetFlashShieldWindow
FSL_SwapBootCluster
FSL_SwapActiveBootCluster
FSL_InvertBootFlag
FSL_SetBlockEraseProtectFlag Waits until the processing is completed, and makes
FSL_SetWriteProtectFlag a transition to the pause state.
FSL_SetBootClusterProtectFlag Yes
FSL_SetFlashShieldWindow
FSL_StatusCheck
FSL_StandBy
FSL_WakeUp Not available
FSL_ForceReset
FSL_GetVersionString No
Flash function idle state Makes a transition to the pause state.
The general register used to pass a return value differs between the RENESAS CA78K0R and CC-RL
compilers.
The return value and the general register used in each compiler are as follows.
Return value
Development tool
C language Assembly language
[Overview]
Describes the function overview of this function.
[Format]
<C language>
Describes the format to call this function from a user program written in the C language.
<Assembler>
Describes the format to call this function from a user program written in the assembly language.
[Presetting]
Describes the presetting of this function.
[Function]
Describes the function details and cautions of this function.
[Argument]
Describes the argument of this function.
[Return Value]
Describes the return values from this function.
FSL_Init
[Overview]
Initialization of the flash self-programming environment
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_Init( __far fsl_descriptor_t* descriptor_pstr)
<Assembler>
CALL !_FSL_Init or CALL !!_FSL_Init
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
The flash self-programming library, data flash library, the program used to operate the data flash memory, and
EEPROM emulation library are not executed or have been ended.
The high-speed on-chip oscillator is running.
[Function]
Reserves and initializes the self-RAM used for flash self-programming. If a self-RAMNote1 exists, do not use it
until flash self-programming is finished.
Define the flash memory programming mode Note2 for flash self-programming in the argument
fsl_flash_voltage_u08.
0x00: Full-speed mode
Other than above: Wide voltage mode
Set the operating frequency of the CPU in the argument fsl_u08 fsl_frequency_u08. The set value is used for
the calculation of timing data in the flash self-programming library.Note3
For the value of the operating frequency of the CPU (fsl_frequency_u08), note the following.
- When a frequency below 4 MHzNote4 is used as the operating frequency of the RL78 microcontroller, 1 MHz,
2 MHz, or 3 MHz can be used (a frequency such as 1.5 MHz that is not an integer value cannot be used).
Set an integer value such as 1, 2, or 3 as the operating frequency value with the initialization function.
- When a frequency equal to or over 4 MHzNote4 is used as the operating frequency of the RL78
microcontroller, a frequency with decimal places can be used. However, set a rounded up integer value as
the operating frequency with the initialization function (FSL_Init).
(Example: For 4.5 MHz, set "5" with the initialization function.)
- This operating frequency is not the frequency of the high-speed on-chip oscillator.
Set the status check mode in the argument fsl_auto_status_check_u08.Note5 For differences between the
status check user mode and status check internal mode, refer to 2.1 Hardware Environment or 6.4 Status
Check Mode.
0x00: Status check user mode
Other than above: Status check internal mode
Notes 1.For the self-RAM, refer to the document "Release note" attached to the installer, or refer to the user's
manual of the target RL78 microcontroller.
2. For details of the flash memory programming mode, refer to the user's manual of the target RL78
microcontroller.
3. This is a required parameter for timing calculation in the flash self-programming library. This setting does
not change the operating frequency of the RL78 microcontroller.
4. For the range of the operating frequency, refer to the user's manual of the target RL78 microcontroller.
5. When allocating the FSL_RCD segment on the ROM, always use it in the status check internal mode.
[Argument]
Definition of argument
Argument Description
__far fsl_descriptor_t* descriptor_pstr Initial setting value of the Flash Self-Programming Library Type 01
(flash memory programming mode, CPU frequency, status check mode)
Argument Description
fsl_u08 fsl_flash_voltage_u08 Setting of the flash memory programming mode
fsl_u08 fsl_frequency_u08 CPU frequency during the execution of flash self-programming
fsl_u08 fsl_auto_status_check_u08 Setting of the status check mode
Argument Type/Register
Development tool
C language Assembly language
[Return Value]
State Description
FSL_Open
[Overview]
Start declaration of flash self-programming (starting of the flash environment)
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_Open(void)
<Assembler>
CALL !_FSL_Open or CALL !!_FSL_Open
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, the FSL_Init function must be completed normally.
[Function]
Performs start declaration of flash self-programming (starting of the flash environment). Call this function in the
beginning of flash self-programming operation.
[Argument]
None
[Return Value]
None
FSL_Close
[Overview]
End declaration of flash self-programming (ending of the flash environment)
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_Close(void)
<Assembler>
CALL !_FSL_Close or CALL !!_FSL_Close
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Performs end declaration of flash self-programming (ending of the flash environment). It ends write operation to
the code flash memory and returns execution to the normal operation mode.
[Argument]
None
[Return Value]
None
FSL_PrepareFunctions
[Overview]
Preparation for use of the flash functions (standard rewrite functions) requiring execution in RAM
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_PrepareFunctions( void )
<Assembler>
CALL !_FSL_PrepareFunctions or CALL !!_FSL_PrepareFunctions
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Prepares the following functions for use.
• FSL_BlankCheck
• FSL_Erase
• FSL_Write
• FSL_IVerify
• FSL_StatusCheck
• FSL_StandBy
• FSL_WakeUp
[Argument]
None
[Return Value]
None
FSL_PrepareExtFunctions
[Overview]
Preparation for use of the flash functions (extension functions) requiring execution in RAM
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_PrepareExtFunctions(void)
<Assembler>
CALL !_FSL_PrepareExtFunctions or CALL !!_FSL_PrepareExtFunctions
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Prepares the following functions for use.
• FSL_SwapBootCluster
• FSL_SwapActiveBootCluster
• FSL_InvertBootFlag
• FSL_SetBlockEraseProtectFlag
• FSL_SetWriteProtectFlag
• FSL_SetBootClusterProtectFlag
• FSL_SetFlashShieldWindow
[Argument]
None
[Return Value]
None
FSL_ChangeInterruptTable
[Overview]
Changing of all interrupt destinations to the specified addresses on the RAM
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_ChangeInterruptTable(fsl_u16 fsl_interrupt_destination_u16)
<Assembler>
CALL !_FSL_ChangeInterruptTable or CALL !!_FSL_ChangeInterruptTable
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
None
[Function]
Changes the destinations of all interrupt functions to the specified addresses on the RAM. After the execution of
this function, when an interrupt occurs, execution goes to the address on the RAM specified with this function
instead of jumping to the interrupt table.
Cautions 1. The type of the interrupt must be determined by the user by checking the interrupt flag. Because the
type of the interrupt must be determined by the user after the execution of this function, the interrupt
flag will not be cleared automatically. The user must clear the flag after determining the type of the
interrupt.
2. Do not specify a RAM address in the area that has restrictions on usage during the execution of flash
self-programming. The flash function may not operate correctly.
3. The interrupt change destination cannot be set to the ROM side (only the address range of FxxxxH
can be specified).
4. When the interrupt destination is changed with this function, the interrupt destination remains changed
even after flash self-programming until the interrupt destination is restored with the
FSL_RestoreInterruptTable() function or a reset is performed.
5. When changing the interrupt destination to the RAM with this function, disable interrupts from the start
to end of the processing.
Argument Description
RAM address of the interrupt destination (lower 16 bits: FxxxxH ) *Upper bits are not
fsl_u16 fsl_interrupt_destination_u16
required.
Argument Type/Register
Development tool
C language Assembly language
[Return Value]
None
[Operation Example]
DI
FSL_ChangeInterruptTable()
EI
FSL_RestoreInterruptTable
[Overview]
Restoration of the interrupt destination changed to the RAM to the standard interrupt vector table
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_RestoreInterruptTable( void )
<Assembler>
CALL !_FSL_RestoreInterruptTable or CALL !!_FSL_RestoreInterruptTable
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
None
[Function]
Restores the interrupt destination changed to the RAM to the standard interrupt vector table.
Cautions 1. If the interrupt destination is changed with the FSL_ChangeInterruptTable() function, the interrupt
destination remains changed even after flash self-programming until a reset is performed unless the
interrupt destination is restored with this function.
2. When changing the interrupt destination to the standard interrupt vector with this function, disable
interrupts from the start to end of the processing.
[Argument]
None
[Return Value]
None
DI
<R> FSL_RestoreInterruptTable()
EI
FSL_BlankCheck
[Overview]
Blank checking of the specified block
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_BlankCheck(fsl_u16 block_u16)
<Assembler>
CALL !_FSL_BlankCheck or CALL !!_FSL_BlankCheck
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete. Also, when an interrupt must be received before
the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt destination to the
RAM.
[Function]
Checks that the code flash memory of the specified block is in the erasure level.
(The erasure level check cannot be done in checking of 0xFF with data read.)
In case of an error, execute the FSL_Erase function.
If the execution of the FSL_Erase function is completed normally, no blank checking is required.
If the specified block number does not exist, a parameter error (0x05) is returned.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
Remarks 1. The FSL_BlankCheck function checks if the cell of the code flash memory satisfies the erasure
level with a sufficient margin. A blank check error does not indicate any problem in the code flash
memory, but perform erasure processing before writing after the blank check error.
2. A blank check is performed only for one block. To perform blank checking of multiple blocks, call
this function multiple times.
[Argument]
Definition of argument
Argument Description
Argument Type/Register
Development tool
C language Assembly language
RENESAS CA78K0R compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
RENESAS CC-RL compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
[Return Value]
State Description
FSL_Erase
[Overview]
Erasure of the specified block
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_Erase(fsl_u16 block_u16)
<Assembler>
CALL !_FSL_Erase or CALL !!_FSL_Erase
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete. Also, when an interrupt must be received before
the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt destination to the
RAM.
[Function]
Erases (0xFF) the content of the code flash memory in the specified block.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
Remark Erasure is performed only for one block. To erase multiple blocks, call this function multiple times.
Argument Description
Argument Type/Register
Development tool
C language Assembly language
RENESAS CA78K0R compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
RENESAS CC-RL compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
[Return Value]
State Description
FSL_IVerify
[Overview]
Verification (internal verification) of the specified block
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_IVerify(fsl_u16 block_u16)
Assembler>
CALL !_FSL_IVerify or CALL !!_FSL_IVerify
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete. Also, when an interrupt must be received before
the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt destination to the
RAM.
[Function]
Performs verification to check the write level in the specified block.
The verification checks if the data written to the code flash memory of the specified block is in the erasure level
(data "1") or write level (data "0").
In case of an error, execute the FSL_Erase function, and then perform writing with FSL_Write again.
If the specified block number does not exist, a parameter error (0x05) is returned.
Cautions 1. After data is written, if no verification (internal verification) is done for the block including the range to
which data is written, the written data is not guaranteed.
2. When data erasure, data write, and internal verification are performed and completed normally after
an internal verification error, the device is determined as normal.
3. If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
Remark Verification is performed only for one block. To perform verification of multiple blocks, call this
function multiple times.
[Argument]
Definition of argument
Argument Description
Argument Type/Register
Development tool
C language Assembly language
RENESAS CA78K0R compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
RENESAS CC-RL compiler fsl_u16 block_u16 AX(0-15): Block number (16 bits)
[Return Value]
State Description
FSL_Write
[Overview]
Writing of 1 word to 64 words data into the specified address (1 word = 4 bytes)
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_Write (__near fsl_write_t* write_pstr)
<Assembler>
CALL !_FSL_Write or CALL !!_FSL_Write
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
• Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
• Before calling this function, save the data to be written to the code flash memory in the data buffer.
[Function]
Writes to the code flash memory at the specified address.
After writing to a block, always execute FSL_IVerify for the block.
Execute the FSL_Write function only to an erased block.
Up to 256 bytes (in units of 4 bytes) of data can be written at once.
In the following cases (the specified word count or address is outside of the allowable setting range), a parameter
error (0x05) is returned.
Word count check
• 0 words
• 65 words or more
Address check
• Not in units of 4 bytes from the start address
• The write end address exceeds the final address of the code flash memory.
Notes 1. After writing data, execute verification (internal verification) of the block including the range to which data
is written. Otherwise, the written data is not guaranteed.
2. If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
Remark To write data larger than 256 bytes, call this function multiple times.
[Argument]
Definition of argument
Argument Description
Definition of fsl_write_t
Contents of fsl_write_t
Argument Description
fsl_u08 __near *fsl_data_buffer_p_u08 Start address of the buffer area where data to write is input (16 bits)
fsl_u32 fsl_destination_address_u32 Start address of the destination (32 bits)
fsl_u08 fsl_word_count_u08 Data count to write (1 to 64: in words)
Argument Type/Register
Development tool
C language Assembly language
State Description
Note1
0x00(FSL_OK) Normal completion
0x05(FSL_ERR_PARAMETER) Parameter error
- The start address is not a multiple of 1 word (4 bytes).
- The written data count is 0.
- The written data count exceeds 64 words.
- The write end address (start address + (written data count × 4 bytes)) exceeds the
code flash memory area.
0x10(FSL_ERR_PROTECTION) Protect error
- The specified range includes the boot area, and the boot area rewrite permission flag
is set to protected.
- The specified block is outside the FSW setting area.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_GetSecurityFlags
[Overview]
Acquisition of security information
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetSecurityFlags(fsl_u08 __near *data_destination_pu08)
<Assembler>
CALL !_FSL_GetSecurityFlags or CALL !!_FSL_GetSecurityFlags
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Obtains the security flag information and inputs the value to the data storage buffer specified in the argument.
[Argument]
Definition of argument
Argument Description
Argument Type/Register
Development tool
C language Assembly language
State Description
data_destination_pu08 Description
bit 1: 0b000000X0 Boot area rewrite protection flag (0: Protected, 1: Permitted)
bit 2: 0b00000X00 Block erasure protection flag (0: Protected, 1: Permitted)
bit 4: 0b000X0000 Write protection flag (0: Protected, 1: Permitted)
Other bits 1
FSL_GetBootFlag
[Overview]
Acquisition of boot flag information
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetBootFlag(fsl_u08 __near *data_destination_pu08)
<Assembler>
CALL !_FSL_GetBootFlag or CALL !!_FSL_GetBootFlag
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Obtains the boot cluster flag information and inputs the value to the data storage buffer specified in the argument.
[Argument]
Definition of argument
Argument Description
Argument Type/Register
Development tool
C language Assembly language
State Description
data_destination_pu08 Description
0x00 Starts up with Boot Cluster 0 as the boot area (from 0000H) after a reset.
0x01 Starts up with Boot Cluster 1 as the boot area (from 0000H) after a reset.
Remark For the swap state of the boot area before the reset, refer to the section on the FSL_GetSwapState
function.
Example RL78/G13: The boot area size (one cluster) is 4KB.
RL78/F13: The boot area size (one cluster) is 8KB.
FSL_GetSwapState
[Overview]
Acquisition of the swap state
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetSwapState(fsl_u08 __near *data_destination_pu08)
<Assembler>
CALL !_FSL_GetSwapState or CALL !!_FSL_GetSwapState
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must
make execution complete.
[Function]
Obtains the current boot cluster swap state and inputs the value to the data storage buffer specified in the
argument.
[Argument]
Definition of argument
Argument Description
Argument Type/Register
Development tool
C language Assembly language
State Description
data_destination_pu08 Description
0x00 The current boot area (The area from 0000H) is Boot Cluster 0.
0x01 The current boot area (The area from 0000H) is Boot Cluster 1.
Remark For the status of the boot area after the reset, refer to the section on the FSL_GetBootFlag function.
Example RL78/G13: The boot area size (one cluster) is 4KB.
RL78/F13: The boot area size (one cluster) is 8KB.
FSL_GetBlockEndAddr
[Overview]
Acquisition of the final address of the specified block
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetBlockEndAddr(__near fsl_getblockendaddr_t* getblockendaddr_pstr)
<Assembler>
CALL !_FSL_GetBlockEndAddr or CALL !!_FSL_GetBlockEndAddr
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Obtains the final address of the block specified in the argument and inputs the value to the data storage buffer.
[Argument]
Definition of argument
Argument Description
__near fsl_getblockendaddr_t* The pointer to the structure which obtains the end address of the specified block.
getblockendaddr_pstr
Definition of fsl_getblockendaddr_t
Contents of fsl_getblockendaddr_t
Argument Description
Argument Type/Register
Development tool
C language Assembly language
[Return Value]
State Description
FSL_GetFlashShieldWindow
[Overview]
Acquisition of the start block number and end block number of the flash shield window
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetFlashShieldWindow(__near fsl_fsw_t* getfsw_pstr);
<Assembler>
CALL !_FSL_GetFlashShieldWindow or CALL !!_FSL_GetFlashShieldWindow
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function must make
execution complete.
[Function]
Obtains the start block and end block of the flash shield window and inputs the values to the data storage buffers
fsl_start_block_u16 (start block) and fsl_end_block_u16 (end block) specified in the arguments, respectively.
[Argument]
Definition of argument
Argument Description
__near fsl_fsw_t* getfsw_pstr Variable for obtaining FSW settings
(FSW start block number and end block number)
Definition of fsl_fsw_t
Argument Description
Argument Type/Register
Development tool
C language Assembly language
[Return Value]
State Description
FSL_SwapBootCluster
[Overview]
Execution of boot swapping and jumping to the address registered in the reset vector in the swapped area
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SwapBootCluster(void)
<Assembler>
CALL !_FSL_SwapBootCluster or CALL !!_FSL_SwapBootCluster
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
Disables interrupts (DI) and performs swapping of the boot clusters immediately after the execution of the function.
Execution moves to the address registered to the reset vector in the swapped area (unlike the reset function of the
RL78 microcontroller, program execution is started only from the reset vector address).
Cautions 1. Do not execute this function in an RL78 microcontroller that does not support boot swapping.
2. Before the execution of swapping, always write the setting information required for operation after
swapping such as the option byte setting to the swap destination area.
3. When this function is executed normally, the code written after this function is not executed because
execution moves to the address registered in the reset vector in the swapped boot cluster.
4. This function does not invert the boot flag. When a reset is performed, the boot cluster enters the
state according to the boot flag setting.
5. When the FSL_ChangeInterruptTable function is executed with the interrupt destination changed,
interrupt processing will go to the area changed by the FSL_ChangeInterruptTable function even after
moving to the address registered in the reset vector. To move to the address registered in the
restored reset vector, execute the FSL_RestoreInterruptTable function to restore the interrupt
destination before executing this function.
6. If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
7. The FSL_SwapBootCluster function execute exchange for the boot cluster 0 and the boot cluster 1.
Do not locate the user program, data, and the flash self-programming library required for
programming on a boot cluster.
[Argument]
None
[Return Value]
State Description
[Flow]
FSL_SwapBootCluster
PUSH PSW
DI
YES
Error?
NO
FSL_SwapActiveBootCluster
[Overview]
Inverting of the current value of the boot flag and execution of boot swapping
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SwapActiveBootCluster(void)
<Assembler>
CALL !_FSL_SwapActiveBootCluster or CALL !!_FSL_SwapActiveBootCluster
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
When this function is executed, the current value of the boot flag is inverted, and boot clusters are swapped.
Cautions 1. Do not execute this function in an RL78 microcontroller that does not support boot swapping.
2. Before the execution of swapping, always write the setting information required for operation after
swapping such as the option byte setting to the swap destination area.
3. The boot clusters are swapped without a reset. Do not allocate the user program, data, or flash
self-programming library required for rewriting in the boot cluster. If it is required to refer to the
program or data in the boot cluster after the execution of this function, use it with considering that the
boot clusters are swapped.
4. This function cannot be executed from the ROM. To use this function, allocate the FSL_RCD
segment on the RAM.
5. After the execution of this function, the interrupt vector on the ROM is also changed. To use interrupt
processing on the ROM before and after the execution, use it with considering that the interrupt vector
on the ROM switches during operation.
6. When this function is used, the functions contained in the FSL_RCD segment cannot be allocated on
the ROM for use.
[Argument]
None
[Return Value]
State Description
Note1
0x00(FSL_OK) Normal completion
0x10(FSL_ERR_PROTECTION) Protect error
- Changing of the flag from protected to permitted was attempted.
- Changing of the boot area switching flag was attempted in the boot area
rewrite-protected state.
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_InvertBootFlag
[Overview]
Inverting of the current value of the boot flag
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_InvertBootFlag(void)
<Assembler>
CALL !_FSL_InvertBootFlag or CALL !!_FSL_InvertBootFlag
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
Inverts the current value of the boot flag. After a reset, the boot cluster enters the state according to the boot flag
setting.
Cautions 1. Do not execute this function in an RL78 microcontroller that does not support boot swapping.
2. The boot cluster is not inverted upon execution of this function.
3. If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x10(FSL_ERR_PROTECTION) Protect error
- Changing of the flag from protected to permitted was attempted.
- Changing of the boot area switching flag was attempted in the boot area
rewrite-protected state.
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_SetBlockEraseProtectFlag
[Overview]
Setting of the block erasure protection flag to protected
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetBlockEraseProtectFlag(void)
<Assembler>
CALL !_FSL_SetBlockEraseProtectFlag or CALL !!_FSL_SetBlockEraseProtectFlag
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
Sets the block erasure protection flag to protected. Block erasure for the device by the programmer cannot be
done.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_SetWriteProtectFlag
[Overview]
Setting of the write protection flag to protected
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetWriteProtectFlag(void)
<Assembler>
CALL !_FSL_SetWriteProtectFlag or CALL !!_FSL_SetWriteProtectFlag
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
Sets the write protection flag to protected. When it is set to protected, writing to the device by the programmer
cannot be done.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_SetBootClusterProtectFlag
[Overview]
Setting of the boot area rewrite protection flag to protected
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetBootClusterProtectFlag(void)
<Assembler>
CALL !_FSL_SetBootClusterProtectFlag or CALL !!_FSL_SetBootClusterProtectFlag
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareExtFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
[Function]
Sets the boot area rewrite protection flag to protected. When it is set to protected, swapping, erasure, and writing
to the boot cluster cannot be done.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_SetFlashShieldWindow
[Overview]
Setting of the flash shield window
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetFlashShieldWindow(__near fsl_fsw_t* setfsw_pstr)
<Assembler>
CALL !_FSL_SetFlashShieldWindow or CALL !!_FSL_SetFlashShieldWindow
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function,
FSL_PrepareFunctions function and FSL_PrepareExtFunctions function must make execution complete. Also,
when an interrupt must be received before the processing is completed, use the FSL_ChangeInterruptTable
function to change the interrupt destination to the RAM.
[Function]
Sets the flash shield window.
Caution If both (1) and (2) below are satisfied, this function can be allocated on the internal ROM for use.
(1) The status check mode is set to the status check internal mode with the FSL_Init function.
(2) "Do not use interrupts" or "disable interrupts on the internal ROM" until the processing of this
function is completed (the reception of interrupts on the RAM is permitted).
Remark The flash shield window function is incorporated as a security function used during the execution of
flash self-programming.
During the execution of flash self-programming, writing and erasure are permitted in the code flash
memory in the range specified as the window, but prohibited in the code flash memory outside the
specified range. However, during on-board/off-board programming, writing and erasure are
permitted even in the code flash memory outside the range specified as the window. When the
range specified as the window and the rewrite-protected area of Boot Cluster 0 overlap, rewrite
protection of Boot Cluster 0 has precedence.
Argument Description
__near fsl_fsw_t* setfsw_pstr Variable for FSW setting
(FSW start block number and end block number)
Argument Description
Argument Type/Register
Development tool
C language Assembly language
State Description
Note1
0x00(FSL_OK) Normal completion
0x05(FSL_ERR_PARAMETER) Parameter error
- The specification of the block number is outside the allowable setting range.
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note2
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note2
0xFF(FSL_BUSY) Execution start of this functionNote2
- The execution of this function has been started.
(Check the execution state with the FSL_StatusCheck function.)
FSL_StatusCheck
[Overview]
Checking of the operation state of the flash function
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_StatusCheck( void )
<Assembler>
CALL !_FSL_StatusCheck or CALL !!_FSL_StatusCheck
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
• Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete. Also, when an interrupt must be received
before the processing is completed, use the FSL_ChangeInterruptTable function to change the interrupt
destination to the RAM.
• This function can be used only in the status check user mode.
[Function]
Checks the start, progress, and status of the flash function executed immediately before.
[Argument]
None
State Description
Note
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote
- An error occurred during erasure processing.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote
- An error occurred during verification (internal verification) processing.
0x1B(FSL_ERR_BLANKCHECK) Blank check errorNote
- The specified block is not in the blank state.
0x1C(FSL_ERR_WRITE) Writing errorNote
- An error occurred during write processing.
0x1F(FSL_ERR_FLOW) Flow errorNote
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.
0x30(FSL_ERR_IDLE) Non-execution errorNote
- No processing is in progress.
0xFF(FSL_BUSY) Flash function in executionNote
- The flash function is in execution.
FSL_StandBy
[Overview]
Suspension of erasure processing (FSL_Erase) and pausing of flash self-programming
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_StandBy(void)
<Assembler>
CALL !_FSL_StandBy or CALL !!_FSL_StandBy
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
• Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete.
• This function can be used only in the status check user mode.
[Function]
Suspends erasure processing (FSL_Erase) being executed, and holds the erasure processing (FSL_Erase) in the
pause state until FSL_WakeUp is executed.
When this function is executed, flash self-programming enters the pause state, and flash self-programming cannot
be executed until FSL_WakeUp is executed.
Cautions 1. During a pause of flash self-programming, the flash functions cannot be executed.
To restart flash self-programming, the FSL_WakeUp function must be executed.
2. A transition to the pause state occurs unless the return value is a flow error.
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure processing before suspension.
0x1B(FSL_ERR_BLANKCHECK) Blank check errorNote1
- An error occurred during blank check processing before suspension.
0x1B(FSL_ERR_IVERIFY) Internal verification errorNote1
- An error occurred during verification (internal verification) processing before
suspension.
0x1C(FSL_ERR_WRITE) Writing errorNote1
- An error occurred during write processing before suspension.
0x1F(FSL_ERR_FLOW) Flow errorNote1 (does not result in the pause state)
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.
0x30(FSL_ERR_IDLE) Non-execution errorNote1
- No processing is in progress.
0x43(FSL_SUSPEND) Pausing of the flash functionNote1, 2
- The processing of the flash function in execution is paused.
FSL_WakeUp
[Overview]
Canceling of the pause state to restart flash self-programming
[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_WakeUp( void )
<Assembler>
CALL !_FSL_WakeUp or CALL !!_FSL_WakeUp
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
• Before the execution of this function, after FSL_Init function is completed normally, FSL_Open function and
FSL_PrepareFunctions function must make execution complete.
• This function can be used only in the status check user mode.
[Function]
Cancels the pause state and restarts flash self-programming. If block erasure processing is suspended, it is
restarted.
[Argument]
None
State Description
Note1
0x00(FSL_OK) Normal completion
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred in the restarted erasure processing.
0x1F(FSL_ERR_FLOW) Flow errorNote1
- The prerequisite defined in presetting is violated.
- Flash self-programming is not in the pause state.
0xFF(FSL_BUSY) Restarting of the flash functionNote1, 2
- The execution of the flash function was restarted.
(Check the execution state with the FSL_StatusCheck function.)
FSL_ForceReset
[Overview]
Resetting of the RL78 microcontroller in use
[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_ForceReset(void)
<Assembler>
CALL !_FSL_ForceReset or CALL !!_FSL_ForceReset
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
None
[Function]
Executes the command code of 0xFF to generate an internal reset of the RL78 microcontroller in use.
Cautions 1. The RL78 microcontroller in use is reset, so the code written after this function is not executed.
<R> 2. When this function is executed while E1,E2,E2 emulator Lite,E20 or IECUBE® is being used, a break
occurs and processing stops.
Normal operation cannot be done after the occurrence of a break. Execute a manual reset.
3. For the internal reset with the command code of 0xFF (internal reset through an illegal instruction),
refer to the user's manual of the target RL78 microcontroller.
[Argument]
None
[Return Value]
None
FSL_GetVersionString
[Overview]
Acquisition of the version of the flash self-programming library
[Format]
<C language>
RENESAS CA78K0R compiler
__far fsl_u08* FSL_GetVersionString( void )
<Assembler>
CALL !_FSL_GetVersionString or CALL !!_FSL_GetVersionString
Remark Call with "!" when the flash self-programming library is allocated at 00000H-0FFFFH, or call with "!!"
otherwise.
[Presetting]
None
[Function]
Obtains the start address that holds the version information of the flash self-programming library.
[Argument]
None
[Return Value]
Data type Description
__far fsl_u08* The version information storage start address of the flash self-programming library
(far area)
The version information of the flash self-programming library consists of ASCII characters.
Example: Flash Self-Programming Library Type 01
"SRL78T01LyyyzGVxxx"
Version information: Example:V221 → V2.21
Compiler information(5 or 6 characters): CA78K0R [ex:RyyyG]
CC-RL [ex:LyyyzG]
Type No.(3 characters): : T01 -> Type 01
Supported device(4 characters) : RL78
Target library(1 character) : ‘S’ is FSL
Here is the revision history of the preceding editions. Chapter indicates the chapter of each edition.
A description of the case when flash functions are executed in the RAM was added. Chapter 2 Programming
The formula for calculating the minimum time of FSL_BlankCheck was added. Environment
In Table 2-4, the formula for calculating the processing time for each function was
corrected.
The resources used to run the flash self-programming library were corrected.
In Table 2-7, the description of the self-RAM area was changed.
In note 1 on Table 2-7, the inquiry about device specifications was changed.
The restriction on versions up to 2.10 was deleted from Figure 2-9.
A note was added to Table 2-8 Stack Size Used by Flash Functions.
The description of the self-RAM was reviewed and corrected.
The available range for stack and data buffer specifications was corrected.
In (3), the description of the functions that require special care regarding the
watchdog timer operation was reviewed and corrected.
In (18), note on the prohibition of 64KB boundary arrangement added.
In Table 6-1, the column of basic functions added and position and description of Chapter 6 Flash
note was changed. Function
The status check mode was corrected from the user mode to the internal mode (in
table titles, etc.).
R01US0050EJ0105