How to unlock or clear flash on RA2L1 after an accessWindowSet()

Hi,

Kit: EK-RA2L1

We tried to use the access winodwset(), below is my code used, after using this i am unable to debug my code, the MCU never enters the Reset Handler. Tried to clear the flash with j-Link lite but no use. Please help 

//err_code = R_FLASH_LP_Erase(&g_flash0_ctrl, 0x00000000, 8);
//assert(FSP_SUCCESS == err_code);


// err_code = R_FLASH_LP_AccessWindowSet(&g_flash0_ctrl, 0x00000000,0x00001FFFF);
// assert(FSP_SUCCESS == err_code);

//err_code = R_FLASH_LP_AccessWindowClear(&g_flash0_ctrl);
//assert(FSP_SUCCESS == err_code);

//err_code = R_FLASH_LP_StartUpAreaSelect(&g_flash0_ctrl, FLASH_STARTUP_AREA_BLOCK0, true);
//assert(FSP_SUCCESS == err_code);

After Debug below is the response

Starting download

Option Function Select, writing to address 0x00000400 with data ffffffffdfceffff

SECMPUxxx, writing to address 0x00000408 with data fcff0f00ffff0f00fcff0f00ffff0f00...

Finished download

Hardware breakpoint set at address 0x650

GDB action 'read memory', has failed with error code, 0xffffffff

Disconnected from the Target Debugger.

  • Do you call R_FLASH_LP_Open() anywhere in your code?

    What is the data in the secure MPU config area, and the AWS & OCDID config area, viewed with JLink commander :-

  • HI Jermy,

    Refer the attached snap

    Yes, Please refer below code

    #include "hal_data.h"
    #include <stdio.h>

    FSP_CPP_HEADER
    void R_BSP_WarmStart(bsp_warm_start_event_t event);
    FSP_CPP_FOOTER

    uint8_t switch_flag = false;

    /*******************************************************************************************************************//**
    * main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
    * is called by main() when no RTOS is used.
    **********************************************************************************************************************/
    void hal_entry(void)
    {
    fsp_err_t err_code = FSP_SUCCESS;

    R_FLASH_LP_Open(&g_flash0_ctrl, &g_flash0_cfg);

    R_ICU_ExternalIrqOpen(&g_external_irq6_ctrl, &g_external_irq6_cfg);
    R_ICU_ExternalIrqEnable(&g_external_irq6_ctrl);

    while(1)
    {
    R_BSP_SoftwareDelay(100,BSP_DELAY_UNITS_MILLISECONDS);
    R_IOPORT_PinWrite(&g_ioport_ctrl, LED3, 1);

    R_BSP_SoftwareDelay(150,BSP_DELAY_UNITS_MILLISECONDS);
    R_IOPORT_PinWrite(&g_ioport_ctrl, LED3, 0);

    if(switch_flag)
    {
    switch_flag = false;
    //err_code = R_FLASH_LP_Erase(&g_flash0_ctrl, 0x00000000, 8);
    //assert(FSP_SUCCESS == err_code);


    err_code = R_FLASH_LP_AccessWindowSet(&g_flash0_ctrl, 0x00000000,0x00000000);
    assert(FSP_SUCCESS == err_code);

    //err_code = R_FLASH_LP_AccessWindowClear(&g_flash0_ctrl);
    //assert(FSP_SUCCESS == err_code);

    //err_code = R_FLASH_LP_StartUpAreaSelect(&g_flash0_ctrl, FLASH_STARTUP_AREA_BLOCK0, true);
    //assert(FSP_SUCCESS == err_code);
    }
    }

    #if BSP_TZ_SECURE_BUILD
    /* Enter non-secure code */
    R_BSP_NonSecureEnter();
    #endif
    }

    /*******************************************************************************************************************//**
    * This function is called at various points during the startup process. This implementation uses the event that is
    * called right before main() to set up the pins.
    *
    * @param[in] event Where at in the start up process the code is currently at
    **********************************************************************************************************************/
    void R_BSP_WarmStart(bsp_warm_start_event_t event)
    {
    if (BSP_WARM_START_RESET == event)
    {
    #if BSP_FEATURE_FLASH_LP_VERSION != 0

    /* Enable reading from data flash. */
    R_FACI_LP->DFLCTL = 1U;

    /* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
    * C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
    #endif
    }

    if (BSP_WARM_START_POST_C == event)
    {
    /* C runtime environment and system clocks are setup. */

    /* Configure pins. */
    R_IOPORT_Open (&g_ioport_ctrl, &g_bsp_pin_cfg);
    }
    }

    /* Callback function */
    void switch_2_callback(external_irq_callback_args_t *p_args)
    {
    FSP_PARAMETER_NOT_USED(p_args);
    switch_flag = true;
    }


    #if BSP_TZ_SECURE_BUILD

    BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();

    /* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
    BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
    {

    }
    #endif

  • The FSPR bit in the AWS register is 0, so the AWS register can no longer be changed.

    The FAWS = FAWE (both 0) so according to the HW manual, the P/E command is allowed to execute in the full program flash range.

    Where is the code linked to, is the erase command :-

    R_FLASH_LP_Erase(&g_flash0_ctrl, 0x00000000, 8);

    erasing the flash that the code is actaully running from?

  • Hi Jermy,

    But if i am creating a new project on the same controller board, still the issue remains same, once i debug it is not entering the Reset handler. I tried to erase the completed flash with RFP entering the SCI boot mode. But still it is the same below issue.

    Can you please help how to restore to default.

  • There are no settings in the device which should prevent the flash being erased or programmed. Since both RFP and the JLink fail to erase the device, I can only think that the device has been damaged in some way.

  • Yes jermey, After all the possibilities of checking i think the MCU is damaged.

    Is this API err_code = R_FLASH_LP_AccessWindowSet(&g_flash0_ctrl, 0x00000000,0x00001FFFF); which has blocked the MCU, which was not cleared the first time.

    Just to understand the root cause of the issue