Title: Flash!
1Flash!
2CPU Rewrite
- CPU-rewrite is a term that refers to an Renesas
MCUs 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.
3EW0 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.
4Block 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)
5Block 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 01, 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.
6ROM 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)
7ROM Code Protect
ROM Code Protect Register
ROMCP
Taken from the M16C/26 Hardware Manual!
8.
9Flash 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.
10R8C 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 dont 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.
11Flash 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 - EW0 only
M32C/85,/87 HNDc WORD A,1 (4k each) Lock -
- EW0 and EW1 Mode
- 7 Byte Serial ID code
- ROM Code Protection
- FoUSB Programming
ALL
12Simple 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
13Flash 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
SKPs.
14Flash 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)
15Flash 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
16Flash API Setup
- You can also set up the defines within HEW.
17Flash 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
18New 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
wasnt blank. - Improve reliability in loss of power situations
- Allow for multiple and uniquely sized data to be
stored
19Virtual 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.
20Virtual 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
21Virtual 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
22Virtual 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
23Virtual EEPROM (Fixed Method)
- To change one or more bytes, user application
must read the SEGMENT array into a RAM buffer,
modify, then write back.
Virtual EEPROM
Buffer in RAM
VirEE Read
1133 2345 8800 0000 0000
5 WORD array
VirEE Write
1133 2369 8800 0000 0000
24Virtual EEPROM (Multiple/Variable Method)
- The user may have multiple records (segments) of
variable length that may be modified individually.
Virtual EEPROM
User assigned record label (0-254)
7
24
data
data
1
10
254
17
data
Size in WORDs -1 (1-255)
data
5
50
User data for that record
25Virtual EEPROM Example
include virtEE_Variable.h typedef struct
unsigned char record_label / 0x00 to 0xFE /
unsigned char data_size / number of WORDS
- 1/ unsigned int NV_FAR pData / pointer
to data / NV_type void main(void)
NV_type EE_data / Read Record 1 /
EE_data.record_label 1 NV_Read( EE_data
) value EE_data.pData0 / Write
Record 5 / EE_data.record_label 5
EE_data.pData0 55 EE_data.pData1 22
EE_data.data_size 2 NV_Write( EE_data
)
26Continue in Lab 5