Document 7175156

Download Report

Transcript Document 7175156

Flash!
Renesas Technology America, Inc.
CPU Rewrite
• CPU-rewrite is a term that refers to an
Renesas MCU’s ability to erase/program its
own internal Flash in circuit.
• R8C is BYTE programmable, where current
M16C and M32C devices are WORD
programmable.
• Old M16C/M32C devices were 256byte
programmable.
• In order to erase any data, the ENTIRE block
must be erase.
Renesas Technology America, Inc.
EW0 vs. EW1 Mode
• HNDc Flash devices can perform Flash
operations using either EW0 or EW1 Mode.
• EW0 Mode: CPU-rewrite Code must be
executed out of RAM and the Flash register
polled for operation completion.
• EW1 Mode: CPU-rewrite Code is run out of
Flash (just not in the same block as target
block) and the CPU is kept in HOLD state
until operation completion.
Renesas Technology America, Inc.
Block LOCK bit
•
•
•
•
•
Hardware mechanism to protect Flash blocks from
accidentally be erased/programmed.
Only on older DINOR, HNDa,b Flash devices
(M16C/62P,/6N, M32C/83,/85)
Once a block is locked, it remains that way (even
through resets) until it is erased.
To erase a locked block requires and extra step in
software which disables ALL lock bit settings.
There are 2 Flash erase commands for this type of
Flash:
– Erase Block (can be used to override lock bit settings)
– Erase All unlocked blocks. (can never erase a locked block)
Renesas Technology America, Inc.
Block PROTECT bits
•
•
•
•
•
•
Hardware mechanism to protect Flash blocks from
accidentally be erased/programmed.
Will be used for all new devices (R8C, M16C, M32C)
Typically, there are only 2 bits (4 settings) for all the
Flash Blocks in the device. Therefore, blocks are
grouped (ie, Block 0&1, All other user blocks)
Data Flash is never protected.
Since the protect bits are SET every time you enter
CPU-rewrite mode, an extra software step is required
to remove protection to certain blocks.
The Protect bits reside in the Flash registers.
Renesas Technology America, Inc.
ROM Code Protect
• Disables Flash memory from being read out
by a parallel programmer.
• The ROMCP register always resides in the
last byte of Flash (0xFFFFF or 0xFFFFFF)
• Once set, user can only access flash via
serial boot mode (which has a 7-byte ID code
protection – next page)
Renesas Technology America, Inc.
ROM Code Protect
ROM
Code
Protect
Register
ROMCP
*Taken from the M16C/26 Hardware Manual!
Renesas Technology America, Inc.
.
Renesas Technology America, Inc.
Flash Suspend
•
•
•
Flash writes are fast, erases are slow. The bigger the
Flash block, the longer the operation will take.
Some newer devices have an Erase Suspend option
that will allow you to postpone an erase operation and
leave CPU-rewrite mode before it has completed (for
example in order to service an interrupt). You can then
go back into CPU-rewrite mode later and continue the
erase.
The HNDe Flash type improves the flash
suspend response time (from 8ms to 90us).
The first device to have HNDe will be R8C/20
Series.
Renesas Technology America, Inc.
R8C Flash
• R8C/12 -17 has a Watchdog register at
address 0xFFFF. If that address programmed
to 00 (by default of NC30 compiler startup file),
then the watchdog will start firing automatically
after reset and interfere with CPU-rewrite
operations that don’t account for this.
• The FlashAPI source code does not “pet” the
watchdog. Therefore, you must set address
FFFF to FF in your R8C startup file.
Renesas Technology America, Inc.
Flash Lookup Table
MCU
TYPE
Write
Data Flash
Lock/Protect
Suspend
Notes
R8C/10,11,14,16
HNDc
BYTE
-
Protect
Yes
W-Dog INTR
R8C/12,13
HNDc
BYTE
A,B (2k each)
Protect
Yes
W-Dog INTR
R8C/15,17
HNDc
BYTE
A,B (1k each)
Protect
Yes
W-Dog INTR
M16C/26
HNDc
WORD
A,B (2k each)
Protect
Yes
only 1 protect bit
M16C/26A,28,29
HNDc
WORD
A,B (2k each)
Protect
Yes
M16C/62P,6N
HNDc
WORD
A,1 (4k each)
Lock
-
M32C/83
DINOR
256 BYTE
-
Lock
-
M32C/85,/87
HNDc
WORD
A,1 (4k each)
Lock
-
ALL:
• EW0 and EW1 Mode
• ROM Code Protection
• 7 Byte Serial ID code
• FoUSB Programming
Renesas Technology America, Inc.
EW0 only
Simple Flash API
•
•
R8C, M16C and M32C MCUs
with HNDc type Flash are
similar enough to create one
API source file for all of them.
Current supported devices are
listed to the right.
R8C
M16C
M32C
R8C/10
M16C/1N2
M32C/83
R8C/11
M16C/26
M32C/84
R8C/12
M16C/26A
M32C/85
R8C/13
M16C/28
R8C/14
M16C/29
R8C/15
M16C/62P
R8C/16
M16C/6N4
R8C/17
M16C/6N5
Renesas Technology America, Inc.
Flash API Files
•
•
•
•
There are only 2 files for the API:
Flash_API.c
Flash_API.h
There is a very simple sample program that works with
all the supported MCU:
FlashAPI_Sample.c
There is an appnote for using this API:
REU05B0058-2_Simple_Flash_API.pdf
A Hew project using these files comes with the SKP’s.
Renesas Technology America, Inc.
Flash API Functions
•
There are only 2 functions in the API
unsigned char FlashErase( unsigned char block );
unsigned char FlashWrite( FLASH_PTR_TYPE flash_addr,
BUF_PTR_TYPE buffer_addr,
unsigned int bytes)
•
•
The acceptable values for “block” in FlashErase are
listed in FlashAPI.h (BLOCK_0, BLOCK_1, etc…)
The types FLASH_PTR_TYPE and BUF_PTR_TYPE in
FlashWrite are memory pointers. The have to be defined
this way in order to deal with the different memory
models between the R8C, M16C and M32C.
success = FlashErase( BLOCK_A );
Success = FlashWrite((FLASH_PTR_TYPE)0xF000,
(BUF_PTR_TYPE) “hello”,
6);
Renesas Technology America, Inc.
Flash API Setup
•
You must define the MCU you are using. The list of valid devices are
at the top of the file Flash_API.h.
#define M16C_62P 1
#define R8C_13 0
•
You must define the Flash Mode you want to use. Mode 0 sends
flash command while running from RAM. Mode 1 sends command
while running in Flash.
#define EW_MODE 0
#define EW_MODE 1
•
You must define the Bus Clock Frequncy (BCLK) you are running at.
This is used to determine how much to slow the MCU down when
sending commands to the flash controller.
#define BCLK_FREQUENCY 20000000
Renesas Technology America, Inc.
Flash API Setup
You can also set up the #defines within HEW.
Renesas Technology America, Inc.
Flash API Setup
• There are 3 things that must be #defined
before using API. They are all listed in the
file Flash_API.h.
• If something is not defined, the
compiler will stop and print out
a message.
C:\FlashAPI\Flash_API.h 179 Error "You must specify your device in Flash_API.h first!!"
C:\FlashAPI\Flash_API.c
Phase M16C C Compiler finished
Renesas Technology America, Inc.
New Virtual EEPROM APIs
• The Virtual EEPROM software was created to:
– Fix design bugs in the initial release
– Use the new Flash API code
– Account for writing into a Flash space that wasn’t
blank.
– Improve reliability in loss of power situations
– Allow for multiple and uniquely sized data to be stored
Renesas Technology America, Inc.
Virtual EEPROM
The Renesas Virtual EEPROM solution is a
software implementation utilizing the two
high Erase-Write cycle Flash blocks.
• The concept is not to erase a flash block every time
stored data needs to be changed. Instead, write the new
data to another un-programmed location within that flash
block until the entire block has been filled.
• Reducing the number of erase cycles of a block better
utilizes and extends the life of the Flash.
Renesas Technology America, Inc.
Virtual EEPROM
• The virtual EEPROM API uses the Flash API in
order to erase/program the Data Flash areas of
the MCU
User Code
Virtual EEPROM API
Flash API
Data Flash Data Flash
Renesas Technology America, Inc.
Virtual EEPROM
• All new R8C, M16C and M32C MCUs come with two
Flash blocks with 10,000 erase/write cycle.
• 10,000 E/W versions have special Option codes
(#D7,#D9)
M16C/62P
BLOCKS A & 1
4KB each
M16C/Tiny Series (2x)
BLOCKS A & B
2KB each
R8C 12,13
BLOCKS A & B
2KB each
R8C 15,17
BLOCKS A & B
1KB each
M32C/85
BLOCKS A & 1
4KB each
Renesas Technology America, Inc.
Virtual EEPROM (Fixed Method)
• The user has a single fixed amount of data that
can be stored referred to a a SEGMENT.
• All the bytes in the SEGMENT must be modified
at the same time.
Virtual EEPROM
5 WORD array
SEGMENT SIZE = 5
Renesas Technology America, Inc.
Virtual EEPROM (Fixed Method)
• To change one or more bytes, user application
must read the SEGMENT array into a RAM
buffer, modify, then write back.
Buffer in RAM
VirEE Read
1133 2345 8800 0000 0000
Virtual EEPROM
5 WORD array
VirEE Write
1133 2369 8800 0000 0000
Renesas Technology America, Inc.
Virtual EEPROM (Multiple/Variable Method)
• The user may have multiple records (segments)
of variable length that may be modified
individually.
User assigned
record label (0-254)
Virtual EEPROM
7
1
24
data
data
10
254
Size in WORDs -1
(1-255)
5
50
17
data
User data for
that record
Renesas Technology America, Inc.
data
Virtual EEPROM Example
#include “virtEE_Variable.h”
typedef struct {
unsigned char record_label;
unsigned char data_size;
unsigned int NV_FAR *pData;
} NV_type;
/* 0x00 to 0xFE */
/* number of WORDS - 1*/
/* pointer to data */
void main(void)
{
NV_type EE_data;
/* Read Record 1 */
EE_data.record_label = 1;
NV_Read( &EE_data );
value = EE_data.pData[0];
/* Write Record 5 */
EE_data.record_label = 5;
EE_data.pData[0] = 55;
EE_data.pData[1] = 22;
EE_data.data_size = 2;
NV_Write( &EE_data );
Renesas Technology America, Inc.
Continue in Lab 5
Renesas Technology America, Inc.