AnsweredAssumed Answered

S32K144 EEPROM sector erase count

Question asked by maciej.cebula@globallogic.com on Aug 22, 2019
Latest reply on Mar 2, 2020 by Veeraju Hallikeri

Hi all,
I am using S32K144 in my project, now I'm implementing EEPROM functionality and all is working fine, but now I want to add some extra feature such as: detected the power loss, or calculation the endurance of the EEPROM in the code.
I am not using quick write functionality - only standard.

For this purpose, I'm reading the FlexRAM Function command FCCOB, below there is my code it is base on the example from S32 Studio.
My problem here is that all-time I got 0 in Brown-out (BO) Detection Codes and in EEPROM sector erase count. Even if the power loss is observed in the data reading from backup EFlash because they are initialized with 0xFF. Can you give me some hint?

 

Std_Return_t Flash_SetFlexRamFunction( FlexRamFunctionControlCode_t tFlexRamFuncCode,  NvmStatus_t * const psNvmStatus)
{
     Std_Return_t tResult = STD_OK;
     /* Check CCIF to verify the previous command is completed */
     if (0U == (FTFC->FSTAT & FTFC_FSTAT_CCIF_MASK))
     {
          tResult = STD_BUSY;
     }
    else
    {
        /* Clear RDCOLERR & ACCERR & FPVIOL flag in flash status register. Write 1 to clear */
         FTFC->FSTAT = (uint8)(FTFC_FSTAT_FPVIOL_MASK | FTFC_FSTAT_ACCERR_MASK | FTFC_FSTAT_RDCOLERR_MASK);
        /* Passing parameter to the command */
          FTFC->FCCOB[FLASH_FCCOB0_INDEX] = FLASH_FCMD_SET_EERAM;
          FTFC->FCCOB[FLASH_FCCOB1_INDEX] = (uint8_t)tFlexRamFuncCode;

        /* Calling flash command sequence function to execute the command */
        DISABLE_IRQ();
          tResult = Fls_CommandSequence();
          ENABLE_IRQ();

        if ((tFlexRamFuncCode == EEE_STATUS_QUERY) && (tResult == STD_OK))
        {
            if (psNvmStatus == 0u)
            {
                 tResult = STD_NOT_OK;
            }
            else
            {
                psNvmStatus->u8BrownOutCode = FTFC->FCCOB[FLASH_FCCOB5_INDEX];
                psNvmStatus->u16SectorEraseCount = (uint16_t)((uint16_t)FTFC->FCCOB[FLASH_FCCOB8_INDEX] << 8U);
                psNvmStatus->u16SectorEraseCount |= (uint16_t)FTFC->FCCOB[FLASH_FCCOB9_INDEX];
            }
        }
    }
    return tResult;
}

Outcomes