lib spifi bug

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by pierre on Sun Aug 03 09:01:04 MST 2014

I have used lpcspifi (v0.06) to program the flash on my LPC4330 Xplorer board, and encountered a bug...

My program executes from flash.
cr_startup_lpc43xx.c starts by setting up the clock and calling a few initialization functions before coping all the executable into RAM.
So, I have set up the linker script to put this init code in flash.

Everything else is set to be loaded in RAM before execution (including all SPIFI related code of course).

However, the spifi code calls those :


just after taking ownership of the flash... so of course, the CPU can't access those functions, and it crashes.

The fix is simple, I removed the call to Chip_Clock_GetClockInputHz (it is just a debug output), and made a copy of Chip_Clock_SetDivider, that I load in RAM along with the rest of the code.

Now it works. Actually, after fixing this, my flash programming code worked on the first try. The new libspifi interface is easier to use than the previous one...

So, cr_startup_xxxx.c needs Chip_Clock_SetDivider to be in flash, but libspifi needs it to be in RAM. A bit of a dilemma here.

cr_startup_xxxx.c could copy the executable in RAM before doing all initialization (hm...), or we need a RAM copy of Chip_Clock_SetDivider.