上午把代码调正确了,但是感觉ecc option并没有插入错误的数据,然后又去查阅了下Flash_API的文档,发现里面有这样的内容:
也就是说例程中提供的Fapi_issueProgrammingCommand函数在Fapi_AutoEccGeneration模式(默认设置)时,无法使用用户设定来操作,ecc只能进行自动生成。为了实现用户引入错误数据的需求,需要更改函数的模式。按照文档中给出的描述,可以使用Fapi_DataOnly和Fapi_EccOnly模式来分别进行数据的写入和ECC的生成。同时,文档中还提到使用Fapi_DataAndEcc模式等同于分别使用dataonly和ecconly(Purpose of this mode is not different than that of using Fapi_DataOnly and Fap_EccOnly modes together. However, this mode is beneficial when both the data and the calculated ECC can be programmed at the same time)。对代码中的内容进行如下修改:
oReturnCheck = Fapi_issueProgrammingCommand((uint32 *)u32Index, Buffer + i, 8, eccbuffer, 1, Fapi_DataAndEcc)