Hi,
it looks like you are performing the code read on the block of flash which is E/W. There is a rule that the code is not allowed to run out of the flash which is E/W. because of this the loop which waits for CCIF must be place in different memory.
I would like to suggest you to look at the code:
//==============================================================================
//PFLASH Send_Command / Send_Command2
//==============================================================================
//this function has to be stored in RAM memory
//the main code in C language is:
// {
// DisableInterrupts; //start critical section
// FSTAT_CCIF = 1; //launch command
// while(FSTAT_CCIF == 0); //wait for done
// EnableInterrupts; //end critical section
// }
//Option1: we could define code in RAM as variable array with disassembled code.
static unsigned char Send_Command[]=
{
0x14, 0x10, 0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x10, 0xEF, 0x3D
};
//Option2: we could define code in RAM as C code and use #pragmas for placement it into RAM segment (see prm file).
#pragma CODE_SEG __NEAR_SEG MY_RAM
void Send_Command2(void)
{
DisableInterrupts; //start critical section
FSTAT_CCIF = 1; //launch command
while(FSTAT_CCIF == 0); //wait for done
EnableInterrupts; //end critical section
}
#pragma CODE_SEG DEFAULT
which is a part of the project G240-Flash-CW51 which can be found in the https://community.nxp.com/docs/DOC-93792
Best regards,
Ladislav