All About Circuits

Industry White Paper

Store Non-Volatile Application Data: Accessing Data Flash on the EK-RA8D1

Learn how to erase, blank-check, write, and verify on-chip data flash on the Renesas EK-RA8D1 using background operation in e² studio and the FSP flash driver.


November 19, 2026 by Renesas Electronics

Storing calibration constants, network credentials, or fault logs in SRAM works fine until your board loses power and every setting vanishes. Adding an external EEPROM chip solves the persistence problem, but it also adds bill-of-materials cost, board routing complexity, and serial bus latency. To save critical parameters directly on the microcontroller without stalling the processor during slow memory cycles, you can use on-chip data flash with background operation.

This walkthrough demonstrates how to erase, blank-check, write, and verify on-chip data flash on the Renesas EK-RA8D1 evaluation kit. Using the e² studio IDE, the Flexible Software Package (FSP), and the Renesas Flash Programmer utility, you will configure the High-Performance Flash driver (r_flash_hp) for asynchronous background execution, initialize the Arm TrustZone security state, program a 64-byte block of sequential data, and inspect the physical memory contents in real time.

 

Project Specs

Target Board EK-RA8D1
MCU Family Renesas RA8 Series (R7FA8D1BHECBD)
Peripheral Covered High-Performance Flash Memory (r_flash_hp)
IDE / Toolchain e² studio + LLVM Embedded Toolchain for Arm (21.1.1)
FSP Version 6.4.0
Interface Used SEGGER J-Link ARM Debugger and Renesas Flash Programmer V3.22.00
Baud Rate N/A (2 wire UART for device initialization / SWD for J-Link debugging)
Skill Level Intermediate
Build Time 25 minutes
Prerequisites e² studio installed, Renesas Flash Programmer V3.22.00 installed, EK-RA8D1 initialized

 

Why Does On-Chip Data Flash Matter on the EK-RA8D1?

In industrial human-machine interfaces, smart thermostats, and vision AI endpoints, firmware constantly needs to update small blocks of non-volatile data while the main application continues running. If a microcontroller only provides a single bank of code flash, erasing or writing a sector halts instruction fetches until the physical flash charge pumps finish their work. On a 480 MHz Arm Cortex-M85 processor like the Renesas RA8D1, stalling the CPU for several milliseconds during a flash erase cycle wastes millions of clock cycles and disrupts real-time control loops.

The Renesas RA family addresses this bottleneck by separating code flash from dedicated on-chip data flash and supporting Data Flash Background Operation (BGO). When BGO is enabled on the EK-RA8D1, the flash controller executes erase, blank check, and write commands asynchronously in hardware while the Cortex-M85 core continues executing application code from code flash. Once the background operation completes, the flash peripheral triggers a hardware interrupt that invokes your user-defined callback function, giving you non-blocking persistence for system parameters.

 

What You’ll Need

Hardware

 

Software

 

The Concept in 60 Seconds

Unlike standard RAM, flash memory cannot overwrite existing bytes directly. Before writing new values to a data flash block, you must first erase the block to reset all bits to their blank state, verify that the region is blank, and then program the new bytes. According to Figure 52.4 (Map of the Data Flash Memory) in the RA8D1 Group User’s Manual: Hardware, the data flash (Data area: 12 KB, which spans 24 KB of combined address space across its two security aliases) is partitioned into 64-byte blocks (Block 0 through Block 191), with each 64-byte block serving as a unit for erasure.

To support Armv8-M TrustZone security, the address space is mapped into a Secure alias starting at 0x2700_0000 and a Non-secure alias starting at 0x3700_0000. As shown in Section 43.3 Arm TrustZone (Figure 43.1 Transactions that can be issued by each master), a Secure master has permission to access both secure and non-secure memory regions, whereas a Non-secure master is restricted strictly to non-secure memory. However, a secure bus master can access only secure regions when communicating with a secure bus slave. When building a Flat (Non-TrustZone) Project, the CPU acts as a secure bus master. Initializing the EK-RA8D1 with Renesas Flash Programmer configures the entire data flash as a secure region, and disabling TrustZone boundary partitioning in the debugger allows your flat application to access 0x27000000U without triggering an access violation.

 

Step-by-Step: Building the Data Flash Project

Step 1: Create a Minimal Bare-Metal Project in e² studio

  1. Open e² studio, click File > New > Renesas C/C++ Project > Renesas RA, select Renesas RA C/C++ Project in the Templates for Renesas RA Project dialog, and click Next >.
  2. Type Data_Flash_RA8D1 into the Project name field and click Next >.
  3. In the Device and Tools Selection window (Figure 1), verify that FSP Version is 6.4.0 and select EK-RA8D1 from the Board drop-down menu, which automatically populates the R7FA8D1BHECBD device and CM85 core. Confirm C is selected as the language along with LLVM Embedded Toolchain for Arm (21.1.1) and J-Link ARM, then click Next >.

     

    The Device and Tools Selection window with FSP 6.4.0 and the EK-RA8D1 board selected. Choosing the board populates the R7FA8D1BHECBD device and CM85 core automatically.

    Figure 1. The Device and Tools Selection window with FSP 6.4.0 and the EK-RA8D1 board selected. Choosing the board populates the R7FA8D1BHECBD device and CM85 core automatically. Image used courtesy of Renesas

     

  4. Choose Flat (Non-TrustZone) Project and click Next >. Select None for the SmartBundle option and click Next >. Select Executable and No RTOS, click Next >, choose the Bare Metal - Minimal template, and click Finish. Click Open Perspective when prompted to open the FSP Configuration view.

Selecting a Flat (Non-TrustZone) Project with the Bare Metal - Minimal template configures the RA8D1 to run in a single security state with only the core board support package initialized.

 

Step 2: Add and Configure the High-Performance Flash Stack

  1. In the FSP Configuration perspective (configuration.xml), switch to the Stacks tab and click New Stack > Storage > Flash (r_flash_hp).
  2. Hover your cursor over the g_flash0 Flash (r_flash_hp) box to view the configuration error tooltip (Figure 2), which displays Error: Flash Interrupts must be enabled if Data Flash Background Operation is enabled, and Error: Callback must be provided if Data Flash Background Operation is enabled.

     

    The configuration error tooltip on the g_flash0 Flash (r_flash_hp) stack, listing the callback and flash interrupt requirements for Data Flash Background Operation.

    Figure 2. The configuration error tooltip on the g_flash0 Flash (r_flash_hp) stack, listing the callback and flash interrupt requirements for Data Flash Background Operation. Image used courtesy of Renesas

     

  3. Click the g_flash0 Flash (r_flash_hp) stack and open the Properties window. Confirm that Data Flash Programming Enable is set to Enabled and Data Flash Background Operation is set to Enabled.
  4. Set Callback to FLASH_CALLBACK, change Flash Ready Interrupt Priority to Priority 6, and change Flash Error Interrupt Priority to Priority 6 (Figure 3).

     

    The same stack after setting Callback to FLASH_CALLBACK and both flash interrupt priorities to Priority 6.

    Figure 3. The same stack after setting Callback to FLASH_CALLBACK and both flash interrupt priorities to Priority 6. Image used courtesy of Renesas

     

  5. Click Generate Project Content to save the configuration and generate the FSP driver files. In the Project Explorer, expand the src folder and open hal_entry.c (and expand Developer Assistance > HAL/Common > g_flash0 Flash (r_flash_hp) so the driver API calls are ready to drag and drop).

Providing the callback function name and interrupt priorities satisfies the BGO hardware requirements so the flash peripheral can signal the CPU asynchronously when background commands finish or encounter an error.

 

Step 3: Verify the Data Flash Memory Map and TrustZone Rules

  1. Open the RA8D1 Group User’s Manual (R01UH0995EJ0120) and search for Map of the Data Flash Memory to inspect manual Figure 52.4 in Section 52 (Flash Memory). Note that Block 0 (64 bytes) of the Secure alias starts at address 0x2700_0000 (Figure 4).

     

    Figure 52.4 of the RA8D1 Group User’s Manual: Hardware, showing Block 0 of the Secure alias at 0x2700_0000 and the 64-byte block geometry of the 12 KB data area.

    Figure 4. Figure 52.4 of the RA8D1 Group User’s Manual: Hardware, showing Block 0 of the Secure alias at 0x2700_0000 and the 64-byte block geometry of the 12 KB data area. Image used courtesy of Renesas

     

  2. Navigate to Section 43.3 Arm TrustZone (manual Figure 43.1, Transactions that can be issued by each master) to verify how the TrustZone Filter (TZF) and Implementation Defined Attribution Unit (IDAU/SAU) enforce bus access permissions between secure masters and slaves (Figure 5).

     

    Figure 43.1 of the hardware manual, showing which transactions each bus master can issue and where the TrustZone Filter raises an access violation.

    Figure 5. Figure 43.1 of the hardware manual, showing which transactions each bus master can issue and where the TrustZone Filter raises an access violation. Image used courtesy of Renesas

     

Checking the hardware manual confirms the exact base address (0x27000000U) and 64-byte block geometry required for your driver API calls.

 

Step 4: Define the Block Address Macro, Status Variables, and Flash Callback

  1. Return to hal_entry.c in e² studio. Below #include "hal_data.h", define the starting address macro for Data Flash Block 0:
    #define FLASH_DF_BLOCK_0 0x27000000U
  2. Directly below the macro, declare two global volatile variables to track interrupt status (hovering over flash_event_t in the editor displays the e_flash_event enumeration values returned by the interrupt service routine):
    volatile bool interrupt_called;
    volatile flash_event_t flash_event;
  3. In the Project Explorer, expand Developer Assistance > HAL/Common > g_flash0 Flash (r_flash_hp) and drag Callback function definition into hal_entry.c above void hal_entry(void).
  4. Inside FLASH_CALLBACK(flash_callback_args_t *p_args), set the flag and record the event:
    interrupt_called = true;
    flash_event = p_args->event;

Marking interrupt_called and flash_event as volatile ensures that the compiler reads their updated values from memory on every loop iteration rather than optimizing the polling loop away.

 

Step 5: Initialize the Source Buffer and Erase Data Flash Block 0

  1. Inside void hal_entry(void), declare the local variables: fsp_err_t err;, uint8_t g_src[64] = {0};, and flash_result_t blank_check_result;.
  2. Use a for loop with a uint32_t loop counter to initialize g_src with sequential values starting at 0x01: for(uint32_t i = 0; i < 64; i++) { g_src[i] = 0x01 + (uint8_t) i; }.
  3. From Developer Assistance, drag Call R_FLASH_HP_Open() into hal_entry() and add assert(FSP_SUCCESS == err);.
  4. Drag Call R_FLASH_HP_Erase() into hal_entry(), pass FLASH_DF_BLOCK_0 as the second argument and 1 as the third argument (err = R_FLASH_HP_Erase(&g_flash0_ctrl, FLASH_DF_BLOCK_0, 1);), and add assert(FSP_SUCCESS == err);.
  5. Wait for the BGO interrupt by adding while(!interrupt_called);, verify the event with assert(FLASH_EVENT_ERASE_COMPLETE == flash_event);, and clear the flag using interrupt_called = false;.

Waiting on interrupt_called and asserting FLASH_EVENT_ERASE_COMPLETE guarantees the physical erase cycle has finished in the background before you issue the next flash command.

 

Step 6: Blank-Check, Write the Buffer, and Compare Memory

  1. Drag Call R_FLASH_HP_BlankCheck() from Developer Assistance into hal_entry(). Add #define FLASH_DATA_BLOCK_SIZE 1024 at the top of hal_entry.c below FLASH_DF_BLOCK_0 to specify the 1,024-byte sector check size, and configure the call as err = R_FLASH_HP_BlankCheck(&g_flash0_ctrl, FLASH_DF_BLOCK_0, FLASH_DATA_BLOCK_SIZE, &blank_check_result);. Add assert(FSP_SUCCESS == err);, wait on while(!interrupt_called);, confirm the sector is blank with assert(FLASH_EVENT_BLANK == flash_event);, and reset interrupt_called = false;.
  2. Drag Call R_FLASH_HP_Write() into hal_entry(), cast g_src to a 32-bit address (uint32_t) g_src for the second argument, set the destination to FLASH_DF_BLOCK_0, and set the byte count to 64: err = R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t) g_src, FLASH_DF_BLOCK_0, 64);.
  3. Add assert(FSP_SUCCESS == err);, wait on while(!interrupt_called);, verify completion with assert(FLASH_EVENT_WRITE_COMPLETE == flash_event);, and reset interrupt_called = false;.
  4. Verify the written bytes using assert(0 == memcmp(g_src, (uint8_t *) 0x27000000, 64)); and add an infinite while(1){ } loop (Figure 6).

     

    The completed hal_entry.c sequence in e² studio, ending with the memcmp verification and the infinite while(1) loop.

    Figure 6. The completed hal_entry.c sequence in e² studio, ending with the memcmp verification and the infinite while(1) loop. Image used courtesy of Renesas

     

Because the RA8D1 data flash is now memory-mapped into the processor’s address space, standard C library functions like memcmp or memcpy can read the programmed flash addresses directly without a separate driver read call.

 

Step 7: Build, Initialize the Target Device, and Configure the Debugger

  1. Click the Data_Flash_RA8D1 project folder in Project Explorer and click the hammer icon to build the binary.
  2. Open Renesas Flash Programmer V3.22.00 and select File > New Project.... Set Microcontroller to RA, name the project EK_RA8D1_board, change Tool from E2 emulator to J-Link (Interface remains 2 wire UART), and click Connect.
  3. Click Target Device > Initialize Device from the top menu bar, wait for the Operation completed message, and click OK (Figure 7).

     

    Selecting Target Device > Initialize Device in Renesas Flash Programmer V3.22.00. The status pane reports Operation completed once the device is initialized.

    Figure 7. Selecting Target Device > Initialize Device in Renesas Flash Programmer V3.22.00. The status pane reports Operation completed once the device is initialized. Image used courtesy of Renesas

     

  4. In e² studio, right-click Data_Flash_RA8D1 and select Debug As > Debug Configurations.... Click Data_Flash_RA8D1 Debug_Flat under Renesas GDB Hardware Debugging, switch to the Debugger tab, and open Connection Settings.
  5. Under TrustZone, change Set TrustZone secure/non-secure boundaries from Yes to No, click Apply, and click Debug. Click Switch to enter the Debug perspective (Figure 8).

     

    The Debugger Connection Settings for Data_Flash_RA8D1 Debug_Flat, with Set TrustZone secure/non-secure boundaries changed to No.

    Figure 8. The Debugger Connection Settings for Data_Flash_RA8D1 Debug_Flat, with Set TrustZone secure/non-secure boundaries changed to No. Image used courtesy of Renesas

     

Initializing the device configures the entire data flash region as secure so the secure bus master can communicate with the secure data flash slave, while setting Set TrustZone secure/non-secure boundaries to No prevents the debugger from applying TrustZone partition boundaries to a flat project.

 

Step 8: Monitor Flash Events and Inspect the Memory Browser

  1. When the Debug perspective opens (initially paused at SystemInit() inside Reset_Handler() in startup.c), click Window > Show View > Expressions, add flash_event, right-click it, and select Enable Real-time Refresh.
  2. Switch to the hal_entry.c editor tab and place breakpoints on the R_FLASH_HP_Open line and on each of the three interrupt_called = false; lines that follow the erase, blank-check, and write event checks.
  3. Click Resume once to pause at hal_entry() in main.c, and click Resume a second time to halt at R_FLASH_HP_Open, just before the erase sequence. Click Resume to stop after the erase check and confirm flash_event reads FLASH_EVENT_ERASE_COMPLETE (0). Click Resume again to stop after the blank check and observe FLASH_EVENT_BLANK (2). Click Resume once more to stop after the write check and confirm FLASH_EVENT_WRITE_COMPLETE (1).
  4. Open Window > Show View > Memory Browser, enter 0x27000000, and inspect the stored bytes. Click Resume one final time to run memcmp and enter while(1).

Inspecting both the Expressions view and the Memory Browser confirms that each BGO interrupt fired in sequence and that the physical flash cells hold the exact buffer contents.

 

Code Snippet

For complete project files, refer to the Renesas RA FSP Example Projects repository.

// Initialize 64-byte source buffer with known sequential values (0x01 to 0x40)
for(uint32_t i = 0; i < 64; i++) {
    g_src[i] = 0x01 + (uint8_t) i;
}

// Write 64 bytes to erased Block 0, wait for BGO callback, and verify via memcmp
err = R_FLASH_HP_Write(&g_flash0_ctrl, (uint32_t) g_src, FLASH_DF_BLOCK_0, 64);
assert(FSP_SUCCESS == err);
while(!interrupt_called);
assert(FLASH_EVENT_WRITE_COMPLETE == flash_event);
interrupt_called = false;

assert(0 == memcmp(g_src, (uint8_t *) 0x27000000, 64));

 

What You Should See

As you step through the breakpoints using Resume, the Expressions window updates flash_event from FLASH_EVENT_ERASE_COMPLETE (0) to FLASH_EVENT_BLANK (2), and finally to FLASH_EVENT_WRITE_COMPLETE (1). Opening the Memory Browser at address 0x27000000 reveals the 64 programmed bytes starting at 01 (04030201 08070605 0C0B0A09 100F0E0D ... 403F3E3D in 32-bit little-endian words) and incrementing by one at each consecutive byte address. Clicking Resume one last time passes the memcmp assertion and leaves the processor running inside while(1) (Figure 9).

 

The Memory Browser at 0x27000000 beside the Expressions view, showing the 64 programmed bytes and flash_event holding FLASH_EVENT_WRITE_COMPLETE.

Figure 9. The Memory Browser at 0x27000000 beside the Expressions view, showing the 64 programmed bytes and flash_event holding FLASH_EVENT_WRITE_COMPLETE. Image used courtesy of Renesas

 

Troubleshooting

The g_flash0 Flash (r_flash_hp) stack shows a red configuration error in e² studio

When Data Flash Background Operation is set to Enabled, the FSP requires both a callback function and active flash interrupts. Open the stack’s Properties tab, set Callback to FLASH_CALLBACK, and set both Flash Ready Interrupt Priority and Flash Error Interrupt Priority to an active level such as Priority 6.

 

Flash operations fail or trigger a TrustZone access violation

In a Flat (Non-TrustZone) Project, the CPU acts as a secure master accessing 0x27000000U. Ensure that you ran Target Device > Initialize Device in Renesas Flash Programmer V3.22.00 and set Set TrustZone secure/non-secure boundaries to No under Debugger > Connection Settings in your e² studio debug configuration.

 

The compiler flags a type error on the second argument of R_FLASH_HP_Write

The R_FLASH_HP_Write API expects a uint32_t source address rather than a uint8_t * pointer. Explicitly typecast your source array as (uint32_t) g_src.

 

Where to Take It Next

Once you can erase and write raw 64-byte blocks with r_flash_hp, a natural next step is to add wear-leveling and power-fail-safe record management using the Virtual EEPROM on Flash (rm_vee_flash) or LittleFS middleware stacks available under the Storage category in the FSP Configuration view. These higher-level stacks automate block rotation so frequent parameter updates do not wear out Block 0.

 

Frequently Asked Questions

What does data flash Background Operation (BGO) do on Renesas RA8 MCUs?

BGO allows the r_flash_hp peripheral to execute slow flash erase, blank check, and write operations asynchronously in the background. Function calls return FSP_SUCCESS immediately after starting the command, and a hardware interrupt triggers your callback function once the operation completes.

 

How is the data flash organized on the Renesas RA8D1?

The data flash provides a 12 KB data area mapped across two 12 KB security aliases (Secure alias starting at 0x2700_0000 and Non-secure alias starting at 0x3700_0000). Both alias regions are divided into 192 blocks of 64 bytes each (Block 0 through Block 191), where 64 bytes is the minimum unit for erasure.

 

How do you read data fash on the EK-RA8D1?

The r_flash_hp driver does not require a dedicated read function because the data flash is directly mapped into the CPU address space. You can read programmed data directly from 0x27000000 using pointers or standard C functions such as memcpy and memcmp.

 

Where is the blank check result stored when BGO is enabled?

When BGO is enabled, R_FLASH_HP_BlankCheck reports whether the memory is blank asynchronously through the flash_event_t parameter inside the callback function (FLASH_EVENT_BLANK or FLASH_EVENT_NOT_BLANK).

 

Related Resources