run-time programming of EEPROM in DP256

Started by danielkolodka2002 June 28, 2006
Hello dear people, actually we are trying to program, using a run-time
routine, the EEPROM of the MCU: HCS912DP256, but we could not do it
yet. We modify and traslate to C, the assembler routine used for Erase
de EEPROM in the bootloader code, of course we change the code to
command the internal FSM, that automatically erase and program this
memory. The result is always the same, every time we erase and program
a sector (4 bytes) with new data values, we read the same, two $FFFF
words. Do you have any reference routine in order to verify our
procedure ?. the EEPROM is always enable, after a normal reset ?. Any
idea will be very appreciate... thank you in advance.

Pedro Daniel Kolodka
Naviacom Argentina

Daniel,
Take a look at:

AN2204, Fast NVM Programming for the MC9S12DP256

You can find it and download it at the Freescale DP256 product page.

Rgds,
Guillermo.

> -----Mensaje original-----
> De: 6... [mailto:6...] En
> nombre de danielkolodka2002
> Enviado el: Micoles, 28 de Junio de 2006 20:31
> Para: 6...
> Asunto: [68HC12] run-time programming of EEPROM in DP256
>
> Hello dear people, actually we are trying to program, using a
> run-time routine, the EEPROM of the MCU: HCS912DP256, but we
> could not do it yet. We modify and traslate to C, the
> assembler routine used for Erase de EEPROM in the bootloader
> code, of course we change the code to command the internal
> FSM, that automatically erase and program this memory. The
> result is always the same, every time we erase and program a
> sector (4 bytes) with new data values, we read the same, two
> $FFFF words. Do you have any reference routine in order to
> verify our procedure ?. the EEPROM is always enable, after a
> normal reset ?. Any idea will be very appreciate... thank you
> in advance.
>
> Pedro Daniel Kolodka
> Naviacom Argentina
>
>
>
>
>
>
>
>
>
>
>
I also recommend to take a look to AN2400 "HCS12 Non Volatile Memory
Guidelines"

danielkolodka2002 escribi
>
> Hello dear people, actually we are trying to program, using a run-time
> routine, the EEPROM of the MCU: HCS912DP256, but we could not do it
> yet. We modify and traslate to C, the assembler routine used for Erase
> de EEPROM in the bootloader code, of course we change the code to
> command the internal FSM, that automatically erase and program this
> memory. The result is always the same, every time we erase and program
> a sector (4 bytes) with new data values, we read the same, two $FFFF
> words. Do you have any reference routine in order to verify our
> procedure ?. the EEPROM is always enable, after a normal reset ?. Any
> idea will be very appreciate... thank you in advance.
>
> Pedro Daniel Kolodka
> Naviacom Argentina
>
>

--
------------
Agustin Pedroso Rizaldos
Software Engineer
R&D deparment
SEDECAL, S.A.
Tel. (+34)91 628 92 35
Fax. (+34)91 628 05 74
C/ Pelaya 9
Polono Ind. "Rio de Janeiro"
28110 Algete (Madrid)- Espa
-----------

Are you debugging with CodeWarrior3.1 or later??

Write your own code to check if the bytes are properly written. Don't
believe what debugger says

Here below, a portion of a flash driver:

//*****************************************************************************
//* Function Name : Flash_Write_Word
//* Description : Program a given Flash location using address and data
//* passed from calling function.
//*
//*****************************************************************************
signed char Flash_Write_Word(unsigned char page,unsigned int * address,
unsigned int data)
{
unsigned char thisPage;

if((unsigned int)address & 0x0001) {return Flash_Odd_Access;} //
Aligned word?
if(readPagedAddress(page,address)!= 0xFFFF){return
Flash_Not_Erased;} // Is it erased?

// Error Bits must be cleared for all blocks
ClearErrorBlocks();

// PPAGE and BNKSEL (Flash Bank Register Selection)
thisPage = PPAGE; //lmg 2/02/06

//Don't put breakpoints in code between these dashed lines
//-----------------------------
PPAGE = page;
FCNFG = GetBNKSEL(PPAGE);
if(FSTAT_CBEIF == 1) // If cmd queue can accept another cmd
{
(*address) = data;
FCMD = PROG;// Store programming command in FCMD
(void)DoOnStack(page);// just passed for PPAGE

PPAGE = thisPage;
//----------------------------
if (FSTAT_ACCERR) {return Access_Error;}
if (FSTAT_PVIOL) {return Protection_Error;}

while (FSTAT_CCIF != 1){} // Wait for command completion
}
else
{
return FULL_QUEUE_ERROR; // Cmd queue can not accept another cmd
}
// CHECK IF THE WORD WAS WRITTEN PROPERLY
if(readPagedAddress(page,address) == data) return OK;
else return CHECK_WRITE;
}
//////////////////////////////////////////////////////////////////////////
// FNC: function to read from paged memory area
//
unsigned int readPagedAddress(unsigned char page, unsigned int *address)
{
unsigned char thisPage;
unsigned int content;

thisPage = PPAGE;
PPAGE = page;
content =(unsigned int) *address;
PPAGE = thisPage;

return content;
}
Guillermo F. Molina escribi
>
> Daniel,
> Take a look at:
>
> AN2204, Fast NVM Programming for the MC9S12DP256
>
> You can find it and download it at the Freescale DP256 product page.
>
> Rgds,
> Guillermo.
>
> > -----Mensaje original-----
> > De: 6...































Gracias Guillermo, vamos a investigar la nota de aplicaci para ver
si encontramos el problema.
Saludos

Pedro

--- In 6..., "Guillermo F. Molina"
wrote:
>
> Daniel,
> Take a look at:
>
> AN2204, Fast NVM Programming for the MC9S12DP256
>
> You can find it and download it at the Freescale DP256 product page.
>
> Rgds,
> Guillermo.
>
> > -----Mensaje original-----
> > De: 6... [mailto:6...] En
> > nombre de danielkolodka2002
> > Enviado el: Micoles, 28 de Junio de 2006 20:31
> > Para: 6...
> > Asunto: [68HC12] run-time programming of EEPROM in DP256
> >
> > Hello dear people, actually we are trying to program, using a
> > run-time routine, the EEPROM of the MCU: HCS912DP256, but we
> > could not do it yet. We modify and traslate to C, the
> > assembler routine used for Erase de EEPROM in the bootloader
> > code, of course we change the code to command the internal
> > FSM, that automatically erase and program this memory. The
> > result is always the same, every time we erase and program a
> > sector (4 bytes) with new data values, we read the same, two
> > $FFFF words. Do you have any reference routine in order to
> > verify our procedure ?. the EEPROM is always enable, after a
> > normal reset ?. Any idea will be very appreciate... thank you
> > in advance.
> >
> > Pedro Daniel Kolodka
> > Naviacom Argentina
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
Gracias Agustin. Te comento, estamos con la aplicaci desarrollada
con el ICC 12(image craft compiler), de todos modos vamos a seguir la
rutina que nos enviaste hecha para el metrowerk. Te hago una
consulta, la FSM que programa la EEPROM, usa como sel de reloj la
salida del oscilador a cristal (16Mhz en nuestro caso) o la
frecuencia del bus (24 Mhz generada por el PLL) ???
Ya que los calculos los hicimos en base a la frecuencia del oscilador
a cristal de 16 Mhz.
Saludos

Pedro Daniel Kolodka
Naviacom Argentina

--- In 6..., Agustin Pedroso wrote:
>
> Are you debugging with CodeWarrior3.1 or later??
>
> Write your own code to check if the bytes are properly written.
Don't
> believe what debugger says
>
> Here below, a portion of a flash driver:
>
> //******************************************************************
***********
> //* Function Name : Flash_Write_Word
> //* Description : Program a given Flash location using address
and data
> //* passed from calling function.
> //*
> //******************************************************************
***********
> signed char Flash_Write_Word(unsigned char page,unsigned int *
address,
> unsigned int data)
> {
> unsigned char thisPage;
>
> if((unsigned int)address & 0x0001) {return Flash_Odd_Access;} //
> Aligned word?
> if(readPagedAddress(page,address)!= 0xFFFF){return
> Flash_Not_Erased;} // Is it erased?
>
> // Error Bits must be cleared for all blocks
> ClearErrorBlocks();
>
> // PPAGE and BNKSEL (Flash Bank Register Selection)
> thisPage = PPAGE; //lmg 2/02/06
>
> //Don't put breakpoints in code between these dashed lines
> //-----------------------------
> PPAGE = page;
> FCNFG = GetBNKSEL(PPAGE);
> if(FSTAT_CBEIF == 1) // If cmd queue can accept another cmd
> {
> (*address) = data;
> FCMD = PROG;// Store programming command in FCMD
> (void)DoOnStack(page);// just passed for PPAGE
>
> PPAGE = thisPage;
> //----------------------------
> if (FSTAT_ACCERR) {return Access_Error;}
> if (FSTAT_PVIOL) {return Protection_Error;}
>
> while (FSTAT_CCIF != 1){} // Wait for command completion
> }
> else
> {
> return FULL_QUEUE_ERROR; // Cmd queue can not accept another
cmd
> }
> // CHECK IF THE WORD WAS WRITTEN PROPERLY
> if(readPagedAddress(page,address) == data) return OK;
> else return CHECK_WRITE;
> }
> ////////////////////////////////////////////////////////////////////
//////
> // FNC: function to read from paged memory area
> //
> unsigned int readPagedAddress(unsigned char page, unsigned int
*address)
> {
> unsigned char thisPage;
> unsigned int content;
>
> thisPage = PPAGE;
> PPAGE = page;
> content =(unsigned int) *address;
> PPAGE = thisPage;
>
> return content;
> }
>
>
> Guillermo F. Molina escribi
> >
> > Daniel,
> > Take a look at:
> >
> > AN2204, Fast NVM Programming for the MC9S12DP256
> >
> > You can find it and download it at the Freescale DP256 product
page.
> >
> > Rgds,
> > Guillermo.
> >
> > > -----Mensaje original-----
> > > De: 6...

































Hola,

>Te hago una
>consulta, la FSM que programa la EEPROM, usa como sel de reloj la
>salida del oscilador a cristal (16Mhz en nuestro caso) o la
>recuencia del bus (24 Mhz generada por el PLL) ???

En la pagina 6 de la AN2400/D se dice:
"The oscillator is used as a clock source so that programming and ensure
is independent of changes in the MCU bus frequency"

La frecuencia de la maquina de estados que programa la flash y la EEPROM
no depende de la frecuencia del BUS sino de la del oscilador del micro
(en mi caso tambi es 16 MHZ). Te paso la rutina que inicializa la
flash segun la AN2720:

La llamada a la rutina se hace pasando la frecuencia en KHz
------------------------------
// Inicializacion de la flash
Flash_Init(16000);
//-------------------

RUTINA DE INICIALIZACION DE LA FLASH

// AGUS: Sacado de s12_fectl.h
#define FDIV8 0x40 /*bit masks */

//*****************************************************************************
//* Function Name : Flash_Init
//* Description : Initialize Flash NVM for HC9S12 by programming
//* FCLKDIV based on passed oscillator frequency, then
//* uprotect the array, and finally ensure PVIOL and
//* ACCERR are cleared by writing to them.
//*
//*****************************************************************************
//
void Flash_Init(unsigned long oscclk)
{
unsigned char fclk_val;

// El reg FCLKDIV solo se puede inicializar una vez
// Check if clock divider has been loaded since last reset
if(FCLKDIV_FDIVLD == FALSE)
{
/* Next, initialize FCLKDIV register to ensure we can program/erase */
if (oscclk >= 12000)
{
fclk_val = oscclk/8/200 - 1; /* FDIV8 set since above 12MHz
clock */
fclk_val |= FDIV8 ;
FCLKDIV |= fclk_val;
FCLKDIV = FCLKDIV | fclk_val| FDIV8;
}
else
{
fclk_val = oscclk/8/200 - 1;
FCLKDIV = FCLKDIV | fclk_val;
}
}
FPROT = 0xFF; /* Disable all protection (only in special modes)*/
FSTAT = FSTAT | (FSTAT_PVIOL_MASK|FSTAT_ACCERR_MASK);/* Clear any
errors */
}
danielkolodka2002 escribi
>
> Gracias Agustin. Te comento, estamos con la aplicaci desarrollada
> con el ICC 12(image craft compiler), de todos modos vamos a seguir la
> rutina que nos enviaste hecha para el metrowerk. Te hago una
> consulta, la FSM que programa la EEPROM, usa como sel de reloj la
> salida del oscilador a cristal (16Mhz en nuestro caso) o la
> frecuencia del bus (24 Mhz generada por el PLL) ???
> Ya que los calculos los hicimos en base a la frecuencia del oscilador
> a cristal de 16 Mhz.
> Saludos
>
> Pedro Daniel Kolodka
> Naviacom Argentina
>
> --- In 6...

























&