RA2L1 MCU Bricks

Hi AZ/IK_Renesas,

I am Using RA2L1 - R7FA2L1A92DFN.  Where I have developed a custom bootloader starting at  Address - 0x00000000. 

In Application I have made Linker settings where the Application starts - 0x00004000.

I am using 

"R_FLASH_LP_Erase (flash_ctrl_t * const p_api_ctrl, uint32_t const address, uint32_t const num_blocks) ;" API for Erasing. - No issues

"R_FLASH_LP_Write(&g_flash0_ctrl, (uint32_t)&Src, Dst, Count);" - For write.

When writing data using write API, controller goes for a non recoverable state. Like Flash Lock Sate.

Below is the Debug Log.

bootloader_Debug.jlink, return = 0
Wed Mar 15, 2023 14:27:32: Device "R7FA2L1AB" selected.
Wed Mar 15, 2023 14:27:32: DLL version: V7.84b, compiled Jan 11 2023 16:42:23
Wed Mar 15, 2023 14:27:32: Firmware: J-Link OB-S124 compiled Sep 1 2022 15:38:25
Wed Mar 15, 2023 14:27:32: Selecting SWD as current target interface.
Wed Mar 15, 2023 14:27:32: JTAG speed is initially set to: 1000 kHz
Wed Mar 15, 2023 14:27:32: Found SW-DP with ID 0x5BA02477
Wed Mar 15, 2023 14:27:32: Found SW-DP with ID 0x5BA02477
Wed Mar 15, 2023 14:27:32: DPIDR: 0x5BA02477
Wed Mar 15, 2023 14:27:32: CoreSight SoC-400 or earlier
Wed Mar 15, 2023 14:27:32: Scanning AP map to find all available APs
Wed Mar 15, 2023 14:27:32: AP[2]: Stopped AP scan as end of AP map has been reached
Wed Mar 15, 2023 14:27:32: AP[0]: AHB-AP (IDR: 0x74770001)
Wed Mar 15, 2023 14:27:32: AP[1]: APB-AP (IDR: 0x44770002)
Wed Mar 15, 2023 14:27:32: Iterating through AP map to find AHB-AP to use
Wed Mar 15, 2023 14:27:32: AP[0]: Skipped. Invalid implementer code read from CPUIDVal[31:24] = 0x00
Wed Mar 15, 2023 14:27:32: AP[1]: Skipped. Not an AHB-AP
Wed Mar 15, 2023 14:27:32: Attach to CPU failed. Executing connect under reset.
Wed Mar 15, 2023 14:27:32: DPIDR: 0x5BA02477
Wed Mar 15, 2023 14:27:32: CoreSight SoC-400 or earlier
Wed Mar 15, 2023 14:27:32: Scanning AP map to find all available APs
Wed Mar 15, 2023 14:27:32: AP[2]: Stopped AP scan as end of AP map has been reached
Wed Mar 15, 2023 14:27:32: AP[0]: AHB-AP (IDR: 0x74770001)
Wed Mar 15, 2023 14:27:32: AP[1]: APB-AP (IDR: 0x44770002)
Wed Mar 15, 2023 14:27:32: Iterating through AP map to find AHB-AP to use
Wed Mar 15, 2023 14:27:32: AP[0]: Skipped. Invalid implementer code read from CPUIDVal[31:24] = 0x00
Wed Mar 15, 2023 14:27:32: AP[1]: Skipped. Not an AHB-AP
Wed Mar 15, 2023 14:27:32: Could not find core in Coresight setup
Wed Mar 15, 2023 14:27:32: Found SW-DP with ID 0x5BA02477
Wed Mar 15, 2023 14:27:32: Found SW-DP with ID 0x5BA02477
Wed Mar 15, 2023 14:27:32: DPIDR: 0x5BA02477
Wed Mar 15, 2023 14:27:32: CoreSight SoC-400 or earlier
Wed Mar 15, 2023 14:27:32: Scanning AP map to find all available APs
Wed Mar 15, 2023 14:27:32: AP[2]: Stopped AP scan as end of AP map has been reached
Wed Mar 15, 2023 14:27:32: AP[0]: AHB-AP (IDR: 0x74770001)
Wed Mar 15, 2023 14:27:32: AP[1]: APB-AP (IDR: 0x44770002)
Wed Mar 15, 2023 14:27:32: Iterating through AP map to find AHB-AP to use
Wed Mar 15, 2023 14:27:32: AP[0]: Core found
Wed Mar 15, 2023 14:27:32: AP[0]: AHB-AP ROM base: 0x4001A000
Wed Mar 15, 2023 14:27:32: CPUID register: 0x411CD200. Implementer code: 0x41 (ARM)
Wed Mar 15, 2023 14:27:32: Feature set: Baseline
Wed Mar 15, 2023 14:27:32: Found Cortex-M23 r1p0, Little endian.
Wed Mar 15, 2023 14:27:32: FPUnit: 4 code (BP) slots and 0 literal slots
Wed Mar 15, 2023 14:27:32: Security extension: not implemented
Wed Mar 15, 2023 14:27:32: CoreSight components:
Wed Mar 15, 2023 14:27:32: ROMTbl[0] @ 4001A000
Wed Mar 15, 2023 14:27:32: [0][0]: E000E000 CID B105900D PID 000BBD20 DEVARCH 47702A04 DEVTYPE 00 Cortex-M23
Wed Mar 15, 2023 14:27:32: [0][1]: E0001000 CID B105900D PID 000BBD20 DEVARCH 47701A02 DEVTYPE 00 DWT
Wed Mar 15, 2023 14:27:32: [0][2]: E0002000 CID B105900D PID 000BBD20 DEVARCH 47701A03 DEVTYPE 00 FPB
Wed Mar 15, 2023 14:27:32: [0][3]: 40019000 CID B105900D PID 000BBD20 DEVARCH 47710A31 DEVTYPE 31 MTB
Wed Mar 15, 2023 14:27:32: Reset: Halt core after reset via DEMCR.VC_CORERESET.
Wed Mar 15, 2023 14:27:32: Reset: Reset device via AIRCR.SYSRESETREQ.
Wed Mar 15, 2023 14:27:32: Hardware reset with strategy 0 was performed
Wed Mar 15, 2023 14:27:32: Initial reset was performed
Wed Mar 15, 2023 14:27:33: Loaded debugee: D:\Projects\TeckTronicx\Port_MKL\Code\CommonFolderArchitecture\10\09_Mar_2023_R1\WIP\Bootloader\Debug\Exe\bootloader.out
Wed Mar 15, 2023 14:27:33: Warning: Failed to measure CPU clock frequency
Wed Mar 15, 2023 14:27:33: Could not detect CPU clock speed. Verification of test code downloaded into RAM failed.
Wed Mar 15, 2023 14:27:33: 15348 bytes downloaded (348.56 Kbytes/sec)
Wed Mar 15, 2023 14:27:33: Download completed.
Wed Mar 15, 2023 14:27:33: Reset: Halt core after reset via DEMCR.VC_CORERESET.
Wed Mar 15, 2023 14:27:33: Reset: Reset device via AIRCR.SYSRESETREQ.
Wed Mar 15, 2023 14:27:33: Software reset was performed
Wed Mar 15, 2023 14:27:33: Target reset
Wed Mar 15, 2023 14:27:33: Illegal register read at register zone offset 128.
Wed Mar 15, 2023 14:27:33: HardFault exception.
Wed Mar 15, 2023 14:27:33: Could not determine the location where the exception occurred.
Wed Mar 15, 2023 14:27:33:
Wed Mar 15, 2023 14:27:33: See the call stack for more information.
Wed Mar 15, 2023 14:27:44: Illegal register read at register zone offset 128.
Wed Mar 15, 2023 14:27:44: HardFault exception.
Wed Mar 15, 2023 14:27:44: Could not determine the location where the exception occurred.

I tried Erasing Entire Blocks Using  Renesas Flash Programmer with below settings

Resulted in below error.

Question

1. Reason for Flash Getting Locked

2. How shall I recover from above stated. 

Thanks in Advance,