AnsweredAssumed Answered

Bug in EEPROM emulation libraries described in AN3390 and AN2594

Question asked by diz on May 8, 2017


i want to report a bug in the library "STM32F2xx_AN3390_FW_V1.0.0", which can cause the loss of user data.

On startup, the library checks the status of the two Flash pages. If one page is marked "valid" and the other marked "receiving", first all data are copied from the valid to the receiving page, than the receiving page is marked valid and than the valid page is erased. (see lines 137-150 and 228-250 in eeprom_emulation.c). If a power fail or reset event occurs after the receiving page is marked valid, but before the previous valid page is erased, on next start we find two pages marked as valid, which is considered an invalid configuration and consequently leads to erasure of both pages.

This bad sequence is already defined in AN3390, page 9, table 2, Here the actions described if page 1 is receiving and  page 0 is valid says "transfer the last updated valued from page 0 to page 1 & mark page 1 as valid & erase page 0" (vice versa if page 0 is receiving and page 1 is valid). The "&" seem to imply temporal order, so this is already the wrong sequence. Instead, we should first erase the source page and THAN mark the receiving page as vaild. If the program restarts after erasure of the source page, it will find one page receiving and one erased, will mark the receiving page as valid and proceed with all data intact.

AN2594 and library "STM32F10x_AN2594_FW_V2.1.0" seem to suffer from the same bug.