void mcal_flash_program_autoecc_sector(uint32_t address, uint32_t *buffer, uint32_t size) { uint32 u32Index = 0; uint16 i = 0; Fapi_StatusType oReturnCheck; Fapi_FlashStatusType oFlashStatus; Fapi_FlashStatusWordType oFlashStatusWord; // // A data buffer of max 8 16-bit words can be supplied to the program // function. // Each word is programmed until the whole buffer is programmed or a // problem is found. However to program a buffer that has more than 8 // words, program function can be called in a loop to program 8 words for // each loop iteration until the whole buffer is programmed. // // Remember that the main array flash programming must be aligned to // 64-bit address boundaries and each 64 bit word may only be programmed // once per write/erase cycle. Meaning the length of the data buffer // (3rd parameter for Fapi_issueProgrammingCommand() function) passed // to the program function can only be either 4 or 8. // // Program data in Flash using "AutoEccGeneration" option. // When AutoEccGeneration option is used, Flash API calculates ECC for the // given 64-bit data and programs it along with the 64-bit main array data. // Note that any unprovided data with in a 64-bit data slice // will be assumed as 1s for calculating ECC and will be programmed. // // Note that data buffer (Buffer) is aligned on 64-bit boundary for verify // reasons. // // Monitor ECC address for the sector below while programming with // AutoEcc mode. // // In this example, the number of bytes specified in the flash buffer // are programmed in the flash sector below along with auto-generated // ECC. // for (i = 0, u32Index = address; //(u32Index < (address + WORDS_IN_FLASH_BUFFER)); (u32Index < (address + size)); i += 8, u32Index += 8) { oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, (uint16 *)(buffer + i / 2), 8, 0, 0, Fapi_AutoEccGeneration); // // Wait until the Flash program operation is over // while (Fapi_checkFsmForReady() == Fapi_Status_FsmBusy) ; if (oReturnCheck != Fapi_Status_Success) { // // Check Flash API documentation for possible errors // // Example_Error(oReturnCheck); } // // Read FMSTAT register contents to know the status of FSM after // program command to see if there are any program operation related // errors // oFlashStatus = Fapi_getFsmStatus(); if (oFlashStatus != 0) { // // Check FMSTAT and debug accordingly // // FMSTAT_Fail(); } // // Verify the programmed values. Check for any ECC errors. // oReturnCheck = Fapi_doVerify((uint32 *)u32Index, 4, buffer + (i / 2), &oFlashStatusWord); if (oReturnCheck != Fapi_Status_Success) { // // Check Flash API documentation for possible errors // // Example_Error(oReturnCheck); } } }