lpcware

SPIFI boot vs. USB/JTAG boot: differences

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by mch0 on Wed Sep 24 03:47:22 MST 2014
Hello,

I recently wanted to boot my almost completed application directly from SPIFI ("cold").
It did not only not work, it even managed to get the chip into a state where the JTAG debugger couldn't connect any more.
The only way to get it back into life was by booting into USB.

The application was working perfectly under JTAG debugging (also from SPIFI).

Right now I got it into working oder (cold boot), but I'm still not happy.

1. Oscillator
One major difference is the clock set up.
With USB the BOOT ROM enables the XTAL oscillator, so when the app. starts, it's already configured and running.
When booting from SPIFI the clock is generated by the IRC and the CPU is supposed to run at 96 MHz.
So the app. has to enable the XTAL oscillator on its own. No problem, my app did that anyway, but I think the LPCOpen 2.12 supplied function void Chip_Clock_EnableCrystal(void) may contain two flaws.
1. The Highspeed-Bit is not set correctly when Fosc<20MHz, because the function never resets it in the first place and by default it is set already. Fix is to replace the line
OldCrystalConfig &= (~1); by OldCrystalConfig &= (~5);.
2. The final wait may be too short. Since the CPU might run at up to 200 MHz at this point, an empty loop 0...1000 seems too short.
I'd rather use 10000 or so.

2. malloc()
This is for me the more serious of the two differences I have found.
I use the redlib() no-host variant. I also used the variant where redlib uses malloc() to print "all-in-one", not char-by-char.
When booting "cold" from SPIFI the code crashes, probably within malloc(). The same code started "warm" from USB/JTAG does not crash. The start of heap looks OK, it's the same anyway.
When I switch to "char-by-char" the problem goes away and I can cold boot.

Although it works, I'm not happy because I do not know why the first version does not work.
It could be sheer luck that it works now and that's not good enough for the field :(

Anyone any idea about the malloc()-problem and/or where to look for remedy?

Mike



Outcomes