Content originally posted in LPCWare by Feo Elektronik WR on Mon May 26 08:58:18 MST 2014
We had a very similar problem using "spifi_drv_M3.lib" (file date 2012-12-11, extracted from "LPC18xx_SPIFI_LPCXpresso6_1-zip" or "libfalcon_m3_spifi_drv.a" on LPC1850:
spifi_init() worked, spifi_erase() and spifi_program() not, returning 0x00020004 (ERR_SPIFI_OPERAND_ERROR).
The reason was a bug in the spifi lib. Here's what I wrote to NXP support:
Quote:
I analyzed the disassembly of spifi_erase() from entry point until call of checkAd(). Please see the attached commented screenshot of the debug session.
spifi_erase() passes a local copy of *opers to cheakAd() that has not yet been initialized at this point.
Only AFTER calling checkAd(), the local copy is initialized with *opers by memcpy_spifi_lib().
Thus, checkAd() is checking random garbage on the stack frame instead of *opers, so sometimes it fails, sometimes not. This is exactly what we observe.
The problem is easy to spot in disassembly of spifi_erase(): bl checkAd comes before bl memcpy_spifi_lib. It should be the other way round.