ZHCAEX4 January 2025 F29H850TU , F29H859TU-Q1
EEPROM_Write_Buffer() 将指向闪存地址的指针作为写入位置,并将指向 64 位写入缓冲区的指针作为输入。该函数会调用所有必要的 FlashAPI 函数,将写入缓冲区提交到位于指定地址的闪存。
首先,函数会清除 FSM 状态并设置适当的保护掩码。
Fapi_StatusType oReturnCheck;
Fapi_FlashStatusType oFlashStatus;
Fapi_FlashStatusWordType oFlashStatusWord;
ClearFSMStatus();
Fapi_setupBankSectorEnable((uint32_t*) FLASH_BANK_SELECT, u32UserFlashConfig,
FLASH_NOWRAPPER_O_CMDWEPROTA, WE_Protection_A_Mask);
Fapi_setupBankSectorEnable((uint32_t*) FLASH_BANK_SELECT, u32UserFlashConfig,
FLASH_NOWRAPPER_O_CMDWEPROTB, WE_Protection_B_Mask);
然后,函数会将来自写入缓冲器的数据编程到闪存中。
oReturnCheck = Fapi_issueProgrammingCommand((uint32_t*) address, (uint8_t*) write_buffer,
WRITE_SIZE_BYTES, 0, 0, Fapi_AutoEccGeneration, u32UserFlashConfig);
while (Fapi_checkFsmForReady((uint32_t) address, u32UserFlashConfig) == Fapi_Status_FsmBusy);
最后,函数会检查是否存在任何编程错误并验证写入的数据是否正确。
if (oReturnCheck != Fapi_Status_Success)
{
Sample_Error();
}
oFlashStatus = Fapi_getFsmStatus((uint32_t) address, u32UserFlashConfig);
if (oFlashStatus != 3)
{
FMSTAT_Fail();
}
oReturnCheck = Fapi_doVerify((uint32_t*) address, VERIFY_LEN, (uint32_t*) write_buffer,
&oFlashStatusWord, 0, u32UserFlashConfig);
if (oReturnCheck != Fapi_Status_Success)
{
Sample_Error();
}