在使用STM32 AN2594提供的EEPROM Emulation程序做参数值保存用时, 实际应用中发现在其中eeprom.c文件中(2007-10-8发布), 功能u16 EE_VerifyPageFullWriteVariable(u16 VirtAddress, u16 Data)中的同一数据值是否已经写入有点小错误: while (Address < PageEndAddress) { /* Verify each time if Address and Address+2 contents are equal to Data and VirtAddress respectively */ if (((*(vu16*)Address) == Data) && ((*(vu16*)(Address + 2)) == VirtAddress)) { return FLASH_COMPLETE; }
如果已经写入值v1, 再写入值v2, 后再写入以前写过的值v1, 回读会读出v2的结果而不是期望的v1.
后来在http://www.st.com/mcu/forums-cat-6365-23.html确实看到有报告这个bug.
因时间限制, 小弟简单地在比较最后一次写入(最后一个匹配地址)的值是否一致, 不一致就再写一遍新值:
/* Check each active page address starting from begining */ while (Address < PageEndAddress) { /* Verify each time if Address and Address+2 contents are equal to Data and VirtAddress respectively */ // if (((*(vu16*)Address) == Data) && ((*(vu16*)(Address + 2)) == VirtAddress)) if ( (*(vu16*)(Address + 2)) == VirtAddress ) { if((*(vu16*)Address) == Data) IsVariableValMatchedFlag = TRUE; else IsVariableValMatchedFlag = FALSE; // return FLASH_COMPLETE; } |