User`s manual
RX600 & RX200 Series Simple Flash API for RX
R01AN0544EU0250 Rev.2.50 Page 20 of 33
March 4, 2014
4.2 R_FlashErase
This function allows an entire flash block to be erased.
Format
uint8_t R_FlashErase(uint32_t block);
Parameters
block
Specifies the block to erase. This value is defined in the r_flash_api_rx_if.h file. The blocks are labeled
in the same fashion as they are in the device’s Hardware Manual. For example, on the RX610 the
block located at address 0xFFFFE000 is called Block 0 in the hardware manual therefore “BLOCK_0”
should be passed for this parameter.
Return Values
FLASH_SUCCESS: Operation successful (if BGO is enabled this means the operations was started
successfully)
FLASH_FAILURE: Operation failed.
FLASH_BUSY: Other flash operation in progress, try again later
Properties
Prototyped in file “r_flash_api_rx_if.h”
Implemented in file “r_flash_api_rx.c”
Description
Erases a single block of flash memory. Starting with RX63x MCUs some RX MCUs now have much smaller
erase blocks for the data flash. For example, the RX630, RX631, and RX63N have 32 byte erase blocks.
This means that that for a 32KB data flash there are 1024 blocks. Instead of having a definition for each
block (e.g. BLOCK_DB0, BLOCK_DB1, …, BLOCK_DB1023) data flash blocks were grouped into 2KB
virtual blocks. Each virtual block therefore consists of 64 real data flash blocks. This was done to make it
easier on users to delete larger regions of data flash as has been done in the past. Users still have the
option of deleting with 32 byte granularity using the R_FlashEraseRange() function.
Reentrant
No, but is protected by lock to prevent errors from concurrent function calls.
Example
uint32_t loop;
uint8_t ret;
/* Search for record */
for (loop = 0; loop < NUM_BLOCKS_TO_ERASE; loop++)
{
/* Erase block */
ret = R_FlashErase(loop);
/* Check for errors. */
if (FLASH_SUCCESS != ret)
{
. . .
}
}
Special Notes:
Do not attempt to erase a flash block that you are currently executing from. If you are erasing a data flash
block then make sure you have enabled modifications of the data flash block by calling the
R_FlashDataAreaAccess() function.