This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM44L520: Fapi_issueAsyncCommandWithAddress Call Not Erasing Flash Sector

Part Number: RM44L520
Other Parts Discussed in Thread: HALCOGEN

I have been having some issues getting the F021 API working correctly in my project. I have attached some code snippets below to demonstrate my issue. 

/*  Creating FaultLOG location in memory and initalizing array 
    that will be used for the log. 
*/  
#pragma DATA_SECTION(userLOGFile, "FaultLOG");
SAFETY_DATA const uint8_t userLOGFile[] = "EMPTY";

/* Function called to erase flash sectors. Right now it is configured for just erasing log data. */
SAFETY_FUNCTION results_e ProgramEraseSector (
        uint16_t    sector      /* One of four sectors */
)
{
    results_e       eraseStatus = fFAIL;
    Fapi_StatusType flashStatus;
    uint8_t         *dataBuffer;


    /* Initialize the flash erase sequence for Bank7 */
    flashStatus = Fapi_initializeFlashBanks((uint32_t) HCLK_FREQ);
    if (flashStatus == Fapi_Status_Success) { flashStatus = Fapi_setActiveFlashBank(Fapi_FlashBank7); }
    /* prgBANK7_ACTIVESECTORS is equal to 0x000Fu */
    if (flashStatus == Fapi_Status_Success) { flashStatus = Fapi_enableEepromBankSectors(prgBANK7_ACTIVESECTORS, (uint32_t) Fapi_FlashSector0); }
    
    if (flashStatus == Fapi_Status_Success)
    {
        /* Wait until Flash State Machine is ready */
        while (FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy) { ; /* Do nothing */ }

        dataBuffer = LogGetJSONPointer();

        Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector, (uint32_t *) dataBuffer);
        if (sector == prgSECTOR_LOG) { m_isLOGAvailable = false; }

        /* Wait until Flash State Machine is ready */
        while (FAPI_CHECK_FSM_READY_BUSY == Fapi_Status_FsmBusy) { ; /* Do nothing */ }

        if (FAPI_GET_FSM_STATUS == (uint32_t) Fapi_Status_Success)
        {
            eraseStatus = fPASS;
            if (sector == prgSECTOR_LOG) { m_isLOGAvailable = true; }
        }
    }

    return(eraseStatus);
}

/* Passes pointer to first address of log. */
SAFETY_FUNCTION uint8_t *LogGetJSONPointer ( void )
{
    uint8_t   *ptr;

    ptr = (uint8_t *) userLOGFile;

    return (ptr);
}

/* Memory map */
MEMORY
{
    VECTORS (X)  : origin=0x00000000 length=0x00000020
    KERNEL  (RX) : origin=0x00000020 length=0x00008000
    FLASH0  (RX) : origin=0x00008020 length=0x000B7FE0
    STACKS  (RW) : origin=0x08000000 length=0x00001000
    KRAM    (RW) : origin=0x08001000 length=0x00000800
    RAM     (RW) : origin=(0x08001000+0x00000800) length=(0x0001e400 - 0x00000800)
    FEE		(RW) : origin=0xF0200000 length=0x00004000 vfill=0xffffffff
    FEE1	(RW) : origin=0xF0204000 length=0x00004000 vfill=0xffffffff
    FEE2	(RW) : origin=0xF0208000 length=0x00004000 vfill=0xffffffff
    FEE3	(RW) : origin=0xF020C000 length=0x00004000 vfill=0xffffffff

/* USER CODE BEGIN (2) */
/* USER CODE END */
}

/* USER CODE BEGIN (3) */
/* USER CODE END */

/*----------------------------------------------------------------------------*/
/* Section Configuration                                                      */

SECTIONS
{
    .intvecs : {} > VECTORS
    /* FreeRTOS Kernel in protected region of Flash */
    .kernelTEXT   : {} > KERNEL
    .cinit        : {} > KERNEL
    .pinit        : {} > KERNEL
    /* Rest of code to user mode flash region */
    .text         : {} > FLASH0
    .const        : {} > FLASH0
    /* FreeRTOS Kernel data in protected region of RAM */
    .kernelBSS    : {} > KRAM
    .kernelHEAP   : {} > RAM
    .bss          : {} > RAM
    .data         : {} > RAM
    .sysmem  	  : {} > RAM

    FEE_TEXT_SECTION : {} > FLASH0
    FEE_CONST_SECTION : {} > FLASH0
    FEE_DATA_SECTION : {} > RAM
	FaultLOG			: START ( ulLogStartAddr ) {}		> FEE3

Stepping through the ProgramEraseSector function I seem to be able to set flash bank 7 as the active flash bank and to enable eeprom on bank 7. The RM44L520 has 16 sectors so I passed in 0x0F to allow all 16 sectors to be erased. Both of these API calls passed back success flags so they seem to have worked correctly.

After calling Fapi_issueAsyncCommandWithAddress with the erase flag and the address for the Log file the FAPI_GET_FSM_STATUS macro never returns the success flag. I checked the FlashWrapper registers and found that the FMdlStat register is set to 0x11 . According to the F021 API document this code indicates that Sector Lock Status bit and the Command Status bits are set. At this point I am a bit confused because according to the API documentation the SLOCK should not be able to be set if all sectors are set to 1 which is what I would expect from the log sectors as they were all vfilled with 0xFF in the memory map. Please let me know if there is something I am missing or is there is some additional step I need to take prior to erasing flash sectors. 

  • The RM44L520 has 16 sectors so I passed in 0x0F to allow all 16 sectors to be erased.

    To enable all 16 sectors, 0xFF should be written to BSE register, passed to the flash API.

  • RM44L520 has only one program flash bank (bank 0). To erase any flash sector of bank 0, you have to copy the flash API and related function and data to SRAM, and execute those code out of SRAM.

  • Does the Fapi_enableEepromBankSectors API call write to the BSE register or is that a separate API call? I tried to changing prgBANK7_ACTIVESECTORS from 0xF to 0xFF and the same problem remains.

    To your second point, at the moment I am trying to write to bank 7 as I am implementing a logfile not a bootloader. From my reading of the documentation it seems like bank 0 is the program flash bank and bank 7 is the for eeprom emulation and can be programmed while code is executing from bank 0. Please correct me if this is incorrect. 

  • Does the Fapi_enableEepromBankSectors API call write to the BSE register or is that a separate API call?

    This API will write the 0xFF to BSE register. For RM44x device, the bank 7 (EEPROM) has 12 sectors. 

    To enable all 16 sectors, 0xFF should be written to BSE register, passed to the flash API.

    I am sorry for the typo. It should be 0xFFFF. Bit 0 is for sector 0, and bit 15 is for sector 16.

    From my reading of the documentation it seems like bank 0 is the program flash bank and bank 7 is the for eeprom emulation and can be programmed while code is executing from bank 0. Please correct me if this is incorrect. 

    You are correct. To write data to bank 7, you don't have to execute code from SRAM. HALCOGen generates drivers for erasing and programming EEPROM. It is called FEE driver:

    The HALCOGen also has an example of using FEE driver:

  • Thank you, updating the prgBANK7_ACTIVESECTORS value to 0xFFFF fixed my issue. Just to clarify, the FEE drivers provided in Halcogen can be used to program bank 7 flash sectors while the F021 API is used primarily to flash bank 0 sectors as the API can be loaded into SRAM but can also be used to program bank 7 flash?  

  • but can also be used to program bank 7 flash?  

    Yes. you can write data to bank 7 using the flash API. You don't have to use the FEE driver generated by HALCOGen.