mc9s12xdt512 mcu & flash initialiation

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

mc9s12xdt512 mcu & flash initialiation

Jump to solution
599 Views
Eric_t
Contributor III

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

0 Kudos
1 Solution
409 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

this is my code. I have not wanted to calculate it again and again so I added the calculation to SW.

The routine follows calculation steps. Of course you can exclude it and substitute by direct writing of FCLKDIV register.

The function describes what to put as a parameters:

UBYTE Flash_Init(unsigned long oscclk, unsigned long tbus) // [kHz,ns]

If you use "My project uses 16MHz oscillator clock, PLL 29.49MHz (bus clock 14.74MHz)"

then

Flash_Init(16000, 68) // [kHz,ns]

So I confirm previous answer.

The result of calculation should be 74 [0x4A]

So it is eenough to write FCLKDIV=0x4A

Moreover I have attached example codes plus calculator which can help you in the future.

Best regards,

Ladislav

View solution in original post

2 Replies
410 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

this is my code. I have not wanted to calculate it again and again so I added the calculation to SW.

The routine follows calculation steps. Of course you can exclude it and substitute by direct writing of FCLKDIV register.

The function describes what to put as a parameters:

UBYTE Flash_Init(unsigned long oscclk, unsigned long tbus) // [kHz,ns]

If you use "My project uses 16MHz oscillator clock, PLL 29.49MHz (bus clock 14.74MHz)"

then

Flash_Init(16000, 68) // [kHz,ns]

So I confirm previous answer.

The result of calculation should be 74 [0x4A]

So it is eenough to write FCLKDIV=0x4A

Moreover I have attached example codes plus calculator which can help you in the future.

Best regards,

Ladislav

409 Views
Eric_t
Contributor III

Hi,

It seems that "Flash_Init" operants needs the oscillator frequency in kHz and tbus in nanosecond.

So, for 16MHz oscillator and PLL frequency of 29.49MHz we have the following:

     29.49MHz / 2 = 14.745MHz bus frequence

     1/14.745MHz =67.8ns (it will be rounded to 68)

So, the call to Flash_Init should be as follow

Flash_Init(16000, 68)

0 Kudos