REN R01us0050ej0105 rl78 MAT 20181031

Download as pdf or txt
Download as pdf or txt
You are on page 1of 121

表紙

User s Manual

RL78 Family
Flash Self-Programming Library Type 01
16 Japanese Release

Installer name: RENESAS_RL78_FSL_T01_xVxx


16-Bit Single-Chip Microcontrollers

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).

Rev.1.05 Oct 2018


Notice
1. Descriptions of circuits, software and other related information in this document are provided only to illustrate the operation of
semiconductor products and application examples. You are fully responsible for the incorporation or any other use of the circuits,
software, and information in the design of your product or system. Renesas Electronics disclaims any and all liability for any losses and
damages incurred by you or third parties arising from the use of these circuits, software, or information.
2. Renesas Electronics hereby expressly disclaims any warranties against and liability for infringement or any other claims involving patents,
copyrights, or other intellectual property rights of third parties, by or arising from the use of Renesas Electronics products or technical
information described in this document, including but not limited to, the product data, drawings, charts, programs, algorithms, and
application examples.
3. No license, express, implied or otherwise, is granted hereby under any patents, copyrights or other intellectual property rights of Renesas
Electronics or others.
4. You shall not alter, modify, copy, or reverse engineer any Renesas Electronics product, whether in whole or in part. Renesas Electronics
disclaims any and all liability for any losses or damages incurred by you or third parties arising from such alteration, modification,
copying or reverse engineering.
5. Renesas Electronics products are classified according to the following two quality grades: “Standard” and “High Quality”. The intended
applications for each Renesas Electronics product depends on the product’s quality grade, as indicated below.
“Standard”: Computers; office equipment; communications equipment; test and measurement equipment; audio and visual equipment;
home electronic appliances; machine tools; personal electronic equipment; industrial robots; etc.
“High Quality”: Transportation equipment (automobiles, trains, ships, etc.); traffic control (traffic lights); large-scale communication
equipment; key financial terminal systems; safety control equipment; etc.
Unless expressly designated as a high reliability product or a product for harsh environments in a Renesas Electronics data sheet or other
Renesas Electronics document, Renesas Electronics products are not intended or authorized for use in products or systems that may pose a
direct threat to human life or bodily injury (artificial life support devices or systems; surgical implantations; etc.), or may cause serious
property damage (space system; undersea repeaters; nuclear power control systems; aircraft control systems; key plant systems; military
equipment; etc.). Renesas Electronics disclaims any and all liability for any damages or losses incurred by you or any third parties arising
from the use of any Renesas Electronics product that is inconsistent with any Renesas Electronics data sheet, user’s manual or other
Renesas Electronics document.
6. When using Renesas Electronics products, refer to the latest product information (data sheets, user’s manuals, application notes, “General
Notes for Handling and Using Semiconductor Devices” in the reliability handbook, etc.), and ensure that usage conditions are within the
ranges specified by Renesas Electronics with respect to maximum ratings, operating power supply voltage range, heat dissipation
characteristics, installation, etc. Renesas Electronics disclaims any and all liability for any malfunctions, failure or accident arising out of
the use of Renesas Electronics products outside of such specified ranges.
7. Although Renesas Electronics endeavors to improve the quality and reliability of Renesas Electronics products, semiconductor products
have specific characteristics, such as the occurrence of failure at a certain rate and malfunctions under certain use conditions. Unless
designated as a high reliability product or a product for harsh environments in a Renesas Electronics data sheet or other Renesas
Electronics document, Renesas Electronics products are not subject to radiation resistance design. You are responsible for implementing
safety measures to guard against the possibility of bodily injury, injury or damage caused by fire, and/or danger to the public in the event
of a failure or malfunction of Renesas Electronics products, such as safety design for hardware and software, including but not limited to
redundancy, fire control and malfunction prevention, appropriate treatment for aging degradation or any other appropriate measures.
Because the evaluation of microcomputer software alone is very difficult and impractical, you are responsible for evaluating the safety of
the final products or systems manufactured by you.
8. Please contact a Renesas Electronics sales office for details as to environmental matters such as the environmental compatibility of each
Renesas Electronics product. You are responsible for carefully and sufficiently investigating applicable laws and regulations that regulate
the inclusion or use of controlled substances, including without limitation, the EU RoHS Directive, and using Renesas Electronics
products in compliance with all these applicable laws and regulations. Renesas Electronics disclaims any and all liability for damages or
losses occurring as a result of your noncompliance with applicable laws and regulations.
9. Renesas Electronics products and technologies shall not be used for or incorporated into any products or systems whose manufacture, use,
or sale is prohibited under any applicable domestic or foreign laws or regulations. You shall comply with any applicable export control
laws and regulations promulgated and administered by the governments of any countries asserting jurisdiction over the parties or
transactions.
10. It is the responsibility of the buyer or distributor of Renesas Electronics products, or any other party who distributes, disposes of, or
otherwise sells or transfers the product to a third party, to notify such third party in advance of the contents and conditions set forth in this
document.
11. This document shall not be reprinted, reproduced or duplicated in any form, in whole or in part, without prior written consent of Renesas
Electronics.
12. Please contact a Renesas Electronics sales office if you have any questions regarding the information contained in this document or
Renesas Electronics products.
(Note 1) “Renesas Electronics” as used in this document means Renesas Electronics Corporation and also includes its directly or indirectly
controlled subsidiaries.
(Note 2) “Renesas Electronics product(s)” means any product developed or manufactured by or for Renesas Electronics.

(Rev.4.0-1 November 2017)


General Precautions in the Handling of MPU/MCU Products

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.

1. Handling of Unused Pins


Handle unused pins in accordance with the directions given under Handling of Unused Pins in the
manual.
⎯ The input pins of CMOS products are generally in the high-impedance state. In operation with an
unused pin in the open-circuit state, extra electromagnetic noise is induced in the vicinity of LSI, an
associated shoot-through current flows internally, and malfunctions occur due to the false
recognition of the pin state as an input signal become possible. Unused pins should be handled as
described under Handling of Unused Pins in the manual.
2. Processing at Power-on
The state of the product is undefined at the moment when power is supplied.
⎯ The states of internal circuits in the LSI are indeterminate and the states of register settings and
pins are undefined at the moment when power is supplied.
In a finished product where the reset signal is applied to the external reset pin, the states of pins
are not guaranteed from the moment when power is supplied until the reset process is completed.
In a similar way, the states of pins in a product that is reset by an on-chip power-on reset function
are not guaranteed from the moment when power is supplied until the power reaches the level at
which resetting has been specified.
3. Prohibition of Access to Reserved Addresses
Access to reserved addresses is prohibited.
⎯ The reserved addresses are provided for the possible future expansion of functions. Do not access
these addresses; the correct operation of LSI is not guaranteed if they are accessed.
4. Clock Signals
After applying a reset, only release the reset line after the operating clock signal has become stable.
When switching the clock signal during program execution, wait until the target clock signal has
stabilized.
⎯ When the clock signal is generated with an external resonator (or from an external oscillator)
during a reset, ensure that the reset line is only released after full stabilization of the clock signal.
Moreover, when switching to a clock signal produced with an external resonator (or by an external
oscillator) while program execution is in progress, wait until the target clock signal is stable.
5. Differences between Products
Before changing from one product to another, i.e. to a product with a different part number, confirm
that the change will not lead to problems.
⎯ The characteristics of an MPU or MCU in the same group but having a different part number may
differ in terms of the internal memory capacity, layout pattern, and other factors, which can affect
the ranges of electrical characteristics, such as characteristic values, operating margins, immunity
to noise, and amount of radiated noise. When changing to a product with a different part number,
implement a system-evaluation test for the given product.
HOW TO USE THIS MANUAL

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.

Self-Programming Library (Japanese Release) and Supported MCUs (R20UT2861XJxxxx)


RL78 Family Self RAM list of Flash Self Programming Library (R20UT2944)

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.

Organization This user’s manual is separated into the following parts:

• 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

CHAPTER 2 PROGRAMMING ENVIRONMENT .......................................................... 9

2. 1 Hardware Environment ................................................................................................................. 9


2. 1. 1 Initialization .................................................................................................................... 12
2. 1. 2 Blocks ............................................................................................................................ 12
2. 1. 3 Processing time of flash self-programming ................................................................... 14
2. 2 Software Environment................................................................................................................. 24
2. 2. 1 Self-RAM ....................................................................................................................... 28
2. 2. 2 Register bank ................................................................................................................ 28
2. 2. 3 Stack and data buffer .................................................................................................... 28
2. 2. 4 Flash self-programming library...................................................................................... 29
2. 2. 5 Program area ................................................................................................................ 29
2. 2. 6 ROMization of programs ............................................................................................... 29
2. 3 Cautions on Programming Environment ..................................................................................... 30

CHAPTER 3 INTERRUPTS DURING EXECUTION OF FLASH


SELF-PROGRAMMING ......................................................................... 33

3. 1 Overview ..................................................................................................................................... 33
3. 2 Interrupts During Execution of Flash Self-Programming ............................................................ 33
3. 3 Cautions on Interrupts ................................................................................................................. 34

CHAPTER 4 SECURITY SETTINGS........................................................................... 35

4. 1 Security Flags ............................................................................................................................. 35


4. 2 Flash Shield Window Function.................................................................................................... 35

CHAPTER 5 BOOT SWAP FUNCTION ...................................................................... 36

5. 1 Overview ..................................................................................................................................... 36
5. 2 Boot Swap Function .................................................................................................................... 36
5. 3 Boot Swapping Procedure .......................................................................................................... 37
5. 4 Cautions on Boot Swapping ........................................................................................................ 42

CHAPTER 6 FLASH FUNCTIONS .............................................................................. 43

6. 1 Types of Flash Functions ............................................................................................................ 43


6. 2 Segments of Flash Functions ..................................................................................................... 44
6. 3 Interrupts and BGO (Background Operation) ............................................................................. 46
6. 4 Status Check Mode..................................................................................................................... 47
6. 4. 1 Status Check User Mode .............................................................................................. 49
6. 5 Pausing of Flash Self-Programming ........................................................................................... 51
6. 6 List of Data Types and Return Values ........................................................................................ 53

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

APPENDIX A REVISION HISTORY .......................................................................... 109

A. 1 Major Revisions in This Edition ................................................................................................ 109


A. 2 Revision History of Preceding Editions ..................................................................................... 110

Index-2
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

RL78 Family R01US0050EJ0105


Rev.1.05
Flash Self-Programming Library Type 01 Oct 31, 2018

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.

R01US0050EJ0105 Rev.1.05 Page 2 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

1. 2 Calling Flash Self-Programming Library

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).

Figure 1-1. State Transition Diagram of Flash Self-Programming

Reset or Power ON uninitialized

FSL_Init() destroy RAM data

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

Sequencer Control FSL_Wakeup() *FSL_Erase Only

R01US0050EJ0105 Rev.1.05 Page 3 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

[Overview of the state transition diagram]


To operate the code flash memory by using the flash self-programming library, the provided functions need to be
executed sequentially to perform processing.

(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.

(7) sequencer busy


State in which the specified processing is being executed with the sequencer. The code flash memory
cannot be referred to while the sequencer is being used. 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.

R01US0050EJ0105 Rev.1.05 Page 4 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

Figure 1-2. Example of Flow of Flash Self-Programming (Rewriting of Code Flash Memory)

Start flash self-programming

<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

End flash self-programming

R01US0050EJ0105 Rev.1.05 Page 5 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

Figure 1-3. Example of Flow of Code Flash Memory Rewriting During Background Operation

For preprocessing and end processing, refer to Figure 1-2.

* When rewriting of the code flash memory is


<5> FSL_BlankCheck
performed in status check user mode.

Error
Status check

In execution

<11> FSL_StatusCheck

In execution Blank check error


Status check

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

R01US0050EJ0105 Rev.1.05 Page 6 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

<1> Initializing the RAM used for flash self-programming


The FSL_Init function is called to initialize the RAM used for flash self-programming and to set the
parameters required for the operation.

<2> Starting the flash environment


The FSL_Open function is called to make flash self-programming available.

<3> Preparation processing


The FSL_PrepareFunctions function is called to prepare the functions used for flash self-programming. To
use extension functions, the FSL_PrepareExtFunctions function must also be called.
For details of the FSL_PrepareFunctions function and FSL_PrepareExtFunctions function, refer to CHAPTER
6 FLASH FUNCTIONS.

<4> Changing interrupt reception to the RAM


When an interrupt is required during the execution of flash self-programming, the FSL_ChangeInterruptTable
function is called to change the interrupt destination from the ROM to RAM.

<5> Blank checking of the specified block (1-Kbyte)


The FSL_BlankCheck function is called to perform a blank check of the specified block (1-Kbyte) (check that
the block is ready to be written to).

<6> Erasing the specified block (1-Kbyte)


The FSL_Erase function is called to erase the specified block (1-Kbyte).

<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.

<8> Verification (internal verification) of the specified block (1-Kbyte)


The FSL_IVerify function is called for verification (internal verification) of the specified block (1-Kbyte).

Note: Internal verification checks if the signal levels of the flash memory cells are correct. It does not compare
data.

<9> Changing interrupt reception back to the ROM


If the interrupt destination was changed to the RAM in <4>, the FSL_RestoreInterruptTable function is called
to change the interrupt reception destination back to the ROM.

R01US0050EJ0105 Rev.1.05 Page 7 of 112


Oct 31, 2018
RL78 Family CHAPTER 1 OVERVIEW
Flash Self-Programming Library Type 01

<10> Ending the flash environment


The FSL_Close function is called to end flash self-programming. The FSL_Close function should be
executed when all writing processing is completed or when flash self-programming should be terminated.

<11> Status checking


When the status check user mode is used, status checking must be performed until the control of the code
flash memory is finished.

Remark 1 word = 4 bytes

R01US0050EJ0105 Rev.1.05 Page 8 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

CHAPTER 2 PROGRAMMING ENVIRONMENT

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.

Figure 2-1. State during Rewrite of Code Flash Memory

Interrupts during code flash


memory control can be handled
only on the RAM.
*Dedicated interrupt processing Internal RAM
BGO (background operation)
for the RAM is required in addition during code flash memory
to interrupt processing for the control can be handled only
ROM. on the RAM.
Internal ROM
The inernal ROM cannot be referred to
during code flash memory control

× (interrupt reception cannot be done).

Normal vector interrupts cannot be received


while code flash memory is being controlled.

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.

R01US0050EJ0105 Rev.1.05 Page 9 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

 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)

User program Library Sequencer

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)

R01US0050EJ0105 Rev.1.05 Page 10 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

 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)

User program Library Sequencer

Call

Execute

On going

Execute
Code flash memory
On going cannot be referred to
during this period.

Execute

Finish

Ret

R01US0050EJ0105 Rev.1.05 Page 11 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

2. 1. 1 Initialization
When rewriting the code flash memory by using the flash self-programming library, make the following
settings.

(1) Starting high-speed on-chip oscillator


During use of the flash self-programming library, keep the high-speed on-chip oscillator running. When
the high-speed on-chip oscillator is stopped, start it before using the flash self-programming library.

(2) Setting CPU operating frequencyNote 1


In order to calculate the timing in the flash self-programming library, set the CPU operating frequency at
initialization. See the description of the FSL_Init() function for the method for setting the CPU operating
frequency.

(3) Setting flash memory programming modeNote 2


In order to set the flash memory programming mode for erasing or writing, either of the flash memory
programming modes shown below should be specified when initializing the flash self-programming library.
See the description of the FSL_Init() function for the settings of the flash memory programming modes.
- Full speed mode
- Wide voltage mode

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.

R01US0050EJ0105 Rev.1.05 Page 12 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

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

R01US0050EJ0105 Rev.1.05 Page 13 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

2. 1. 3 Processing time of flash self-programming


This section describes the time required to process the Flash Self-Programming Library Type 01 functions.
The number of clock cycles required to execute flash functions differs depending on whether the flash functions
are allocated to the internal ROM area (flash memory) or they are allocated to the internal RAM area. When
the functions are executed in the RAM, the processing time may increase to a maximum of double the time
needed when they are executed in the ROM.
This section shows the processing time when the FSL_RCD segment is executed in the RAM and the other
segments are executed in the ROM. For each segment of flash functions, see Table 6-2 Segment List of Flash
Functions.

(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.

Figure 2-5. Overview of Flash Self-Programming Library Function Processing Time


in Status Check User Mode

User Program FSL

FSL_Write

Status = BUSY

Function Processing Time


FSL_StatusCheck

Status = BUSY

FSL_StatusCheck

Status = BUSY

FSL_StatusCheck

Status = OK

R01US0050EJ0105 Rev.1.05 Page 14 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-1. Flash Function Processing Time in Status Check User Mode (Full Speed Mode)

FSL_Functions Max. (μs)

FSL_Init 5021 / fCLK

FSL_Open 10 / fCLK

FSL_Close 10 / fCLK

FSL_PrepareFunctions 2484 / fCLK

FSL_PrepareExtFunctions 1259 / fCLK

FSL_ChangeInterruptTable 253 / fCLK

FSL_RestoreInterruptTable 229 / fCLK

FSL_BlankCheck 2069 / fCLK + 30

FSL_Erase 2192 / fCLK+ 30

FSL_IVerify 2097 / fCLK + 30

FSL_Write 2451 / fCLK + 30

FSL_GetSecurityFlags 331 / fCLK

FSL_GetBootFlag 328 / fCLK

FSL_GetSwapState 206 / fCLK

FSL_GetBlockEndAddr 368 / fCLK

FSL_GetFlashShieldWindow 307 / fCLK

FSL_SwapBootCluster 419 / fCLK + 32

FSL_SwapActiveBootCluster 2316 / fCLK + 30

FSL_InvertBootFlag 2341 / fCLK + 30

FSL_SetBlockEraseProtectFlag 2347 / fCLK + 30

FSL_SetWriteProtectFlag 2346 / fCLK+ 30

FSL_SetBootClusterProtectFlag 2347 / fCLK + 30

FSL_SetFlashShieldWindow 2141 / fCLK + 30

FSL_StatusCheck 1135 / fCLK + 50

Erase 935 / fCLK + 31

Other than Erase


140367 / fCLK + 513844
FSL_StandBy (when FSL_SetXXX are supported)

Other than Erase


76101 / fCLK + 35952
(when FSL_SetXXX are not supported)

Suspended Erase 2144 / fCLK + 30


FSL_WakeUp
Other than Erase 148 / fCLK

FSL_ForceReset 

FSL_GetVersionString 10 / fCLK

Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)

R01US0050EJ0105 Rev.1.05 Page 15 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-2. Flash Function Processing Time in Status Check User Mode (Wide Voltage Mode)

FSL_Functions Max. (μs)

FSL_Init 5021 / fCLK

FSL_Open 10 / fCLK

FSL_Close 10 / fCLK

FSL_PrepareFunctions 2484 / fCLK

FSL_PrepareExtFunctions 1259 / fCLK

FSL_ChangeInterruptTable 253 / fCLK

FSL_RestoreInterruptTable 229 / fCLK

FSL_BlankCheck 2068 / fCLK + 30

FSL_Erase 2192 / fCLK + 30

FSL_IVerify 2097 / fCLK + 30

FSL_Write 2451 / fCLK + 30

FSL_GetSecurityFlags 331 / fCLK

FSL_GetBootFlag 328 / fCLK

FSL_GetSwapState 206 / fCLK

FSL_GetBlockEndAddr 368 / fCLK

FSL_GetFlashShieldWindow 307 / fCLK

FSL_SwapBootCluster 419 / fCLK + 32

FSL_SwapActiveBootCluster 2316 / fCLK + 30

FSL_InvertBootFlag 2341 / fCLK + 30

FSL_SetBlockEraseProtectFlag 2347 / fCLK + 30

FSL_SetWriteProtectFlag 2346 / fCLK + 30

FSL_SetBootClusterProtectFlag 2347 / fCLK + 30

FSL_SetFlashShieldWindow 2141 / fCLK + 30

FSL_StatusCheck 1135 / fCLK + 50

Erase 935 / fCLK + 44

Other than Erase


123274 / fCLK + 538046
FSL_StandBy (when FSL_SetXXX are supported)

Other than Erase


73221 / fCLK + 69488
(when FSL_SetXXX are not supported)

Suspended Erase 2144 / fCLK + 30


FSL_WakeUp
Other than Erase 148 / fCLK

FSL_ForceReset 

FSL_GetVersionString 10 / fCLK

Remark fCLK: CPU operating frequency (For example, when using a 20 MHz clock, fCLK is 20.)

R01US0050EJ0105 Rev.1.05 Page 16 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

(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

User program FSL

FSL_Write

Flash function processing time


Min. – Max.

Status = OK

R01US0050EJ0105 Rev.1.05 Page 17 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-3. Flash Function Processing Time in Status Check Internal Mode (Full Speed Mode)

FSL_Functions Min. (μs) Max. (μs)

FSL_Init  5021 / fCLK

FSL_Open  10 / fCLK

FSL_Close  10 / fCLK

FSL_PrepareFunctions  2484 / fCLK

FSL_PrepareExtFunctions  1259 / fCLK

FSL_ChangeInterruptTable  253 / fCLK

FSL_RestoreInterruptTable  229 / fCLK

FSL_BlankCheck 3302 / fCLK + 84 4833 / fCLK + 164

FSL_Erase 4877 / fCLK + 163 73339 / fCLK + 255366

FSL_IVerify  10474 / fCLK + 1107

FSL_Write 3121 / fCLK + 66 3121 / fCLK + 66


+ (595 / fCLK + 60) × W + (1153 / fCLK + 561) × W

FSL_GetSecurityFlags  331 / fCLK

FSL_GetBootFlag  328 / fCLK

FSL_GetSwapState  206 / fCLK

FSL_GetBlockEndAddr  368 / fCLK

FSL_GetFlashShieldWindow  307 / fCLK

FSL_SwapBootCluster  419 / fCLK + 32

FSL_SwapActiveBootCluster 1938 / fCLK + 50 141314 / fCLK + 513862

FSL_InvertBootFlag 1565 / fCLK + 18 140940 / fCLK + 513830

FSL_SetBlockEraseProtectFlag 1571 / fCLK + 18 140946 / fCLK + 513830

FSL_SetWriteProtectFlag 1569 / fCLK + 18 140945 / fCLK + 513830

FSL_SetBootClusterProtectFlag 1571 / fCLK + 18 140946 / fCLK + 513830

FSL_SetFlashShieldWindow 1356 / fCLK + 18 140739 / fCLK + 513830

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.)

R01US0050EJ0105 Rev.1.05 Page 18 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-4. Flash Function Processing Time in Status Check Internal Mode (Wide Voltage Mode)

FSL_Functions Min. (μs) Max. (μs)

FSL_Init  5021 / fCLK

FSL_Open  10 / fCLK

FSL_Close  10 / fCLK

FSL_PrepareFunctions  2484 / fCLK

FSL_PrepareExtFunctions  1259 / fCLK

FSL_ChangeInterruptTable  253 / fCLK

FSL_RestoreInterruptTable  229 / fCLK

FSL_BlankCheck 3298 / fCLK + 124 4574 / fCLK + 401

FSL_Erase 4675 / fCLK + 401 64468 / fCLK + 266193

FSL_IVerify  7659 / fCLK + 7534

FSL_Write
3121 / fCLK + 66 3121 / fCLK+ 66
+ (591 / fCLK + 112) × W + (1108 / fCLK + 1085) × W

FSL_GetSecurityFlags  331 / fCLK

FSL_GetBootFlag  328 / fCLK

FSL_GetSwapState  206 / fCLK

FSL_GetBlockEndAddr  368 / fCLK

FSL_GetFlashShieldWindow  307 / fCLK

FSL_SwapBootCluster  419 / fCLK + 32

FSL_SwapActiveBootCluster 1938 / fCLK + 50 124221 / fCLK + 538064

FSL_InvertBootFlag 1565 / fCLK + 18 123847 / fCLK + 538032

FSL_SetBlockEraseProtectFlag 1571 / fCLK + 18 123853 / fCLK + 538032

FSL_SetWriteProtectFlag 1569 / fCLK + 18 123852 / fCLK + 538032

FSL_SetBootClusterProtectFlag 1571 / fCLK + 18 123853 / fCLK + 538032

FSL_SetFlashShieldWindow 1356 / fCLK + 18 123646 / fCLK + 538032

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.)

R01US0050EJ0105 Rev.1.05 Page 19 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

(3) Recommended interval of FSL_StatusCheck (status check)


The FSL_StatusCheck function is used to check the status in the status check user mode. However, correct
results cannot be obtained if the FSL_StatusCheck function is executed before control by the sequencer
finishes. Therefore, spacing each process executed by each flash function by a specific time is useful to
enhance the efficiency of status checking. In addition, because a write process using the FSL_Write function
must be triggered by status check processing every 4-byte, the status must be checked each time 4-byte is
written.

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)

User program FSL

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

R01US0050EJ0105 Rev.1.05 Page 20 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

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)

User program FSL

FSL_Erase

Erase trigger
Status = BUSY

No call for FSL_StatusCheck

1-block erase
Call interval

FSL_StatusCheck
Erase ends

Status = OK

R01US0050EJ0105 Rev.1.05 Page 21 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-5. Recommended Interval of Status Check in Status Check User Mode (Full Speed Mode)

FSL_Functions Call Interval (μs)

FSL_Init 

FSL_Open 

FSL_Close 

FSL_PrepareFunctions 

FSL_PrepareExtFunctions 

FSL_ChangeInterruptTable 

FSL_RestoreInterruptTable 

FSL_BlankCheck 1569 / fCLK + 98

When block is blanked 1490 / fCLK + 97


FSL_Erase
When block is not blanked 3092 / fCLK + 6471

FSL_IVerify 7181 / fCLK + 1041


Note
FSL_Write 72 / fCLK + 60

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 

When block is blanked 1490 / fCLK + 97


FSL_WakeUp
When block is not blanked 3092 / fCLK + 6471

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.

R01US0050EJ0105 Rev.1.05 Page 22 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-6. Recommended Interval of Status Check in Status Check User Mode (Wide Voltage Mode)

FSL_Functions Call Interval (μs)

FSL_Init 

FSL_Open 

FSL_Close 

FSL_PrepareFunctions 

FSL_PrepareExtFunctions 

FSL_ChangeInterruptTable 

FSL_RestoreInterruptTable 

FSL_BlankCheck 1310 / fCLK + 335

When block is blanked 1289 / fCLK + 335


FSL_Erase
When block is not blanked 2689 / fCLK + 6959

FSL_IVerify 4366 / fCLK + 7468

FSL_WriteNote 67 / fCLK + 112

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 

When block is blanked 1289 / fCLK + 335


FSL_WakeUp
When block is not blanked 2689 / fCLK + 6959

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.

R01US0050EJ0105 Rev.1.05 Page 23 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

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.

Table 2-7. Software Resources Used by Flash Self-Programming Library Type 01

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)".

Stack (see Table 2-8) 46 max. 50 max.


Note4
Data buffer Can be allocated to a RAM area other than the self-RAM and the
1 to 256 1 to 256
(see Table 2-9) area from FFE20H to FFEFFH
Arguments of library
0 to 8 0 to 8
functions
Library size ROM: 1,252 max. ROM: 1,294 max. Can be allocated to a program area other than the self-RAM and
(see Tables 2-10 the area from FFE20H to FFEFFH
and 2-11) RAM: 0 to 447 RAM: 0 to 468 Can be allocated to a program area other than the self-RAM, the
area from FFE20H to FFEFFH, and the internal ROM.

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.

R01US0050EJ0105 Rev.1.05 Page 24 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Figure 2-9 Example 1 of Arrangement in RAM Including Self-RAM


(RL78/G13: product with 4 Kbytes RAM and 64 Kbytes ROM)
Special function register (SFR)
FFEFFH
Area where RAM (stack, data buffer, etc.) used by
General-purpose registers 32 bytes
SADDR area the Flash Self-Programming Library cannot be
FFE20H allocated
FFE1FH

No allocation restriction
RAM
4 Kbytes

FF300H
FF2FFH

Area whose usage is prohibited


(Self-RAM) Area damaged when the Flash Self-Programming
Library is used
FEF00H
FEEFFH

Mirror

Figure 2-10 Example 2 of Arrangement in RAM without Self-RAM


(RL78/G13: product with 2 Kbytes RAM and 32 Kbytes ROM)

Special function register (SFR)


FFEFFH
Area where RAM (stack, data buffer, etc.) used by
General-purpose registers 32 bytes
SADDR area the Flash Self-Programming Library cannot be
FFE20H allocated
FFE1FH

RAM
2 Kbytes
No allocation restriction

FF700H
FF6FFH

Mirror

R01US0050EJ0105 Rev.1.05 Page 25 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Table 2-8. Stack Size Used by Flash Functions

Function Name byte Function Name byte


CA78 CCRL CA78 CCRL
FSL_Init 40 44 FSL_GetBlockEndAddr 36 40
FSL_Open 0 2 FSL_GetFlashShieldWindow 46 50
FSL_Close 0 2 FSL_SwapBootCluster 38 40
FSL_PrepareFunctions 10 12 FSL_SwapActiveBootCluster 42 46
FSL_PrepareExtFunctions 10 12 FSL_InvertBootFlag 42 46
FSL_ChangeInterruptTable 30 32 FSL_SetBlockEraseProtectFlag 42 46
FSL_RestoreInterruptTable 30 32 FSL_SetWriteProtectFlag 42 46
FSL_BlankCheck 42 46 FSL_SetBootClusterProtectFlag 42 46
FSL_Erase 42 46 FSL_SetFlashShieldWindow 42 46
FSL_IVerify 42 46 FSL_StatusCheck 30 34
FSL_Write 42 46 FSL_StandBy 30 34
FSL_GetSecurityFlags 46 50 FSL_WakeUp 42 46
FSL_GetBootFlag 46 50 FSL_ForceReset 0 2
FSL_GetSwapState 36 40 FSL_GetVersionString 0 2

Note Each size does not include the stack size used by the caller to call the FSL function.

Table 2-9. Data Buffer Size Used by Flash Functions

Function Name byte Function Name byte


FSL_Init 0 FSL_GetBlockEndAddr 4
FSL_Open 0 FSL_GetFlashShieldWindow 4
FSL_Close 0 FSL_SwapBootCluster 0
FSL_PrepareFunctions 0 FSL_SwapActiveBootCluster 0
FSL_PrepareExtFunctions 0 FSL_InvertBootFlag 0
FSL_ChangeInterruptTable 0 FSL_SetBlockEraseProtectFlag 0
FSL_RestoreInterruptTable 0 FSL_SetWriteProtectFlag 0
FSL_BlankCheck 0 FSL_SetBootClusterProtectFlag 0
FSL_Erase 0 FSL_SetFlashShieldWindow 4
FSL_IVerify 0 FSL_StatusCheck 0
FSL_WriteNote 4 to 256 FSL_StandBy 0
FSL_GetSecurityFlags 2 FSL_WakeUp 0
FSL_GetBootFlag 1 FSL_ForceReset 0
FSL_GetSwapState 1 FSL_GetVersionString 0

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

R01US0050EJ0105 Rev.1.05 Page 26 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

Flash Self-Programming Library Code Size


(1) Code size when allocating all functions to ROM
Table 2-10 shows the code size required when all flash self-programming library functions are allocated to
ROM. Allocating the code to RAM is not required, but usage restrictions will prevent some functions being
used if all functions are allocated to ROM. For details, see 6.2 Segments of Flash Functions.

Table 2-10. Code Size When Allocating All Functions to ROM

Conditions CA78K0R compiler (V2.20) CC-RL compiler (V2.21)


RAM Size (byte) ROM Size (byte) RAM Size (byte) ROM Size (byte)
Code size when all functions are
registered 0 1,252 0 1294
* Some functions cannot be used.
Code size when all the following
functions are used:
• FSL_Init
• FSL_Open
• FSL_Close
• FSL_PrepareFunctions 0 500 0 502
• FSL_BlankCheck
• FSL_Erase
• FSL_IVerify
• FSL_Write
• FSL_StatusCheck

(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.

Table 2-11. Code Size When Allocating Some Functions to RAM

Conditions CA78K0R compiler (V2.20) CC-RL compiler (V2.21)


RAM Size (byte) ROM Size (byte) RAM Size (byte) ROM Size (byte)
Code size when all functions are 447 (FSL_RCD) 805 + size of program 468 (FSL_RCD) 826 + size of program
registered that must be that must be
ROMized (447) ROMized (468)
Code size when all the following 66 (FSL_RCD) 434 + size of program 88 (FSL_RCD) 502 + size of program
functions are used: that must be that must be
• FSL_Init ROMized (66) ROMized (88)
• FSL_Open
• FSL_Close
• FSL_PrepareFunctions
• FSL_BlankCheck
• FSL_Erase
• FSL_IVerify
• FSL_Write
• FSL_StatusCheck

R01US0050EJ0105 Rev.1.05 Page 27 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

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.

2. 2. 3 Stack and data buffer


The flash self-programming library uses the sequencer to write to the code flash memory, but it uses the CPU
for pre-setting and control. Therefore, to use the flash self-programming library, the stack specified by the user
program is also required.

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.

R01US0050EJ0105 Rev.1.05 Page 28 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

2. 2. 4 Flash self-programming library


Not all the flash functions are linked. Only the flash functions to be used are linkedNote.

 Memory allocation of the flash self-programming library


Segments are assigned to the functions and variables used in the flash self-programming library. Areas
used in the flash self-programming library can be specified at the specific locations.
For details, refer to 6.2 Segments of Flash Functions, or refer to the document "Release note" attached
to the installer.

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.

R01US0050EJ0105 Rev.1.05 Page 29 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

2. 3 Cautions on Programming Environment

(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.)

R01US0050EJ0105 Rev.1.05 Page 30 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

(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.)

R01US0050EJ0105 Rev.1.05 Page 31 of 112


Oct 31, 2018
RL78 Family CHAPTER 2 PROGRAMMING ENVIRONMENT
Flash Self-Programming Library Type 01

(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.

R01US0050EJ0105 Rev.1.05 Page 32 of 112


Oct 31, 2018
RL78 Family CHAPTER 3 INTERRUPTS DURING EXECUTION OF FLASH SELF-PROGRAMMING
Flash Self-Programming Library Type 01

CHAPTER 3 INTERRUPTS DURING EXECUTION OF FLASH


SELF-PROGRAMMING

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.

3. 2 Interrupts During Execution of 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.

Figure 3-1. Interrupts During Execution of Flash Self-Programming

On-chip RAM ・
Interrupt processing for the RAM Address of the RAM specified as the interrupt
destination = Beginning address of the interrupt
function allocated

Code flash memory After the interrupt destination is changed to the


is being controlled RAM, all interrupts branch to the same address.
Code flash memory ・
For the details of interrupt, the user needs to
(cannot be referred to) check the interrupt flag.
*No vector table is created automatically.
Normal interrupt vector

× Interrupts on the ROM cannot be received because the


ROM cannot be used during the code flash memory is
being controlled.

R01US0050EJ0105 Rev.1.05 Page 33 of 112


Oct 31, 2018
RL78 Family CHAPTER 3 INTERRUPTS DURING EXECUTION OF FLASH SELF-PROGRAMMING
Flash Self-Programming Library Type 01

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 execution of flash functions is prohibited in interrupt processing.

- Save and restore the registers used in interrupt processing.

- 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.

R01US0050EJ0105 Rev.1.05 Page 34 of 112


Oct 31, 2018
RL78 Family CHAPTER 4 SECURITY SETTINGS
Flash Self-Programming Library Type 01

CHAPTER 4 SECURITY SETTINGS

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).

Functions setting the security flag Description

FSL_SetBlockEraseProtectFlag Sets the block erasure protection flag to protected.

FSL_SetWriteProtectFlag Sets the write protection flag to protected.

FSL_SetBootClusterProtectFlag Sets the boot area (boot cluster 0) rewrite protection flag to protected.

4. 2 Flash Shield Window Function

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.

Function setting the flash shield window Description

FSL_SetFlashShieldWindow Sets the flash shield window.

R01US0050EJ0105 Rev.1.05 Page 35 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

CHAPTER 5 BOOT SWAP FUNCTION

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.

5. 2 Boot Swap Function

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.

Note Boot Cluster 0: Boot program area


Boot Cluster 1: Boot swap target area

R01US0050EJ0105 Rev.1.05 Page 36 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

5. 3 Boot Swapping Procedure

Figure 5-1 shows an example of the flow of boot swapping using the flash self-programming library.

Figure 5-1. Example of Flow of Boot Swapping

Start boot swap

<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

<13> Ending processing

End boot swapping

R01US0050EJ0105 Rev.1.05 Page 37 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

<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

<2> Erasure of Boot Cluster 1


All blocks in Boot Cluster 1 are erased by calling the FSL_Erase function.

Remark The FSL_Erase function performs erasure in units of blocks.

Normal operation mode

Boot Boot
Program area Erase
cluster 1 cluster 1

Program area Program area

Boot Boot
cluster 0 On-chip debug security ID cluster 0 On-chip debug security ID
setting area setting area

Option byte Option byte

CALLT table CALLT table

Vector table Vector table

R01US0050EJ0105 Rev.1.05 Page 38 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

<3> Copying of the new boot program to Boot Cluster 1


A new boot program (the program you want to allocate as the boot program area after boot swap processing) is
written to Boot Cluster 1 by calling the FSL_Write function.

Remark The FSL_Write function performs writing in units of words (1 word = 4 bytes, up to 64 words (256
bytes))

A new boot program is downloaded to the internal


ROM via the external interface (three-wire SIO,
UART, etc.) and written sequentially.

On-chip RAM

Boot Boot Writing of a


Already erased
cluster 1 cluster 1 new boot program

Program area Program area

Boot Boot
cluster 0 On-chip debug security ID cluster 0 On-chip debug security ID
setting area setting area

Option byte Option byte

CALLT table CALLT table

Vector table Vector table

<4> Verification of Boot Cluster 1


All blocks of Boot Cluster 1 to which writing has been done are verified by calling the FSL_IVerify function.

Remark The FSL_IVerify function performs verification in units of blocks.

<5> Confirmation of the boot swap bit (recommended)


The security flag information is obtained by calling the FSL_GetSecurityFlags function. Check that the boot
area (Boot Cluster 0) rewrite protection flag is 1 (permitted).

Remark If the (Boot Cluster 0) rewrite protection flag is 0 (protected), an error occurs when the
FSL_InvertBootFlag function is called in <6>.

R01US0050EJ0105 Rev.1.05 Page 39 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

<6> Setting of the boot swap bit


Switching of the boot flag is performed by executing the FSL_InvertBootFlag function.

<7> Occurrence of an event


When a reset is generated, Boot Cluster 1 becomes the boot program area.

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

Boot Boot New boot program


cluster 0 On-chip debug security ID cluster 1
setting area
Option byte

CALLT table
Vector table

<8> Ending of swap processing (Boot Cluster 1)


Swap processing for Boot Cluster 1 is finished after steps <2> to <7>.
If Boot Cluster 0 does not have to be rewritten, terminate processing.
If Boot Cluster 0 has to be rewritten, perform the processing of <9> and on.

<9> Preprocessing
The same processing as <1> is performed.

R01US0050EJ0105 Rev.1.05 Page 40 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

<10> Erasure of Boot Cluster 0


All blocks of Boot Cluster 0 are erased by calling the FSL_Erase function.

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

<11> Writing of the new program to Boot Cluster 0


The content of the new program is written to Boot Cluster 0 by calling the FSL_Write function.

Boot Boot
Already erased New program
cluster 0 cluster 0

Boot New boot program


Boot New boot program
cluster 1 cluster 1

R01US0050EJ0105 Rev.1.05 Page 41 of 112


Oct 31, 2018
RL78 Family CHAPTER 5 BOOT SWAP FUNCTION
Flash Self-Programming Library Type 01

<12> Verification of Boot Cluster 0


All blocks of Boot Cluster 0 to which writing has been done are verified by calling the FSL_IVerify function.

<13> End processing


As the end processing of boot swapping, the FSL_Close function is called.

5. 4 Cautions on Boot Swapping

- 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.

R01US0050EJ0105 Rev.1.05 Page 42 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

CHAPTER 6 FLASH FUNCTIONS

This chapter describes the details of the flash functions (functions in the flash self-programming library).

6. 1 Types of Flash Functions

The flash self-programming library consists of the following flash functions.

Table 6-1. List of Flash Functions

Function name Description Basic Function


Note
function for G11Note

FSL_Init Initialization of the flash self-programming environment ○ ○


FSL_Open Starting of the flash environment (start declaration of flash self-programming) ○ ○
FSL_Close Ending of the flash environment (end declaration of flash self-programming) ○ ○
FSL_PrepareFunctions Preparation processing for flash functions ○ ○
FSL_PrepareExtFunctions Preparation processing for flash functions (extension functions) - ○
FSL_ChangeInterruptTable Interrupt vector change processing (changing the interrupt destination from ROM to RAM) - -
FSL_RestoreInterruptTable Interrupt vector restoration processing (changing the interrupt destination from RAM to ROM) - -
FSL_BlankCheck Blank checking of the specified block ○ ○
FSL_Erase Erasure of the specified block. ○ ○
FSL_IVerify Verification (internal verification) of the specified block ○ ○
FSL_Write Writing of 1 word to 64 words data into the specified address (1 word=4 bytes) ○ ○
FSL_GetSecurityFlags Acquisition of security information - -
FSL_GetBootFlag Acquisition of boot flag information - ○
FSL_GetSwapState Acquisition of swap information - ○
FSL_GetBlockEndAddr Acquisition of the final address of the specified block - -
FSL_GetFlashShieldWindow Acquisition of the start block number and end block number of the flash shield window - ○
FSL_SwapBootCluster Execution of boot swapping and jumping to the registered address of the reset vector - ○
FSL_SwapActiveBootCluster Inverting of the current value of the boot flag and execution of boot swapping - -
FSL_InvertBootFlag Inverting of the current value of the boot flag - ○
FSL_SetBlockEraseProtectFlag Setting of the block erasure protection flag to protected - -
FSL_SetWriteProtectFlag Setting of the write protection flag to protected - -
FSL_SetBootClusterProtectFlag Setting of the boot area (boot cluster 0) rewrite protection flag to protected - -
FSL_SetFlashShieldWindow Setting of the start block and end block of the flash shield window - ○
FSL_StatusCheck Status check processing ○ -
FSL_StandBy Pause processing of flash self-programming - -
FSL_WakeUp Restart processing of flash self-programming - -
FSL_ForceReset Resetting of the microcontroller in use - ○
FSL_GetVersionString Version acquisition processing of 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.

R01US0050EJ0105 Rev.1.05 Page 43 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 2 Segments of Flash Functions

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.

R01US0050EJ0105 Rev.1.05 Page 44 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Table 6-2. List of Flash Function Segments


Function name Segment name ROM allocation RAM allocation

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.

R01US0050EJ0105 Rev.1.05 Page 45 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 3 Interrupts and BGO (Background Operation)

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.

R01US0050EJ0105 Rev.1.05 Page 46 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 4 Status Check Mode

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.

• Status check user modeNote


After the control setting of the sequencer is done by the flash function, execution returns to the user
program. The user needs to check the status of the sequencer with the status check function
(FSL_StatusCheck), but the user program can operate until the sequencer processing is completed. The
user programs and interrupt program to operate during sequencer control need to be allocated on the
RAM.

• Status check internal modeNote


Execution does not return to the user program until the status of the sequencer is checked with the flash
function and the sequencer processing is completed. To process interrupts during the execution of the
function (during sequencer control), the interrupt program needs to be allocated on the RAM.

Figure 6-1 Example of Status Check Mode


Example 1: Writing in the status check user mode Example 2: Writing in the status check internal mode

User Library User Library

Function executed Function executed

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.

R01US0050EJ0105 Rev.1.05 Page 47 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Table 6-4. List of Status Checking of Flash Functions

Function name Sequencer control Status check

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.

R01US0050EJ0105 Rev.1.05 Page 48 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 4. 1 Status Check User Mode


In the status check user mode, the back ground operation (BGO) can be performed on the RAM. The
operation examples of each procedure are shown in the following figure.

Figure 6-2 Example 1 of Status Check User Mode (FSL_Write: When writing 12 bytes data)

R01US0050EJ0105 Rev.1.05 Page 49 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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

R01US0050EJ0105 Rev.1.05 Page 50 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 5 Pausing of Flash Self-Programming

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.

Figure 6-4 Example of Pausing of Flash Self-Programming


Example 1: Pause processing during erasure processing Example 2: Pause processing during writing (other than erasure) processing

User Library User Library


Erasure executed Writing executed
Start of Start of
processing processing
Function closed Function closed

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.

Pause released Pause state


Erasure * ROM can be
processing referred to
restarted Restart instruction
* ROM cannot
Status check be referred
Pause released
End of
processing

Status check
End of
processing

R01US0050EJ0105 Rev.1.05 Page 51 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Table 6-5. List of Execution States of Stand-by Function

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.

R01US0050EJ0105 Rev.1.05 Page 52 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 6 List of Data Types and Return Values

The data types are as follows

Table 6-6. List of Data Types

Definition Data type Description

fsl_u08 unsigned char 1-byte (8-bit) unsigned integer


fsl_u16 unsigned int 2-byte (16-bit) unsigned integer
fsl_u32 unsigned long int 4-byte (32-bit) unsigned integer

The meaning of each return value is as follows.

Table 6-7. List of Return Values

Definition Return Description


value

FSL_OK 0x00 Normal completion


FSL_ERR_PARAMETER 0x05 Parameter error
- The specified parameter has an error.
FSL_ERR_PROTECTION 0x10 Protect error
- The target area is protected.
FSL_ERR_ERASE 0x1A Erasure error
- Erasure of the target area failed.
FSL_ERR_BLANKCHECK 0x1B Blank check error
- The target area is not in the blank state.
FSL_ERR_IVERIFY 0x1B Internal verification error
- An error occurred during internal verification processing of the
target area.
FSL_ERR_WRITE 0x1C Writing error
- Writing to the target area failed.
FSL_ERR_FLOW 0x1F Flow error
- The processing of the flash function executed immediately
before has not been completed.
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.
FSL_IDLE 0x30 Idle state
- Flash self-programming is not executed.
FSL_SUSPEND 0x43 Pause state
- Flash self-programming is paused.
FSL_BUSY 0xFF Execution start of the flash function or the flash function in
execution
- The function of the flash function is in execution.

R01US0050EJ0105 Rev.1.05 Page 53 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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.

Table 6-8. List of Return Values Used in Each Compiler

Return value
Development tool
C language Assembly language

RENESAS CA78K0R compiler fsl_u08 C(General-purpose register)


RENESAS CC-RL compiler fsl_u08 A(General-purpose register)

R01US0050EJ0105 Rev.1.05 Page 54 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

6. 7 Description of Flash Functions

The flash functions are described in the following format.

Flash function name

[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.

[Register State After Call]


Describes the register state after this function is called.

[Argument]
Describes the argument of this function.

[Return Value]
Describes the return values from this function.

[Flow] (FSL_SwapBootCluster() function only)


Describes the internal flow of this function.

[Operation Example] (FSL_ChangeInterruptTable() and FSL_RestoreInterruptTable() functions only)


Describes operation examples for using this function.

R01US0050EJ0105 Rev.1.05 Page 55 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far FSL_Init(const __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.

R01US0050EJ0105 Rev.1.05 Page 56 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

 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.

[Register State After Call]


Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[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)

Definition of __far fsl_descriptor_t*

Development tool C language (Structure definition) Assembly language (Example of definition)

RENESAS CA78K0R compiler typedef struct { fsl_descriptor_str:


fsl_u08 fsl_flash_voltage_u08; DB fsl_flash_voltage_u08
fsl_u08 fsl_frequency_u08; DB fsl_frequency_u08
fsl_u08 fsl_auto_status_check_u08; DB fsl_auto_status_check_u08
} fsl_descriptor_t;
RENESAS CC-RL compiler typedef struct { fsl_descriptor_str:
fsl_u08 fsl_flash_voltage_u08; .DB fsl_flash_voltage_u08
fsl_u08 fsl_frequency_u08; .DB fsl_frequency_u08
fsl_u08 fsl_auto_status_check_u08; .DB fsl_auto_status_check_u08
} fsl_descriptor_t;

R01US0050EJ0105 Rev.1.05 Page 57 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Parameters in __far fsl_descriptor_t*

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

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __far fsl_descriptor_t *descriptor_pstr AX(0-15), C(16-23)


The start address of the variable (24 bits)
RENESAS CC-RL compiler const __far fsl_descriptor_t *descriptor_pstr DE(0-15), A(16-23)
The start address of the variable (24 bits)

[Return Value]

State Description

0x00(FSL_OK) Normal completion


- Initial setting is complete.
0x05(FSL_ ERR_PARAMETER) Parameter error
- The frequency value is outside the allowable setting range.
- The high-speed on-chip oscillator is not running.

R01US0050EJ0105 Rev.1.05 Page 58 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_Open

[Overview]
Start declaration of flash self-programming (starting of the flash environment)

[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_Open(void)

RENESAS CC-RL compiler


void __far 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.

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 59 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_Close

[Overview]
End declaration of flash self-programming (ending of the flash environment)

[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_Close(void)

RENESAS CC-RL compiler


void __far 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.

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 60 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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 )

RENESAS CC-RL compiler


void __far 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

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 61 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


void __far 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

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 62 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


void __far 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.

[Register State After Call]


The registers are not destructed.

R01US0050EJ0105 Rev.1.05 Page 63 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Argument]
Definition of argument

Argument Description

RAM address of the interrupt destination (lower 16 bits: FxxxxH ) *Upper bits are not
fsl_u16 fsl_interrupt_destination_u16
required.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler fsl_u16 fsl_interrupt_destination_u16 AX(0-15):


RAM address (lower 16 bits)
RENESAS CC-RL compiler fsl_u16 fsl_interrupt_destination_u16 AX(0-15):
RAM address (lower 16 bits)

[Return Value]
None

[Operation Example]

Start interrupt destination


change processing

DI

FSL_ChangeInterruptTable()

EI

End interrupt destination


change processing

R01US0050EJ0105 Rev.1.05 Page 64 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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 )

RENESAS CC-RL compiler


void __far 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.

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 65 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Operation Example]

Start interrupt destination


change processing

DI

<R> FSL_RestoreInterruptTable()

EI

End interrupt destination


change processing

R01US0050EJ0105 Rev.1.05 Page 66 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_BlankCheck

[Overview]
Blank checking of the specified block

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_BlankCheck(fsl_u16 block_u16)

RENESAS CC-RL compiler


fsl_u08 __far 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.

R01US0050EJ0105 Rev.1.05 Page 67 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

block_u16 Block number of the block to be blank-checked

Contents of argument settings

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

0x00(FSL_OK) Normal completionNote1


- The specified block is in the blank state.
0x05(FSL_ERR_PARAMETER) Parameter error
- The specification of the block number is outside the allowable setting range.
0x1B(FSL_ERR_BLANKCHECK) Blank check errorNote1
- The specified block is not in the blank state.
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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 68 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_Erase

[Overview]
Erasure of the specified block

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_Erase(fsl_u16 block_u16)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

R01US0050EJ0105 Rev.1.05 Page 69 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Argument]
Definition of argument

Argument Description

block_u16 Block number of the block to be erased

Contents of argument settings

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

0x00(FSL_OK) Normal completionNote1


0x05(FSL_ERR_PARAMETER) Parameter error
- The specification of the block number is outside the allowable setting range.
0x10(FSL_ERR_PROTECTION) Protect error
- The specified block is included in the boot area, and the boot area rewrite
permission flag is set to protected.
- The specified block is outside the FSW setting area.
0x1A(FSL_ERR_ERASE) Erasure errorNote1
- An error occurred during erasure 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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 70 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_IVerify

[Overview]
Verification (internal verification) of the specified block

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_IVerify(fsl_u16 block_u16)

RENESAS CC-RL compiler


fsl_u08 __far 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.

R01US0050EJ0105 Rev.1.05 Page 71 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

block_u16 Block number to be verified

Contents of argument settings

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

0x00(FSL_OK) Normal completionNote1


0x05(FSL_ERR_PARAMETER) Parameter error
- The specification of the block number is outside the allowable setting range.
0x1B(FSL_ERR_IVERIFY) Verification (internal verification) errorNote1
- An error occurred during verification (internal verification) 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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 72 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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).

R01US0050EJ0105 Rev.1.05 Page 73 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Remark To write data larger than 256 bytes, call this function multiple times.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

__near fsl_write_t* write_pstr Write data storage settings


(Data buffer address, write destination address, and write size)

Definition of fsl_write_t

Development tool C language (Structure definition) Assembly language (Example of definition)

RENESAS CA78K0R compiler typedef struct { fsl_write_str :


fsl_u08 __near *fsl_data_buffer_p_u08; DW fsl_data_buffer_p_u08:
fsl_u32 fsl_destination_address_u32; DG fsl_destination_address_u32:
fsl_u08 fsl_word_count_u08; DB fsl_word_count_u08:
} fsl_write_t;
RENESAS CC-RL compiler typedef struct { fsl_write_str :
fsl_u08 __near *fsl_data_buffer_p_u08; .DB2 fsl_data_buffer_p_u08:
fsl_u32 fsl_destination_address_u32; .DB4 fsl_destination_address_u32:
fsl_u08 fsl_word_count_u08; .DB fsl_word_count_u08:
} 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)

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near fsl_write_t* write_pstr AX(0-15):


The start address of the variable (16 bits)
RENESAS CC-RL compiler __near fsl_write_t* write_pstr AX(0-15):
The start address of the variable (16 bits)

R01US0050EJ0105 Rev.1.05 Page 74 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 75 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_GetSecurityFlags

[Overview]
Acquisition of security information

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetSecurityFlags(fsl_u08 __near *data_destination_pu08)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

fsl_u08 __near *data_destination_pu08 Data storage buffer


- Reserve a 1-byte data buffer.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near *data_destination_pu08 AX(0-15):


The start address of the data buffer (16 bits)
RENESAS CC-RL compiler __near *data_destination_pu08 AX(0-15):
The start address of the data buffer (16 bits)

R01US0050EJ0105 Rev.1.05 Page 76 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

State Description

0x00(FSL_OK) Normal completion

0x1F(FSL_ERR_FLOW) Flow error


- The processing of the flash function executed immediately before has not
been completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.

Security bit information


The security bit information is written to the data storage buffer (data_destination_pu08) passed in the argument.

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

R01US0050EJ0105 Rev.1.05 Page 77 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_GetBootFlag

[Overview]
Acquisition of boot flag information

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetBootFlag(fsl_u08 __near *data_destination_pu08)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

fsl_u08 __near *data_destination_pu08 Data storage buffer


- Reserve a 1-byte data buffer.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near *data_destination_pu08 AX(0-15):


The start address of the data buffer (16 bits)
RENESAS CC-RL compiler __near *data_destination_pu08 AX(0-15):
The start address of the data buffer (16 bits)

R01US0050EJ0105 Rev.1.05 Page 78 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

State Description

0x00(FSL_OK) Normal completion

0x1F(FSL_ERR_FLOW) Flow error


- The processing of the flash function executed immediately before has not been
completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.

Boot flag information


The boot flag information is written to the data storage buffer (data_destination_pu08) passed in the argument.

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.

R01US0050EJ0105 Rev.1.05 Page 79 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_GetSwapState

[Overview]
Acquisition of the swap state

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_GetSwapState(fsl_u08 __near *data_destination_pu08)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
Definition of argument

Argument Description

fsl_u08 __near *data_destination_pu08 Data storage buffer


- Reserve a 1-byte data buffer.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near *data_destination_pu08 AX(0-15):


The start address of the data buffer (16 bits)
RENESAS CC-RL compiler __near *data_destination_pu08 AX(0-15):
The start address of the data buffer (16 bits)

R01US0050EJ0105 Rev.1.05 Page 80 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

State Description

0x00(FSL_OK) Normal completion

0x1F(FSL_ERR_FLOW) Flow error


- The processing of the flash function executed immediately before has not been
completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.

Boot swap status


The boot swap information is written to the data storage buffer (data_destination_pu08) passed in the argument.

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.

R01US0050EJ0105 Rev.1.05 Page 81 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[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

R01US0050EJ0105 Rev.1.05 Page 82 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Definition of fsl_getblockendaddr_t

Development tool C language (Structure definition) Assembly language (Example of definition)

RENESAS CA78K0R compiler typedef struct { fsl_getblockendaddr_str:


fsl_u32 fsl_destination_address_u32; DG fsl_destination_address_u32
fsl_u16 fsl_block_u16 DW fsl_block_u16
} fsl_getblockendaddr_t;
RENESAS CC-RL compiler typedef struct { fsl_getblockendaddr_str:
fsl_u32 fsl_destination_address_u32; .DB4 fsl_destination_address_u32
fsl_u16 fsl_block_u16 .DB2 D2 fsl_block_u16
} fsl_getblockendaddr_t;

Contents of fsl_getblockendaddr_t

Argument Description

fsl_u32 fsl_destination_address_u32 End address storage buffer :Output


- Reserve a 4-byte data buffer.
fsl_u16 fsl_block_u16 Block number :Input

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near fsl_getblockendaddr_t* AX(0-15):


getblockendaddr_pstr The start address of the variable (16 bits)
RENESAS CC-RL compiler __near fsl_getblockendaddr_t* AX(0-15):
getblockendaddr_pstr The start address of the variable (16 bits)

[Return Value]

State Description

0x00(FSL_OK) Normal completion


0x05(FSL_ ERR_PARAMETER) Parameter error
- The specification of the block number is outside the allowable setting range.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not
been completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 83 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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);

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[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)

R01US0050EJ0105 Rev.1.05 Page 84 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

Definition of fsl_fsw_t

Development tool C language (Structure definition) Assembly language (Example of definition)

RENESAS CA78K0R compiler typedef struct { _getfsw_pstr:


fsl_u16 fsl_start_block_u16; DW fsl_start_block_u16:
fsl_u16 fsl_end_block_u16; DW fsl_end_block_u16
} fsl_fsw_t;
RENESAS CC-RL compiler ypedef struct { _getfsw_pstr:
fsl_u16 fsl_start_block_u16; .DB2 fsl_start_block_u16:
fsl_u16 fsl_end_block_u16; .DB2 fsl_end_block_u16
} fsl_fsw_t

Contents of __near fsl_fsw_t

Argument Description

fsl_u16 fsl_start_block_u16; FSW start block storage buffer


- Reserve a 2-byte data buffer.
fsl_u16 fsl_end_block_u16; FSW end block storage buffer
- Reserve a 2-byte data buffer.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near fsl_fsw_t* getfsw_pstr AX(0-15):


The start address of the variable (16 bits)
RENESAS CC-RL compiler __near fsl_fsw_t* getfsw_pstr AX(0-15):
The start address of the variable (16 bits)

[Return Value]

State Description

0x00(FSL_OK) Normal completion


0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not been
completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 85 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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).

R01US0050EJ0105 Rev.1.05 Page 86 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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.

[Register State After Call]


Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

[Return Value]

State Description

0x10(FSL_ERR_PROTECTION) Protect error


- Boot swapping was attempted in the boot area rewrite-protected state.
0x1F(FSL_ERR_FLOW) Flow error
- The processing of the flash function executed immediately before has not
been completed.Note
- The prerequisite defined in presetting is violated.
- Flash self-programming is in the pause state.Note

Note Only in the status check user mode.


Remark For normal completion, the return value cannot be checked.

[Flow]

FSL_SwapBootCluster

PUSH PSW

DI

Swap processing of the boot cluster

YES
Error?

NO

End the flash environment POP PSW

Read the reset vector Function return

Jump to the registered address


of the reset vector

R01US0050EJ0105 Rev.1.05 Page 87 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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.

R01US0050EJ0105 Rev.1.05 Page 88 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 89 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_InvertBootFlag

[Overview]
Inverting of the current value of the boot flag

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_InvertBootFlag(void)

RENESAS CC-RL compiler


fsl_u08 __far 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).

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 90 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 91 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_SetBlockEraseProtectFlag

[Overview]
Setting of the block erasure protection flag to protected

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetBlockEraseProtectFlag(void)

RENESAS CC-RL compiler


fsl_u08 __far 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).

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 92 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 93 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_SetWriteProtectFlag

[Overview]
Setting of the write protection flag to protected

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetWriteProtectFlag(void)

RENESAS CC-RL compiler


fsl_u08 __far 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).

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 94 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 95 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_SetBootClusterProtectFlag

[Overview]
Setting of the boot area rewrite protection flag to protected

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_SetBootClusterProtectFlag(void)

RENESAS CC-RL compiler


fsl_u08 __far 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).

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 96 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 97 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

R01US0050EJ0105 Rev.1.05 Page 98 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Argument]
Definition of argument

Argument Description
__near fsl_fsw_t* setfsw_pstr Variable for FSW setting
(FSW start block number and end block number)

Definition of __near fsl_fsw_t

Development tool C language (Structure definition) Assembly language (Example of definition)

RENESAS CA78K0R compiler t typedef struct { fsl_fsw_str:


fsl_u16 fsl_start_block_u16; DW fsl_start_block_u16:
fsl_u16 fsl_end_block_u16; DW fsl_end_block_u16
} fsl_fsw_t;
RENESAS CC-RL compiler typedef struct { fsl_fsw_str:
fsl_u16 fsl_start_block_u16; .DB2 fsl_start_block_u16:
fsl_u16 fsl_end_block_u16; .DB2 fsl_end_block_u16
} fsl_fsw_t;

Contents of __near fsl_fsw_t

Argument Description

FSW start block storage buffer


fsl_u16 fsl_start_block_u16;
- Reserve a 2-byte data buffer.
FSW end block storage buffer
fsl_u16 fsl_end_block_u16;
- Reserve a 2-byte data buffer.

Contents of argument settings

Argument Type/Register
Development tool
C language Assembly language

RENESAS CA78K0R compiler __near fsl_fsw_t* setfsw_pstr AX(0-15):


The start address of the variable (16 bits)
RENESAS CC-RL compiler __near fsl_fsw_t* setfsw_pstr AX(0-15):
The start address of the variable (16 bits)

R01US0050EJ0105 Rev.1.05 Page 99 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check internal mode.


2. Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 100 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_StatusCheck

[Overview]
Checking of the operation state of the flash function

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_StatusCheck( void )

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 101 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.

Note Only in the status check user mode.

R01US0050EJ0105 Rev.1.05 Page 102 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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)

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 103 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.

Notes 1. Only in the status check user mode.


2. Only when erasure processing is paused.

R01US0050EJ0105 Rev.1.05 Page 104 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_WakeUp

[Overview]
Canceling of the pause state to restart flash self-programming

[Format]
<C language>
RENESAS CA78K0R compiler
fsl_u08 FSL_WakeUp( void )

RENESAS CC-RL compiler


fsl_u08 __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler C(General-purpose register) -


RENESAS CC-RL compiler A(General-purpose register) -

[Argument]
None

R01US0050EJ0105 Rev.1.05 Page 105 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01
[Return Value]

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.)

Notes 1. Only in the status check user mode.


2. Only when erasure processing is restarted.

R01US0050EJ0105 Rev.1.05 Page 106 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

FSL_ForceReset

[Overview]
Resetting of the RL78 microcontroller in use

[Format]
<C language>
RENESAS CA78K0R compiler
void FSL_ForceReset(void)

RENESAS CC-RL compiler


void __far 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.

[Register State After Call]


The registers are not destructed.

[Argument]
None

[Return Value]
None

R01US0050EJ0105 Rev.1.05 Page 107 of 112


Oct 31, 2018
RL78 Family CHAPTER 6 FLASH FUNCTIONS
Flash Self-Programming Library Type 01

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 )

RENESAS CC-RL compiler


__far fsl_u08* __far 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.

[Register State After Call]

Development tool Return value Destructed register

RENESAS CA78K0R compiler BC(0-15), DE(16-31) -


RENESAS CC-RL compiler DE(0-15), A(16-23) -

[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

R01US0050EJ0105 Rev.1.05 Page 108 of 112


Oct 31, 2018
RL78 Family APPENDIX A REVISION HISTORY
Flash Self-Programming Library Type 01

APPENDIX A REVISION HISTORY

A. 1 Major Revisions in This Edition

Page Description Classification


Throughout the document
- Correction of errors. (a)
Cover
- The ZIP file name was changed to the installer name. (d)
Chapter 6 Flash Function
p.43 The supported device was corrected. (a)
Operation example:Function name was changed from
p.66 (a)
FSL_ChangeInterruptTable() to FSL_RestoreInterruptTable().
p.107 The emulator was added. (c)

Remark "Classification" in the above table classifies revisions as follows.


(a): Error correction, (b): Addition/change of specifications, (c): Addition/change of description or note,
(d): Addition/change of package, part number, or management division,
(e): Addition/change of related documents

R01US0050EJ0105 Rev.1.05 Page 109 of 112


Oct 31, 2018
RL78 Family APPENDIX A REVISION HISTORY
Flash Self-Programming Library Type 01

A. 2 Revision History of Preceding Editions

Here is the revision history of the preceding editions. Chapter indicates the chapter of each edition.

Rev. Description Chapter


Rev.1.04 The English translation was reviewed and corrected. Throughout
The user's manual of the flash self-programming library for CC-RL was integrated the document
into this manual.
Support of the RL78/G11 group microcontrollers was added.
In Table 2-5, the description of FSL_Erase Call Interval was corrected. Chapter 2 Programming
A description regarding the supported compilers was added. Environment
In Table 2-7, the software resources for the CC-RL compiler were added.
In Table 2-8, the stack sizes for the CC-RL compiler were added.
In Tables 2-10 and 2-11, the ROM and RAM sizes for the CC-RL compiler were
added.
The methods for allocating the self-RAM area and specifying desired addresses
in the CC-RL compiler were added.
A description regarding the start of the high-speed on-chip oscillator was added.
A description regarding operation frequency setting was added.
The applicable versions were added to the restriction on segment allocation.
The description that each segment must not extend across a 64-Kbyte boundary
was added.
The method for representing hexadecimal numbers in the assembler in the
Renesas CC-RL compiler package was added.
A restriction regarding allocation of the functions for boot swapping was added. Chapter 5 Boot Swap
Function
In Table 6-1, the functions supported for the RL78/G11 group microcontrollers Chapter 6 Flash
were added. Function
In note 1, the status check mode supported for the RL78/G11 group
microcontrollers were added.
The heading of section 6.2 was changed ("Section" was added).
The description regarding allocation to specified areas was reviewed and
corrected.
The return values from each library function in the CC-RL compiler were added
The C-language format for each library function in the CC-RL compiler was
added.
The definitions and descriptions of the arguments for each library function in the
CC-RL compiler were added.
The descriptions regarding the return values and arguments in each function
were corrected.
The descriptions regarding the boot area addresses were modified.
Caution 7 was added to the description of the FSL_SwapBootCluster function.

R01US0050EJ0105 Rev.1.05 Page 110 of 112


Oct 31, 2018
RL78 Family APPENDIX A REVISION HISTORY
Flash Self-Programming Library Type 01

Rev. Description Chapter


Rev.1.03 The corresponding ZIP file name and release version were added to the cover. Throughout
The target device descriptions were deleted. the document

References to the list of the target MCUs were added.


The term "voltage mode" was changed to "flash memory programming mode" for
consistency of terminology.
Various types of operating frequency described in the former version were unified
to the CPU operating frequency.
A description regarding boot cluster 0 was added to the boot area.
The FSL_IVerify state check processing was added to Figure 2-2. Chapter 1 Overview

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 Rev.1.05 Page 111 of 112


Oct 31, 2018
RL78 Family APPENDIX A REVISION HISTORY
Flash Self-Programming Library Type 01

Rev. Description Chapter


Rev.1.02 The document on the data flash library, which was classified as the application note Throughout
(old version of R01AN0350), was changed to the user’s manual.
the document
The corresponding installer and release version were added to the cover page.
Contents of the processing time and software resources were moved from the
usage note to this document. Accordingly, the reference destination described in
this document was also changed.
The supported device was added.
The notation of high-speed OCO was deleted to unify the notation of high-speed
on-chip oscillator.
The description of the operating frequency was unified to the CPU operating
frequency since individual descriptions had different notations.
The state transition from “prepared” to “extprepared” was added to figure 1-1. Chapter 1 Overview
Description on the FSL_PrepareFunctions function was added.
The names of functions were clearly stated in the overall description.
Notes on rewriting were added.
Notes on internal verification were added.
State when the FSL_Close function is executed was added.
Notes on the interrupt were added. Chapter 2 Programming
Description of the mode selection was added to the example of controlling rewriting Environment
of the flash memory.
Description of the initial setting was added
Items regarding the processing time were added (the description of the processing
time was moved from the usage note to this document).
Items regarding the resources were added (the description on the resources was
moved from the usage note to this document).
Note on the frequency of the high-speed on-chip oscillator was added.
Note on the RAM parity error was added.
Note on the writing was added.
Description of the non-supported product (R5F10266) was added.
Note on the interrupt was added.
Note on the boot swap function was added.
Note on the security setting was added.
Notes on the interrupt were added. Chapter 3 Interrupts
During Execution of
Flash
Self-Programming
Note on the security setting was added. Chapter 4 Security
Setting
Tables of defining structures and tables of parameter contents were added. Chapter 6 Flash
Descriptions were added to the sections for assembler in the field of settings
Function
of arguments.
Note on the internal reset was added.

R01US0050EJ0105 Rev.1.05 Page 112 of 112


Oct 31, 2018
RL78 Microcontrollers User’s Manual: Flash Self-Programming Library Type 01

Publication Date: Rev.1.00 Mar 31, 2011


Rev.1.05 Oct 31, 2018

Published by: Renesas Electronics Corporation


SALES OFFICES http://www.renesas.com
Refer to "http://www.renesas.com/" for the latest and detailed information.
Renesas Electronics Corporation
TOYOSU FORESIA, 3-2-24 Toyosu, Koto-ku, Tokyo 135-0061, Japan
Renesas Electronics America Inc.
1001 Murphy Ranch Road, Milpitas, CA 95035, U.S.A.
Tel: +1-408-432-8888, Fax: +1-408-434-5351
Renesas Electronics Canada Limited
9251 Yonge Street, Suite 8309 Richmond Hill, Ontario Canada L4C 9T3
Tel: +1-905-237-2004
Renesas Electronics Europe Limited
Dukes Meadow, Millboard Road, Bourne End, Buckinghamshire, SL8 5FH, U.K
Tel: +44-1628-651-700
Renesas Electronics Europe GmbH
Arcadiastrasse 10, 40472 Düsseldorf, Germany
Tel: +49-211-6503-0, Fax: +49-211-6503-1327
Renesas Electronics (China) Co., Ltd.
Room 1709 Quantum Plaza, No.27 ZhichunLu, Haidian District, Beijing, 100191 P. R. China
Tel: +86-10-8235-1155, Fax: +86-10-8235-7679
Renesas Electronics (Shanghai) Co., Ltd.
Unit 301, Tower A, Central Towers, 555 Langao Road, Putuo District, Shanghai, 200333 P. R. China
Tel: +86-21-2226-0888, Fax: +86-21-2226-0999
Renesas Electronics Hong Kong Limited
Unit 1601-1611, 16/F., Tower 2, Grand Century Place, 193 Prince Edward Road West, Mongkok, Kowloon, Hong Kong
Tel: +852-2265-6688, Fax: +852 2886-9022
Renesas Electronics Taiwan Co., Ltd.
13F, No. 363, Fu Shing North Road, Taipei 10543, Taiwan
Tel: +886-2-8175-9600, Fax: +886 2-8175-9670
Renesas Electronics Singapore Pte. Ltd.
80 Bendemeer Road, Unit #06-02 Hyflux Innovation Centre, Singapore 339949
Tel: +65-6213-0200, Fax: +65-6213-0300
Renesas Electronics Malaysia Sdn.Bhd.
Unit 1207, Block B, Menara Amcorp, Amcorp Trade Centre, No. 18, Jln Persiaran Barat, 46050 Petaling Jaya, Selangor Darul Ehsan, Malaysia
Tel: +60-3-7955-9390, Fax: +60-3-7955-9510
Renesas Electronics India Pvt. Ltd.
No.777C, 100 Feet Road, HAL 2nd Stage, Indiranagar, Bangalore 560 038, India
Tel: +91-80-67208700, Fax: +91-80-67208777
Renesas Electronics Korea Co., Ltd.
17F, KAMCO Yangjae Tower, 262, Gangnam-daero, Gangnam-gu, Seoul, 06265 Korea
Tel: +82-2-558-3737, Fax: +82-2-558-5338

© 2018 Renesas Electronics Corporation. All rights reserved.


Colophon 5.2
RL78 Family

R01US0050EJ0105

You might also like