Hi, All~
I am using the ra-fsp flash_hp example, but the R_FLASH_HP_Erase API does not work as FSP_ERR_CMD_LOCKED is returned during the operation.
I also tested it on EK-RA8M1, but the same error is returned and it does not work.
Please advise which part I should fix.
I created the project using FSP 5.8.0.
Hi RooneyJang ,
the RA8 MCU series has a security feature, which locks the flash memory. The Unit that manages the flash access is the FCU (Flash Control Unit) -> for more explaination see Chapter 49 of the Groups user manual RA8E1 Group User's Manual: Hardware (renesas.com). By observing the DFAE bit of the FASTAT register, you can see, if a data flash access violation occurred. other than that, please check out the chapter 49.11.1.3 Protection by Block Protect Setting.
Please also see this Application Note: RA8 MCU Quick Design Guide (renesas.com) - 8.1.4.2 Flash Block Protection. It is very helpful to understand, how the flash protection works.I hope this answer helps
best regards
PC_Renesas
When I access the RA8E1 Data Flash with mempy and try to read the data, I get a MemManage Fault and a BusFault as shown in the attached image. Both 0x27000000 and 0x37000000 are the same. Please explain how I can read the data from DataFlash Memory based on e2 studio.
Have you initialized the device to factory default before running the project ?
After initializing, I proceeded as shown in the attached screen shot.
Ok, can you try to run the example project now ?
No, When Data Flash Block Address is set to 0x27000000, CMD Lock Error is returned in R_FLASH_HP_Erase. When Data Flash Address is set to 0x37000000 and then R_FLASH_HP_Erase and R_FLASH_HP_Write are executed, but when memcpy(read_buffer, (uint8_t *) FLASH_HP_DF_BLOCK_1, BLOCK_SIZE); code is executed, Default_Handler is called. An exception occurs as mentioned above.
HI RooneyJang , I have taken the above example and reduced it to the bare essentials. You can find my example code here:
#define FLASH_DF_BLOCK_0 0x27000040U #define TRANSFER_LENGTH 4 uint8_t g_dest[TRANSFER_LENGTH]; uint8_t g_src[TRANSFER_LENGTH]; flash_result_t blank_check_result; void r_flash_hp_basic_example (void) { /* Initialize p_src to known data */ for (uint8_t i = 0; i < TRANSFER_LENGTH; i++) { g_src[i] = (uint8_t) ('A' + (i % 26)); } /* Open the flash hp instance. */ fsp_err_t err = R_FLASH_HP_Open(&g_flash0_ctrl, &g_flash0_cfg); assert(FSP_SUCCESS == err); /* Erase 1 block of data flash starting at block 0. */ err = R_FLASH_HP_Erase(&g_flash0_ctrl, FLASH_DF_BLOCK_0, 1); assert(FSP_SUCCESS == err); /* Check if block 0 is erased. */ err = R_FLASH_HP_BlankCheck(&g_flash0_ctrl, FLASH_DF_BLOCK_0, TRANSFER_LENGTH, &blank_check_result); assert(FSP_SUCCESS == err); /* Verify the previously erased area is blank */ assert(FLASH_RESULT_BLANK == blank_check_result); /* Write 32 bytes to the first block of data flash. */ err = R_FLASH_HP_Write(&g_flash0_ctrl, g_src, FLASH_DF_BLOCK_0, TRANSFER_LENGTH); assert(FSP_SUCCESS == err); assert(0 == memcmp(g_src, (uint8_t *) FLASH_DF_BLOCK_0, TRANSFER_LENGTH)); }
All of this uses the r_flash_hp stack. The code writes teh ASCII symbols "ABCD" to the memory address 0x27000040.
I hope the answer helps. Best regards PC_Renesas
You are possibly trying to access data flash with wrong security attribution, that is why DFAE bit is set to 1.
From this image I see that no secure area is allocated for data flash:
So accessing the data area with secure alias will fail:
Make sure you Initialize the device back to factory default settings with Renesas Device Partition Manager or Renesas Flash Programmer tool and keep this setting to 'No' to keep the default Trustzone settings: