I would like to post some 'caveats' about the Cortex M4 BIST routines.
FIrstly, as you might imagine, the routines are NOT 'compiler subroutine-call-friendly', in that they don't preserve ANY scratchpad registers. So I have to surround the calls with 'manual' register save/restore:
//Complete test of core register set for CORTEX M4
asm(" PUSH.W {R4-R12, LR}");
register bool_t test = IEC60730B_KINETIS_CpuRegisterTest();
asm(" POP.W {R4-R12, LR}");
Secondly, the CPU test routines do NOT leave the CPU controls in their default power-on state. Most specifically, I find I must return these three registers to 'zero' to restore 'normal' interrupt operation:
__set_PRIMASK( 0 ); //Restore these items 'munged' by the test!
__set_BASEPRI( 0 );
__set_FAULTMASK( 0 );
The RAM test isn't quite so easy, since it wants to over-write all of RAM. But even changing the configuration for the 'end of RAM' to carve out some stack space, I am still in a condition that for some reason hangs-up in clock initialization if I allow the RAM tests to run due to some continued confusion in the compiler about 'retained' register contents.