APPLICATION NOTE RX600 & RX200 Series Simple Flash API for RX R01AN0544EU0250 Rev.2.50 March 4, 2014 Introduction A simple Application Program Interface (API) has been created to allow users of flash based RX600 & RX200 Series devices to easily integrate reprogramming abilities into their applications using User Mode programming. User Mode programming is the term used to describe a Renesas MCU's ability to reprogram its own internal flash memory while running in its normal operational mode.
RX600 & RX200 Series Simple Flash API for RX 1. Overview The Simple Flash API is provided to customers to make the process of programming and erasing on-chip flash areas easier. Both ROM and data flash areas are supported. The API in its simplest form can be used to perform blocking erase and program operations. The term ‘blocking’ means that when a program or erase function is called, the function does not return until the operation has finished.
RX600 & RX200 Series Simple Flash API for RX 2. API Information This Middleware API follows the Renesas API naming standards. 2.1 Hardware Requirements This middleware requires your MCU support the following features: • Flash with background operation feature (all RX600 & RX200 Series MCUs feature this) • Clock speed supplied to Flash Control Unit must be greater than or equal to 4MHz 2.2 Hardware Resource Requirements This section details the hardware peripherals that this middleware requires.
RX600 & RX200 Series Simple Flash API for RX FLASH_API_RX_CFG_DATA_FLASH_BGO Enables non-blocking data flash operations. When enabled, data flash operations will occur in the background and API functions will return before the operation has finished. When disabled API functions will not return until the data flash operation has completed. FLASH_API_RX_CFG_ROM_BGO Enables non-blocking ROM operations.
RX600 & RX200 Series Simple Flash API for RX the backup PSW register. The downside to this approach is that the user loses the ability to use the fast interrupt for another interrupt. 2.8 API Data Structures This section details the data structures that are used with the middleware’s API functions. 2.8.1 Flash Block Addresses If needed, the user can use the g_flash_BlockAddresses[] array to get the addresses associated with a MCU’s memory blocks.
RX600 & RX200 Series 2.10 Simple Flash API for RX Adding Middleware to Your Project Follow the steps below to add the middleware’s code to your project. 1. 2. 3. 4. 5. 6. 7. Copy the ‘r_flash_api_rx’ directory (packaged with this application note) to your project directory. Add src\r_flash_api_rx.c to your project. Add an include path to the 'r_flash_api_rx' directory. Add an include path to the 'r_flash_api_rx\src' directory. Copy the reference configuration file 'r_flash_api_rx_config_reference.
RX600 & RX200 Series MCU Simple Flash API for RX Configuration 1 RX63N 512KB ROM 2 3 1 RX62N 512KB ROM 2 3 1 RX210B 1MB ROM 2 3 1 RX220 256KB ROM 2 3 Toolchain ROM (Bytes) RAM (Bytes) RXC v1.02.01 2638 1505 RXC v2.00.00 2292 1276 RXC v1.02.01 3092 148 RXC v2.00.00 2675 148 RXC v1.02.01 3702 2237 RXC v2.00.00 3218 1946 RXC v1.02.01 2214 1209 RXC v2.00.00 1894 1002 RXC v1.02.01 2657 276 RXC v2.00.00 2284 276 RXC v1.02.01 3204 2050 RXC v2.00.
RX600 & RX200 Series 2.13 Simple Flash API for RX Putting Flash API Code in RAM RX600 & RX200 Series MCUs require that sections in RAM and ROM be created to hold the API functions for reprogramming ROM. This is required because the FCU cannot program or erase ROM while executing or reading from ROM. Also, the RAM section will need to be initialized after reset. Note that this is only for ROM programming.
RX600 & RX200 Series Simple Flash API for RX 3. Add the linker option to map the ROM section (PFRAM) address to RAM section address (RPFRAM) as seen below. 4. The linker is now setup to correctly allocate the appropriate Flash API code to RAM. Now we need to make sure that the code gets copied from ROM to RAM after reset. If this is not done before a Flash API function is called then the MCU will jump to uninitialized RAM. Two ways to copy this code to RAM are presented below.
RX600 & RX200 Series Simple Flash API for RX In e2 studio: The same process of setting up the linker sections and mapping ROM to RAM needs to be done in e2 studio as well. 1. Add a new section titled ‘RPFRAM’ in a RAM area. 2. Add a new section titled ‘PFRAM’ in a ROM area. 3. To make the linker map the PFRAM ROM section to the RPFRAM RAM section a new entry must be added to the ‘ROM to RAM mapped section’ table. This is done using the Linker >> Output section of the Tool Settings in e2 studio.
RX600 & RX200 Series 2.14 Simple Flash API for RX Using Non-Blocking Background Operations When background operations (BGO) for ROM or data flash are enabled, API function calls will not block and will return before the flash operation has finished. The user should take care in these instances that they do not try to access the flash area that is being operated on until the operation has finished.
RX600 & RX200 Series Simple Flash API for RX 3. Usage Notes 3.1 Debugging within HEW Using the E1, E20 and J-Link, you are allowed to debug while erasing and programming the on board flash memory and data flash memory. Care should be taken to make sure that the flash block holding the user program is not erased unless the user has some way of programming new code while executing in RAM.
RX600 & RX200 Series Simple Flash API for RX In e2 studio: This is done in the ‘Debug Configurations’ window which is accessed by selecting your project and clicking ‘Run >> Debug Configurations’. Select your debug configuration and then select the ‘Debugger’ tab. Now click the ‘Debug Tool Settings’ tab and click the box at the end of the row which contains ‘Internal Flash Memory Overwrite’.
RX600 & RX200 Series 3.2 Simple Flash API for RX Viewing Programmed/Erased Flash Memory in HEW Use of the Memory window inside HEW or e2 studio to view the flash memory contents after an erase or write will not work under the default debugger settings. The reason for this is that the IDE will cache the flash memory contents when the debug session starts and will not refresh the values after the program/erase command finishes.
RX600 & RX200 Series Simple Flash API for RX In e2 studio: This is done in the ‘Debug Configurations’ window which is accessed by selecting your project and clicking ‘Run >> Debug Configurations’. Select your debug configuration and then select the ‘Debugger’ tab. Now click the ‘Debug Tool Settings’ tab and locate the ‘Program re-writes internal Program ROM’ and ‘Program re-writes internal Data Flash’ rows.
RX600 & RX200 Series 3.6 Simple Flash API for RX Interrupts ROM or data flash areas cannot be accessed while a flash operation is on-going for that particular memory area. This means that care will need to be taken when allowing interrupts to occur during flash operations. These precautions apply whether the user is using BGO operations or not. 3.7 Configure for Only Data Flash Use The Flash API can be configured to only enable data flash operations.
RX600 & RX200 Series 3.11 Simple Flash API for RX Putting Flash API in User Boot Area By default, the Renesas RX Toolchain will use 24 bits for the maximum distance that a branch instruction can jump to. The options are 16, 24, or 32 bits. The smaller the chosen value, the smaller the compiled code will be.
RX600 & RX200 Series 3.12 Simple Flash API for RX Execute from Data Flash A common question is if the MCU can execute code from the data flash. The answer is yes, but performance will be degraded. The reason for this is that the MCU can access ROM in a single cycle using the same clock that is used for the CPU (ICLK) while the data flash is accessed using the FCLK (or PCLK on RX610 and RX62x MCUs). In many cases the FCLK will be less than the ICLK which will lead to read delays.
RX600 & RX200 Series Simple Flash API for RX 4. API Functions 4.1 Summary The following functions are included in this API: Function Description R_FlashErase() Erases an entire flash block. R_FlashEraseRange() Erases a range of addresses. Erases at least 1 flash block. R_FlashWrite() Write data to ROM or data flash. R_FlashDataAreaAccess() Enable read, write, erase access to data flash. R_FlashDataAreaBlankCheck() Check if a data flash address (or block) is erased.
RX600 & RX200 Series 4.2 Simple Flash API for RX 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.
RX600 & RX200 Series 4.3 Simple Flash API for RX R_FlashEraseRange (Not Available on RX610, RX62x) The function starts erasing data flash blocks at a given address and stops when the number of bytes to erase has been reached. Format uint8_t R_FlashEraseRange(uint32_t start_addr, uint32_t bytes); Parameters start_addr Specifies the address where the erase should begin. This must be on an erase boundary and the address must be in the data flash area. bytes Specifies the number of bytes to erase.
RX600 & RX200 Series 4.4 Simple Flash API for RX R_FlashWrite This function allows data to be written into flash. Format uint8_t R_FlashWrite(uint32_t uint32_t uint16_t flash_addr, buffer_addr, bytes); Parameters flash_addr This is a pointer to the Flash or Data Flash area to write. The address must be on a programming line boundary. See Description below for important restrictions regarding this parameter. buffer_addr This is a pointer to the buffer containing the data to write to Flash.
RX600 & RX200 Series Simple Flash API for RX Example uint8_t ret; uint8_t write_buffer[PROGRAM_SIZE] = “Hello World...”; /* Write data to internal memory. */ ret = R_FlashWrite(address, (uint32_t)write_buffer, PROGRAM_SIZE); /* Check for errors. */ if (FLASH_SUCCESS != ret) { . . . } Special Notes: The programming sizes for different RX MCUs are shown in the table below.
RX600 & RX200 Series 4.5 Simple Flash API for RX R_FlashDataAreaAccess This function allows Data Flash areas to be accessed or modified. The data flash cannot be read, written, or erased before calling this function. Format void R_FlashDataAreaAccess(uint16_t read_en_mask, uint16_t write_en_mask); Parameters read_en_mask This is a bitmapped value where bits are used to determine which Data blocks should be able to be read by the MCU.
RX600 & RX200 Series 4.6 Simple Flash API for RX R_FlashDataAreaBlankCheck This function is used to determine if an area in the Data Flash area is blank or not, since this cannot be determined by simply reading the memory location. This function is required because the user cannot read data flash locations and check they are blank by comparing them to 0xFF. Format uint8_t R_FlashDataAreaBlankCheck(uint32_t address, uint8_t size); Parameters address The address of the area to blank check.
RX600 & RX200 Series Simple Flash API for RX Example uint8_t ret; /* Blank check an entire data flash block. */ ret = R_FlashDataAreaBlankCheck(address, BLANK_CHECK_ENTIRE_BLOCK); /* Check result. */ if (FLASH_NOT_BLANK == ret) { /* Block is not blank. */ . . . } else if (FLASH_BLANK == ret) { /* Block is blank. */ . . . } Special Notes: The blank check sizes for different RX MCUs are shown in the table below.
RX600 & RX200 Series 4.7 Simple Flash API for RX R_FlashProgramLockBit Sets the lock bit for a flash block. Format uint8_t R_FlashProgramLockBit(uint32_t block); Parameters block The ROM erasure block that will have its lock bit set. Return Values FLASH_SUCCESS: FLASH_FAILURE: FLASH_BUSY: FLASH_ERROR_ADDRESS: Operation successful, lock bit set. Operation failed. Other flash operation in progress, try again later Invalid block was input. Properties Prototyped in file “r_flash_api_rx_if.
RX600 & RX200 Series 4.8 Simple Flash API for RX R_FlashReadLockBit Reads the lock bit for a flash block. Format uint8_t R_FlashReadLockBit(uint32_t block); Parameters block The ROM erasure block that will have its lock bit read. Return Values FLASH_LOCK_BIT_SET: Lock bit is set FLASH_LOCK_BIT_NOT_SET: Lock bit is not set FLASH_FAILURE: Operation Failed FLASH_BUSY: Another flash operation is in progress FLASH_ERROR_ADDRESS: Invalid block was input. Properties Prototyped in file “r_flash_api_rx_if.
RX600 & RX200 Series 4.9 Simple Flash API for RX R_FlashSetLockBitProtection Enables or disables lock bit protection. Format uint8_t R_FlashSetLockBitProtection(uint32_t lock_bit); Parameters lock_bit Boolean value that determines whether to enable or disable lock bit protection. If set to ‘true’ then lock bit protection will be enabled. If set to ‘false’ then lock bit protection will be disabled.
RX600 & RX200 Series 4.10 Simple Flash API for RX R_FlashGetStatus Returns the current state of the flash. Format uint8_t R_FlashGetStatus(void); Parameters None. Return Values FLASH_SUCCESS: FLASH_BUSY: Flash is ready to use Flash is busy with another operation Properties Prototyped in file “r_flash_api_rx_if.h” Implemented in file “r_flash_api_rx.c” Description This function will return the current state of the flash.
RX600 & RX200 Series 4.11 Simple Flash API for RX R_FlashCodeCopy Copies Flash API code from ROM to RAM. Format void R_FlashCodeCopy(void); Parameters None. Return Values None. Properties Prototyped in file “r_flash_api_rx_if.h” Implemented in file “r_flash_api_rx.c” Description When programming or erasing ROM the Flash API code cannot reside in ROM. This function will transfer the code from ROM to RAM. Reentrant Yes. Example /* Transfer Flash API code to RAM so that we can program/erase ROM.
RX600 & RX200 Series 4.12 Simple Flash API for RX R_FlashGetVersion Returns the current version of the Flash API. Format uint32_t R_FlashGetVersion(void); Parameters None. Return Values Version of Flash API. Properties Prototyped in file “r_flash_api_rx_if.h” Implemented in file “r_flash_api_rx.c” Description This function will return the version of the currently installed Flash API.
RX600 & RX200 Series Simple Flash API for RX Website and Support Renesas Electronics Website http://www.renesas.com/ Inquiries http://www.renesas.com/inquiry All trademarks and registered trademarks are the property of their respective owners. R01AN0544EU0250 Rev.2.
Revision Record Rev. 1.00 1.20 Date Jan.27.10 Feb.11.10 1.30 1.40 1.41 1.43 2.00 Mar.05.10 May.26.10 Jun.11.10 Feb.18.11 Apr.27.11 2.10 Jul.11.11 2.20 Dec.01.11 2.30 Sep.12.12 2.40 Dec.12.12 2.50 Mar.04.14 Description Page Summary — First edition issued — Made minor text revisions and added section on disabling interrupts.
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.
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 of these circuits, software, and information in the design of your equipment. Renesas Electronics assumes no responsibility for any losses incurred by you or third parties arising from the use of these circuits, software, or information. 2.