DSASW00429032
DSASW00429032
µPD78F0828B
8-bit Single-Chip Microcontroller
The related documents in this publication may include preliminary versions. However, preliminary
versions are not marked as such.
The export of this product from Japan is regulated by the Japanese government. To export this
product may be prohibited without governmental license, the need for which must be judged by th
customer. The export or re-export of this product from a country other than Japan may also be
prohibited without a license from that country. Please call an NEC sales representative.
The information in this document is current as of 02.11.2000. The information is subject to change without
notice. For actual design-in, refer to the latest publications of NEC’s data sheets or data books, etc., for
the most up-to-date specifications of NEC semiconductor products. Not all products and/or types are
available in every country. Please check with an NEC sales representative for availability and additional
information. No part of this document may be copied or reproduced in any form or by any means without
prior written consent of NEC. NEC assumes no responsibility for any errors that may appear in this
document. NEC does not assume any liability for infringement of patents, copyrights or other intellectual
property rights of third parties by or arising from the use of NEC semiconductor products listed in this
document or any other liability arising from the use of such products. No license, express, implied or
otherwise, is granted under any patents, copyrights or other intellectual property rights of NEC or others.
Descriptions of circuits, software and other related information in this document are provided for illustrative
purposes in semiconductor product operation and application examples. The incorporation of these
circuits, software and information in the design of customer’s equipment shall be done under the full
responsibility of customer. NEC assumes no responsibility for any losses incurred by customers or third
parties arising from the use of these circuits, software and information. While NEC endeavours to enhance
the quality, reliability and safety of NEC semiconductor products, customers agree and acknowledge that
the possibility of defects thereof cannot be eliminated entirely. To minimize risks of damage to property
or injury (including death) to persons arising from defects in NEC semiconductor products, customers must
incorporate sufficient safety measures in their design, such as redundancy, fire-containment and anti-
failure features. NEC semiconductor products are classified into the following three quality grades:
“Standard”, “Special” and “Specific”. The “Specific” quality grade applies only to semiconductor products
developed based on a customer-designated “quality assurance program” for a specific application. The
recommended applications of a semiconductor product depend on its quality grade, as indicated below.
Customers must check the quality grade of each semiconductor product before using it in a particular
application.
"Standard": Computers, office equipment, communications equipment, test and measurement equip-
ment, audio and visual equipment, home electronic appliances, machine tools, personal
electronic equipment and industrial robots.
"Special": Transportation equipment (automobiles, trains, ships, etc.), traffic control systems, anti-
disaster systems, anti-crime systems, safety equipment and medical equipment (not specifi-
cally designed for life support).
"Specific": Aircrafts, aerospace equipment, submersible repeaters, nuclear reactor control systems, life
support systems or medical equipment for life support, etc.
The quality grade of NEC semiconductor products is “Standard“ unless otherwise expressly specified in
NEC's data sheets or data books, etc.
If customers wish to use NEC semiconductor products in applications not intended by NEC, they must
contact an NEC sales representative in advance to determine NEC's willingness to support a given
application.
Notes: (1) “NEC” as used in this statement means NEC Corporation and also includes its majority-owned
subsidiaries.
(2) “NEC semiconductor products” means any semiconductor product developed or manufactured
by or for NEC (as defined above).
M5 2000.03
• Device availability
• Ordering information
• Development environment specifications (for example, specifications for third-party tools and
components, host computers, power plugs, AC supply voltages, and so forth)
• Network requirements
In addition, trademarks, registered trademarks, export restrictions, and other legal issues may also vary
from country to country.
NEC Electronics Inc. (U.S.) NEC Electronics (Germany) GmbH NEC Electronics Hong Kong Ltd.
Santa Clara, California Benelux Office Hong Kong
Tel: 408-588-6000 Eindhoven, The Netherlands Tel: 2886-9318
800-366-9782 Tel: 040-2445845 Fax: 2886-9022/9044
Fax: 408-588-6130 Fax: 040-2444580
800-729-9288 NEC Electronics Hong Kong Ltd.
NEC Electronics (France) S.A. Seoul Branch
NEC Electronics (Germany) GmbH Vélizy-Villacoublay, France Seoul, Korea
Duesseldorf, Germany Tel: 01-30-67 58 00 Tel: 02-528-0303
Tel: 0211-65 03 02 Fax: 01-30-67 58 99 Fax: 02-528-4411
Fax: 0211-65 03 490
NEC Electronics (France) S.A. NEC Electronics Singapore Pte. Ltd.
NEC Electronics (UK) Ltd. Spain Office United Square, Singapore 1130
Milton Keynes, UK Madrid, Spain Tel: 65-253-8311
Tel: 01908-691-133 Tel: 91-504-2787 Fax: 65-250-3583
Fax: 01908-670-290 Fax: 91-504-2860
NEC Electronics Taiwan Ltd.
NEC Electronics Italiana s.r.l. NEC Electronics (Germany) GmbH Taipei, Taiwan
Milano, Italy Scandinavia Office Tel: 02-2719-2377
Tel: 02-66 75 41 Taeby, Sweden Fax: 02-2719-5951
Fax: 02-66 75 42 99 Tel: 08-63 80 820
Fax: 08-63 80 388 NEC do Brasil S.A.
Electron Devices Division
Rodovia Presidente Dutra, Km 214
07210-902-Guarulhos-SP Brasil
Tel: 55-11-6465-6810
Fax: 55-11-6465-6829
J99.1
Readers This manual is intended for users who want to understand the functions of the
µPD78F0828B.
This users manual shall serve as a programming-aid for any customer who is using the NEC-K0-family
Secure SelfProgramming-firmware with Realtime-support like it is implemented in the µPD78F0828B
(CANASSP3). Both, Hard- and Software-Environment have to be configured to use Self-Programming.
Two different modes are possible to access the Flash-Memory:
• Using the OnBoard-Programming Mode: An initial program has to be programmed into the device
via a programming-tool like the FLASH-Master. It can be connected to an interface on an applica-
tion-target board. This program is either the full code to be programmed, or should include a so
called BOOT-LOADER located in the lower FLASH-memory-area. The main task of this BOOT-
LOADER is to start basic software-functions after leaving the RESET-mode and to support the
Flash-Self-Programming-functionality for reprogramming from a connected network.
• Using the Self-Programming Mode: In self-programming mode data can be programmed to the
flash. Data can be parameters or program code that got into the device by support of the user pro-
gram. Therefore the user program can use all device specific peripherals like CAN, UART and tim-
ers. Once the data is in the device, e.g. buffered in the RAM area, it can be programmed via an
internal programming interface to the upper half flash area. The flash-ROM is divided into two
blocks, an upper (block 1) and a lower block (block 0). Only the upper block can be programmed in
self-programming mode.To write data also into the lower block, the two blocks can be switched with
the swap self-programming function, so that the old lower block will be permanently the upper block.
This new constellation is also valid after RESET. A further call of the swap routine will fail, until the
present upper block is erased.
Timer
CAN I/O
User Cod
Programming
Interface
Flash
Programming
10 Vpp Voltage
Generator
This document explains how self-programming is working and how it can be used under assistance of
an API (Application Programming Interface). This API is realized as a library, written in a higher-level
programming language (ANSI-C). It should facilitate the use of the self-programming functions out of
the user program.
In the second chapter the environment is described how this API can be used in programs to get full
self-programming functionality.
This document is based on the device 78F0828B but can easily be used for other devices with the
same self-programming technology and real time support.
The following chapter will describe the main-topics of Self-Programming on the µPD78F0828B and how
the programming is done on the chip.
1.2.1 Description
Starting with a un-programmed chip, the user is responsible to program a boot-loader, supporting the
Self-Programming-functions, in the lower block of the Flash-Area. The Self-Programming support- func-
tions must be included in the final application program, too, if data- or parameter-updates are further
necessary.
By a user-defined communication-channel data must be written to a specified RAM-Area; this data is
later-on programmed to the upper-memory-block.
After programming of upper-ROM-block is done, the ROM-blocks are swapped so the actual code
resides in the old ROM-block1. Now, the new ROM-block0 can be programmed, whereby all Flash-
Memory is Write-accessible.
- Normal Flash-Programming: The user can program the Flash-Area, but no security and no sup-
port of RAM-based functions are given while running the Firmware-routines
- Secure Flash Self-Programming: The user can program the Flash-Area, but in case of failures, at
least one ROM-block is recognized to contain valid data.
- RTSF-Selfprogramming: The user can run any function without interrupt, but using watchdog, out
of a pre-defined RAM-Area while using the Self-Programming routines. This is called RealTime-
SupportFunction.
0xFFFF
Special Function Register
256 x 8Bit
0xFF00
General Register
32 x 8Bit
NOT Useable
0xFA80
0xFA7F
LC-Display RAM
0xFA64 28 x 4Bit
0xFA63
NOT Useable
0xF7DF
Application and DCAN-RAM
0xF600
0xF5FF
User-Area, Expans. RA
0xF000 1.5 kByte
Not useable
0xEE00
0xEDFF Internal Flash ROM
Block 1
0x76F
Internal Flash ROM
Block 0
0x0000
As described, the ROM is divided into an upper and a lower block; only the upper block is directly
accessible for the Self-Programming routines. Nevertheless, the whole Flash-Area is programmable by
using the Self-Programming Swap-Function.
After applying the 10 V to V PP and entering Self-Programming mode, the upper ROM-block will be
switched with the hidden-ROM-Area.
Erase
Flash Memory Flash Memory Write
29,75K bytes FLSPM0 <- 1 29,75K bytes Verify
(erasable area) Hidden ROM (erasable area) Hidden ROM
entering
Self-prog. Mode
7700 leaving 7700
FLSPM0 <- 0
Flash Memory Flash Memory
29,75K bytes 29,75K bytes
Subroutine call
Boot Strap Boot Strap
Interrupt Interrupt
Lower Block
From this Hidden-ROM-area, all Self-Programming-functions calls are executed. After the boot-strap
and the code is written, the upper ROM-block contains the new program, so the ROM-blocks are re-
switched to enable the new code. Now the new block1 can be programmed. The below figure shows
this in detail.
Figure 1-6: Detailed description of Flash-Programming
Internal RAM inkl. Internal RAM inkl. Internal RAM inkl. Internal RAM inkl.
SFR: 1,0Kbytes SFR: 1,0Kbytes SFR: 1,0Kbytes SFR: 1,0Kbytes
CAN RAM: 0,5 Kb CAN RAM: 0,5 Kb CAN RAM: 0,5 Kb CAN RAM: 0,5 Kb
F600
Code executable Code executable Code executable Code executable
RAM: 1,5Kbytes RAM: 1,5Kbytes RAM: 1,5Kbytes RAM: 1,5Kbytes
F000
EDFF
Flash Memory
Block 1
Block 1
Block 0
7700
Boot Strap
Flash Memory
Flash Memory
Block 0
Block 1
Block 1
Block 0
The Entry-RAM-Area is a pre-defined area with a length of 32 bytes. These bytes contain all data nec-
essary for the firmware-routines and are initialized by the library-call-function SP_Init.
Normally, pre-defined values are stored here by the Init-Function, so the user shouldn’t change them. If
there is a need to change this values, please follow the information provided in this chapter.
struct ERAM
{
unsigned char _Reserved1;
unsigned char _Reserved2;
unsigned int _FlashMemStartAdr;
unsigned int _Reserved3;
unsigned char _ByteInFlash_BlockNo;
unsigned char _WriteTimeData1;
unsigned char _EraseTimeData1;
unsigned char _EraseTimeData2;
unsigned char _EraseTimeData3;
unsigned char _ConvTimeData1;
unsigned char _ConvTimeData2;
unsigned char _ConvTimeData3;
unsigned int _WrDatStorStartAdr;
unsigned int _RAMRoutStartAdr;
unsigned int _FlashSwapRetAdr;
unsigned char _IntervTimeData1;
unsigned char _Reserved4[11];
};
The start-address of the entry-RAM-Area is defined in the API-header file and respective the linker-file.
The important elements in the Entry-RAM are described as follows:
• FlashMemory Start-Address: Here the address takes place, where the Flash-Writing routine starts to
write
• No. of bytes written in flash-memory: This value has to been set to 0x01allways - description of the
ROM-block number where firmware-routines take effect; only the Write-function is here in use of the
number of bytes which will be written (Maximum of 256 bytes in a row).
• EraseTimeData(1-3): These three values are calculated by the assumption, that in a first try, the
erasing of ROM should take 2 seconds of time; if the first erase wasn’t successful, the erase-time
will be changed to a value about 0.25 seconds and the block will be erased with this time-quanta
again, until the whole ROM is erased.
For two seconds erasing, the three values are defined as 0xF5, 0xB, 0x5 at 8 MHz following the formula
( EraseTimeData2 + EraseTimeData3 )
------------------------------------------------------------------------------------------------------------------
EraseTime = EraseTimeData1 × 2 OperatingFrequency
The values for TimeData2 and TimeData3 should be left as they are.
Example for Erase-Times of 2 and 0.25 seconds@8 MHz:
ConvTimedata2 + ConvTimeData3
---------------------------------------------------------------------------------------------------------
OperatingFrequency
ConversionTime = ConvTimeData1 × 2
• WriteData StoragBuffer StartAddress: These two bytes define the starting-address, of a RAM
buffer. The RAM buffer is used to stocks data for writing into the upper Flash-block and for verifying.
• RAM-routine StartAddress: These two bytes contain the address where the user-program is
located. It is called while the RTSF-function in ROM-programming is enabled.
• FlashSwap ReturnAddress: These cells contain the address, where after the FlashSwap the new
start-Vector of the new program-area is located.
• ReturnInterval TimeData1: This value adjusts the interval the RTSF-support function is called
depending on the external connected frequency. The ReturnIntervalTime is calculated by the for-
mula:
Example for 512 µsec that secures a RTSF-call of less than 1.024 msec.
Return-Interval Time:
To write this data by user-program, a pointer has to be defined (e.g. pointer_ERAM), which will be
anchored to an array located at the pre-defined EntryRAM-address (e.g. array_ERAM).
If the erase-time values from the first try to the repeated try should be changed, following syntax will do
this for example:
pointer_ERAM = &array_ERAM;
( ... )
pointer_ERAM ->_EraseTimeData1 = RepeEraseTimeData1; // sets the erase-time to shorter
cycle to prevent
pointer_ERAM ->_EraseTimeData2 = RepeEraseTimeData2; // flash-cells from stressing!
pointer_ERAM ->_EraseTimeData3 = RepeEraseTimeData3;
The pointer is linked to the array-structure, then the needed ER-values are set.
Following drawing will show sample values for the single function-times. These values are still prelimi-
nary and are intended to be changed. Besides, these values will give intentions for typical times,
changes to upper- or lower-bonds will be possible.
This five functions provide all features to do a Secure Self-Programming of the complete Flash-Area.
U se r S o ftw a re
SP_
SP_ SP_
Area
SP_Init Write Swap
SP_Erase Verify
S e lf -p r o g r a m m in g F ir m w a r e
RESE
A signature is located on the upper-side of each Flash-block. This signature is written active or non-
active, depending on the status the block should have.
The block with the written signature is automatically the lower block. In unfavourable circumstances
e.g. voltage drop, the signature of the upper Flash-block might be written and the one of the lower block
might not be destroyed.
After RESET, randomly one of the two blocks may be recognized as valid. In this case, the user must
prepare his software to recognize whether the original or the new programmed block is containing the
actual code
1.2.8 RTSF-Support
The RTSF (so called RealTimeSupportFunction)-support gives the user the possibility to let real time
functions like watchdog timer, network management communications or other run while the Self-Pro-
gramming functions are in use.
To start the RTSF-support by calling the Self-Programming-library-functions, a RTSF-value unequal to
0x0000, equivalent to the start-address of the RTSF-user-function in RAM must be set. This will call the
RTSF-function which will set this start-address of the RTSF-user-support-function into the Entry-RAM-
Area. For RTSF-usage, a dedicated Area form 0xF000 to max. 0xF5FF in RAM is reserved. The user
must define this Area in his.xcl-link-file and has to copy the RTSF-user-function into RAM by himself.
While calling the Self-Programming-routines, in non-equidistant steps lower than 1msec. the support-
function is called without halting the Self-Programming-routines.
Internal R AM inkl.
SFR : 1,0Kbytes
C AN R AM : 0,5 Kb
F600 Call User R outine
C ode executable
R AM : 1,5Kbytes
F000
Return
SW
ED FF
Loop
Erase
<1m s
Flash M em ory W rite
Enter 29,75K bytes Verify
(erasable area)
Hidden
SP-M ode ROM
FLSPM 0<- 1
7700
STO P
Flash M em ory
29,75K bytes
Boot Strap
Interrupt
Nevertheless, it is not dangerous to call user-support-functions probably running longer than the execu-
tion-interval of the Self-Programming-function. The SP-function is stopped after the execution-interval
is ended without any respect to the RTSF-user-function-duration.
Using this feature, no long-durating user-RTSF-support-function can disturb the running SP-proce-
dures.
The user-function resides in the Area from 0xF000 to max. 0xF5FF, equivalent to 1.5 KByte of RAM.
This Area must be allocated by the user for RTSF-support.
As a general overview, the whole procedure of Self-Programming is shown in the following diagram;
please use this as template for all Self-Programming purposes!
Start
Startofof
Self Programming
Self Programming RTSF
Call Firmware Subroutine
Copy Code to RAM <1ms
(only if RTSF used) Hidden ROM
- Erase/Blank check RTSF
Branch to lower /Write/Verify
flash block / RAM
Disable Vpp Voltage
Disable Interrupts
N
Vpp = 0V?
Select Self Programming Mode
RTSF
Y
Enable Vpp Voltage
Select Normal Operating Mode :User program
2.1 Memory-demands
As described before in this document, the RAM-usage has to be canalized for using all features of the
Flash-SelfProgramming routines. Some constant memory-layouts are necessary as follows:
An area with a length of 32 Bytes, containing the EntryRAM
The Write Data Storage-Buffer with a defined length of 256 Bytes
The Stack Area, length approximately 40 Byte
The User-Code Area with a max. length of 1.5 KByte, defined from 0xF000 to max. 0xF5FF.
2.1.2 Linker-configuration
//-------------------------------------------------------------------------------------------
// -LINK.XCL-
//
// XLINK command file to be used with the 78000 Embedded Workbench
// using procesor option -v1 memory model option -ms or -mS
//
//--------------------------------------------------------------------------------------------
// Archived: $Revision: 1.1 $
// (c) Copyright IAR Systems 199
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// changes for Secure SelfProgramming
// (C) NEC Electronics (Germany) GmbH 2000
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
// Define CPU.
//--------------------------------------------------------------------------------------------
-c78000
//--------------------------------------------------------------------------------------------
// Define all user-specific RAM-areas for Secure SelfProgrammin
//--------------------------------------------------------------------------------------------
The user-code area is fixed to location F000 tomax. F5FF, the Entry-RAM-Area is defined from FE21 to
FE43, resulting in a length of 32 bytes, the Read-Buffer is defined from F6E0 to F7DF, resulting in a
length of 256 Byte.
By allocating the needed segments above, the following Self-Programming memory-layout is gener-
ated:
0xFFFF
Special Function Register
256 x 8Bit
0xFF00
General Register
32 x 8Bit
Entry-RAM
Area
Internal high-speed RAM
0xFB00 1024 x 8Bit
0xFAFF
NOT Useable
0xFA80
0xFA7F
LC-Display RAM
0xFA64 28 x 4Bit
0xFA63
NOT Useable
0xF7DF
Read Buffer Storage Data
0xF600
0xF5FF
User-Area, Expans. RAM
0xF000 1.5 kByte
0xEDFF
Internal Flash ROM
Block 1
0x76FF
Internal Flash ROM
Block 0
0x0000
This chapter will describe the conditions to get a full running system with Self-Programming.
2.2.1 Pre-conditions
To get the Software running, the following should be defined before starting programming.
Which protocol should responsible to get the data to program from outside into the chip?
Define the protocol, using e.g. UART, CSI, CAN.
All functions will use very similar In- and Out-Parameters, which will be described as follows.
Input-Parameters
• RTSF-Parameter
The input-parameter used in every function is the _RTSF-variable.
If this variable is set to 0x0000 while calling the depending SP-library-function, no user-RTSF-
function will be called while making the SelfProgramming-function.
Otherwise, if there is need of the RTSF-Function, the starting-address of this user-function has to be
defined in the function-call; usually, this will define address in the range from 0xF000 to max. 0xF5FF
• SPWriteStartAddress
This variable is used by the Write-function and defines the target-address in the upper Flash-ROM-
block, where writing data from the RAM-buffer is started; any value from 0x7800 onwards to 0xEE00
minus SPNoByte is valid.
• SPNoByte
For the Write-Function, this value defines the number of bytes to be written into the Flash-Memory
starting from SPWriteStartAdr onwards. Valid values are from 1 to 256.
• SPBuffStartAddress
Defines the Start-address of the RAM-buffer. This RAM-buffer contains the data for the write-routine
and is used by the Area_Verify-routine, too.
• SwapRetAdr
This address defines the starting-address of the new program, which will be called after the upper and
the lower block were swapped; please remember that this must not be the address the microcontroller
jumps to after executing the RESET-procedure.
While the Swap is executed, the signature of the upper block is written and the signature of the lower
block is destroyed, so that after a RESET-Function is released, the old upper-block retains his new
lower-position and the new program is executed by taking the new start-vector at address 0000.
Output-Parameter
Error-Flag
All functions will return the same parameter, but with different values. The different values are worked
within the SP-library, but errors, which are not re-workable will be directed to the calling program. The
error-codes are listed in the following:
• Parameter-Error: This error is defined, if some of the values, defined in the Entry-RAM-Area, are not
compatible to the function-execution, e.g. Block-No != 1 or write 20 Bytes to 0xEDF0.
• Verify-Error: This error is defined when internal verification of written data is not executed correctly.
• Write-Error: If the data from RAM to Flash-ROM cannot be written correctly, this error will be shown.
• OverErase-Error: This error is returned if any cell is overerased. This could happen in following
cases:
- erasing takes too long
- erased cells are erased again
- cells, programmed with FF, (equals to never programmed), are erased.
The last two cases can be avoided by using the prewrite-function before each erase-function call.
Depending of the over-erase status of the cell, an over-erase error could be corrected by using the
WriteBack-function.
• BlankCheck-Error: If the internal Blank-Check finds non-blank memory-cells, this error-code is gen-
erated.
2.3.2 SP_Init
Like described in the above picture, the In- and Out-Parameters are as follows:
The function calls several firmware-routines to initialise and check the EntryRAM. If a RealTimeSup-
portFunction is requested by the input-parameter, the RTSF-function is automatically called within the
used firmware-routines.
Default values out of the Firmware-ROM, that are based on an 8MHz clock are written into the Entry-
RAM-Area. These are 50 µsec, 2 sec and 10 msec for the three parameters write-, erase- and conver-
sion-time.
After setting these values and testing if the settings are in a defined range, a return-value is created and
the function is ended.
If the values written by the SP_Init-function doesn’t fit into users need, they must be rewritten manually.
With the given start-address and the offset from chapter “The Entry-RAM” o n page7, all recent values
can be changed.
The Start-Address of Entry-RAM must be defined in the.xcl-file, because all library-functions use this
address to get data out of the Entry-RAM and start the Flash-Programming!
This can be done, if the standardized values, written into the Entry-RAM by the library-Initilization, don’t
fit into the users special needs.
2.3.3 SP_Erase
The Erase-function is the most complex function of the library-set. The only input-parameter needed is
the RTSF-usage-value.
The output-parameter will give information about the status of Flash-block-Erasing. Between the calling
and the ending of the erase-function, several options are calculated in the Erase-function itself. A short
overview should give the user an introduction what the Erase-function will do internal:
First of all, a blank-Check is done to determine, whether the ROM-block to be flashed is already empty
or not.
If the Area is blank, the erase-function is finished with no-error. If there are non-blanked cells, the Pre-
Writing of the area is initiated. This Pre-Writing should preserve the ROM-Area from OverErase-Errors
by writing 0x00 to all cells.
After this Pre-Write is done, the full upper ROM-Area will be erased. To get a fast time for erasing and a
minimum stress for the flash-block the erasing is done in an iterative way. Between each step, an
erase-success is checked by a blank-check.
While the first Erase-cycle is not successful, the writing-parameters are changed to the shorter repeti-
tive values to start the next erase-iteration.
In case of OverErasing, the SP_Erase-subroutine will write-Back the FlashROM. This means, that the
write-back-function tries to repair the over-erased cell by kind of special writing.
The SP_Erase-function will be ended either by successful Blank-Check or reaching the maximum
erase- or conversion-time. By reaching the maximum times an error-code is returned.
2.3.4 SP_Write
As described in the above header-file, this function uses more than just the RTSF-input-parameters:
Input-parameters: output-parameters:
SP_WriteStartAddress: Sets address where in RB3_B: error-code stored in register B of Bank 3
ROM data-writing should be started
SPNoByte: Defines the number of Bytes to write Write-error: Writing to at least one bit was not successful.
in ROM Parameter Error: WriteStartAdr + SPNoByte exceeds write-
SPBuffStartAdr: Declares the start-address able Flash-Area
where data in RAM resides
_RTSF_Adr: 0x0000 when no RTSF-support is
needed
The SP_Write-function fetches data from pre-defined RAM-area and writes it into the upper Flash-Block
at starting address, defined while the function is called.
If the RTSF-support is requested, the start-address of the RTSF-support-function is written to the
according Entry-RAM-Bytes.
With the input-parameters, the EntryRAM-values Flash Memory Start-Address, No. of bytes written in
flash-memory and WriteData_StoragBuffer_StartAddress are declared.
The write-Time, used for the write-in of data, is calculated as described in the following formula:
With an operating-Frequency of 8 MHz and a Data1 of 200, the basic WriteTime will amount to 50 µsec.
2.3.5 SP_AreaVerify
The Verify-function needs also more than one calling-parameter. The ROM-address, where the temp-
data will be written to, is still defined.
Input-parameters: output-parameters:
SP_BuffStartAdr: Sets address of RAM-buffer RB3_B: error-code stored in register B of Bank 3
where temporarily data is stored
_RTSF_Adr: 0x0000 when no RTSF-support is
needed
The verification of the whole Flash-Area is done by this function. The input-parameter SP_BuffStartAdr
is copied into EntryRAM-Area to the WriteDataStorageStartAdr.
The firmware-routine does a byte-to-byte-compare of the whole Flash-block in 256-Byte-steps. There-
fore, the RAM-buffer is used to copy the data out of the Flash into the RAM and do the comparison. If
the check wasn’t successful, an error is generated and the test is ended.
Please take care, that the writing of the data and the AreaVerify shouldn’t go apart to long. A successful
test will guarantee a data-security of 10 years.
2.3.6 SP_Swap
The Swap-function should be called after all needed data is written from RAM to Flash, so a full-fea-
tured program is located in the upper memory-block. This following, the upper- and the lower block must
be switched, so the former lower-block can be erased and written to access the whole Flash-ROM-
Area.
Input-parameters: output-parameters:
SwapRetAdr: Sets address where program coun- RB3_B: error-code stored in register B of Bank 3
ter after swap has to point to
_RTSF_Adr: 0x0000 when no RTSF-support is
needed
If the Swap is executed, the program counter is set to the SwapReturnAddress at leaving the firmware-
routine. The starting-address of the related program should be located here.
In case of error while executing the Swap-function (e.g. losing the VPP), following figure declares, which
ROM-block will actual be the upper ROM-block:
Swap-function execution
Error occurs whil
Swap withou executing Swap-
error between
any erro Error before routine
setting new sig-
changing
nature and des-
the signature
troing old one
old block
old upper Flash-block =
p h y s . b lo c k
1 w ill b e
is new code-Flash-block new block b o o t - b lo c k
To guide the user by programming the Flash-Device with the on-chip Secure Self-Programming, a sam-
ple programming-sequence is shown.
First of all, the linker-file should be configured to specify the used RAM and Flash-Areas.
//-------------------------------------------------------------------------------------------
// -LINK.XCL
//
// XLINK command file to be used with the 78000 Embedded Workbenc
// using procesor option -v1 memory model option -ms or -mS.
//
//-------------------------------------------------------------------------------------------
// Archived: $Revision: 1.1 $
// (c) Copyright IAR Systems 1997
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
// changes for Secure SelfProgramming
// (C) NEC Electronics (Germany) GmbH 2000
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
// Define CPU.
//-------------------------------------------------------------------------------------------
-c78000
//-------------------------------------------------------------------------------------------
// Define all user-specific RAM-areas for Secure SelfProgramming
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
// Define all other Self-Programming related stuff
//-------------------------------------------------------------------------------------------
• Ucode: Area, where the User-code used for the RTSF-support-function will reside. Not only in this
example, this Area should be from 0xF000 to max. 0xF5FF.
• MySegER: Area which includes the Entry-RAM-Area; the example defines this from 0xFE21 to
0xFE43
• MySegRB: This Area resides in RAM and stores the data read by a protocol like CAN. The example
sets this value from 0xF6E0 to 0xF7DF.
• USERCODE: By first programming, this area contains the data that will be copied as RTSF-user-
support function into the Ucode-Area.
• SWAPCODE: This area contains code which can be copied to the Flash and be called after both
Flash-blocks have been swapped.
To complete the example, the non-library-version of the MAIN.c-file is given; here certain values are
defined for the CAN-ASSP3, which should be carried by the user to guarantee Self-Programming-func-
tionality:
The SP_lib.h file is part of the library, the SP_API.h-file is delivered with the library; herein are defined
values which can be changed to fit into users needs.
The used registers should be set in a way like shown above to provide the user with the needed RAM,
Flash and system frequency.
Following this, the Self-Programming functions are called in the described way. Please note, that there
are only 128 bytes copied for this example; that wouldn’t be enough to support further Self-Program-
ming-functions!
• Be sure that the data to be programmed in the formerly blanked Flash-block is located in the RAM-
Buffer
• Program the now new upper-block with data from RAM-Buffer with steps described above.
As description, the following flowchart gives an overview how to program the Flash-ROM:
After the declaration is done, the user-program should define a protocol which can carry the data into
the MySegRB-Area in blocks of 256 Byte.
When the area is filled, the Self-Programming mode has to be entered by calling the belonging SP-Rou-
tines.
First, the steps A to E in the above given Flowchart are executed to get a fully programmed upper
Flash-memory-block. With swapping both blocks, the new upper-block can be programmed.
Please remember, that a boot loader, containing the library for Self-Programming, has to be
included in the new-programmed application for future Self-Programming.
The following sequence shows the monitor of the flash-master, connected to a PCvia any Terminal-pro-
gram:
Using this sequence, the device can be programmed with the Flash-Master as easy as with the On-
Chip Secure Self-Programming-functions.
• Documentation
Version Description
V 1.0 Initial Documentation
• Self-Programming Library
Version Description
V 1.0 Initial Library-release
Description Name
Header-file with API-Information SP_API.h
library-file with described library-functions to use with 78F0828b SP_lib.r26
Emulation-library emulator.r26
Device-file for 78F0828b Df0828b.h
Sample Link-file for use with the IAR-workbench SP_Lnk.xc
library with outsourced standard-library-calls SP_l06fit
Tel. FAX
Address
North America Hong Kong, Philippines, Oceania Asian Nations except Philippines
NEC Electronics Inc. NEC Electronics Hong Kong Ltd. NEC Electronics Singapore Pte. Ltd.
Corporate Communications Dept. Fax: +852-2886-9022/9044 Fax: +65-250-3583
Fax: 1-800-729-9288
1-408-588-6130
Korea Japan
Europe
NEC Electronics Hong Kong Ltd. NEC Semiconductor Technical Hotline
NEC Electronics (Europe) GmbH
Seoul Branch Fax: 044-548-7900
Technical Documentation Dept.
Fax: 02-528-4411
Fax: +49-211-6503-274
South America Taiwan
NEC do Brasil S.A. NEC Electronics Taiwan Ltd.
Fax: +55-11-6465-6829 Fax: 02-2719-5951
Document title: