AnsweredAssumed Answered

mc9s12xdt512 mcu & flash initialiation

Question asked by Eric_t d on Oct 12, 2017
Latest reply on Oct 13, 2017 by lama

Hi!

 

I have download from NXP, a demo example project for programming the internal flash memory of XD256 controllers.

The project that I download is "SW-XD256-FLASH-E_W-v1_0-CW45"

I have attached the project.

Since the project refers to XD256 controllers, assume that the project is also valid for mc9s12xdt512 controller.

I have made a try and the project works just fine with mc9s12xdt512 controller.

The problem that I am facing, is that it is not clear what is the correct frequency that I should enter in "Flash_Init" routine.

 

"Flash_Init" routine.

 

//==============================================================================
// Function Name: Flash_Init
// Description : Initialize Flash NVM for HCS12 by programming FCLKDIV based on
// passed oscillator frequency, then uprotect the array, and finally ensure PVIOL
// and ACCERR are cleared by writing to them.
//==============================================================================
UBYTE Flash_Init(unsigned long oscclk, unsigned long tbus) // [kHz,ns]
{
unsigned long fclk_val;
unsigned long temp;

if(tbus > 1000L) return PROGRAM_ERASE_IMPOSSIBLE; // tbus > 1us (1000ns) (page 35 S12FTS256KV2.pdf )
temp = (oscclk*1000) % 8;
fclk_val = (oscclk * (5000UL+tbus)) / 1000000UL;

if (oscclk >= 12800UL)
{ fclk_val = fclk_val / 8;
if(temp) { fclk_val = fclk_val - 1; } // oscclk % 8 is not an integer
FCLKDIV = (unsigned char) (fclk_val | 0x40);
}
else
{ if(temp) { fclk_val = (fclk_val-1); } // oscclk % 8 is not an integer
FCLKDIV = (unsigned char) fclk_val;
}

// test computed parameters
if (oscclk >= 12800L) {temp = 8UL*1000000UL*(1+FCLKDIV&0x3F) / oscclk + tbus;}
else {temp = 1000000UL*(1+FCLKDIV&0x3F) / oscclk + tbus; }
temp = temp / 1000;
if(temp < 5UL) return PROGRAM_ERASE_IMPOSSIBLE;
FSTAT= 0x30;
}
//==============================================================================
//==============================================================================
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

the main calls it as follow  

//----------------------------------------
//initialization of FLASH module
//----------------------------------------
err = Flash_Init(16000,125); // Oscillator clock = 16 000 kHz
// Bus clock = 8MHz => tbus=125ns

My project uses 16MHz oscillator clock, PLL 29.49MHz (bus clock 14.74MHz)

I assume that the operant of "Flash_Init" should be the PLL clock and not the oscillator clock.

I assume that I have to call the "Flash_Init" as follow: 

Flash_Init(29490, 68); 

Could anyone confirm that the above flash initialization is correct?

 

Thank you

Original Attachment has been moved to: SW-XD256-FLASH-E_W-v1_0-CW45.zip

Outcomes