EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Flash programming MC9S08

Started by kris73kris August 29, 2005
Hi,

I using MC9S08GT60.
Where is error?

Kris.

linker.prm
///////////////////////////////////////////////////////////////////
/* This is a linker parameter file for the GT60 */
NAMES END /* CodeWarrior will pass all the needed files to the linker
by command line. But here you may add your own files too. */

SEGMENTS /* here all RAM/ROM areas of the device are listed. Used in
PLACEMENT below. */
Z_RAM = READ_WRITE 0x0080 TO 0x00FF;
RAM = READ_WRITE 0x0100 TO 0x107F;
ROM = READ_ONLY 0x182C TO 0xFEFF;
ROM2 = READ_ONLY 0x1080 TO 0x17FF;
EEPROM = NO_INIT 0x7000 TO 0x700D;
END

PLACEMENT /* here all predefined and user segments are placed into the
SEGMENTS defined above. */
DEFAULT_ROM INTO ROM /*, ROM2*/; /* in case you
want to use ROM here as well, add option -OnB=b to the compiler. */
DEFAULT_RAM INTO RAM;
EEPROM_DATA INTO EEPROM;
_DATA_ZEROPAGE, MY_ZEROPAGE INTO Z_RAM;
END

STACKSIZE 0x200

VECTOR 0 _Startup

main.c
///////////////////////////////////////////////////////////////////
#define BUSCLK_FREQ_KHZ 3670
#if (((BUSCLK_FREQ_KHZ/200) % 1) == 0)
#define FCLK_PRESCALER BUSCLK_FREQ_KHZ/200
#else
#define FCLK_PRESCALER BUSCLK_FREQ_KHZ/200 - 1
#endif
#define FCLK_FREQ_KHZ (BUSCLK_FREQ_KHZ / (1 + FCLK_PRESCALER))

#ifndef ALIGNED_WORD_MASK
#define ALIGNED_WORD_MASK 0x01
#endif

#ifndef PASS
#define PASS 1
#endif

#ifndef FAIL
#define FAIL 0
#endif #define PROG_BYTE 0x20
#define PROG_BYTE_BURST 0x25 #pragma DATA_SEG EEPROM_DATA
byte tab2[7];
#pragma DATA_SEG DEFAULT

byte ProgFlash(byte* progAdr, byte* bufferPtr, byte size)
{

if(((byte)progAdr & ALIGNED_WORD_MASK) != 0) /* Check for aligned
word */
{
return(FAIL);
}

FCNFG = 0;
FPROT = 0xc0;
FSTAT = 0x30;

if(FSTAT_FACCERR) FSTAT_FACCERR = True;
FCDIV = FCLK_PRESCALER;

while(size != 0)
{
/* Is the command buffer empty? */
while(!FSTAT_FCBEF);
/* Write word to FLASH buffer. */
*progAdr++ = *bufferPtr++;
/* Initiate program command */
FCMD = PROG_BYTE_BURST;
/* Clear command buffer empty flag by writing a 1 to it
This launches the command. */
FSTAT_FCBEF = True;
// ------------UWAGA instrukcji nop moe by8 lub 10
!!!!!!!!!!!!!!!!!!!!!!!!!!!!
asm
{
nop
nop
nop
nop
nop
nop
nop
nop
}
/* Was the access error flag set */
/* Was the protection violation error flags set */
if((FSTAT_FACCERR) || (FSTAT_FPVIOL))
{
return(FAIL);
}
/* One less word to program */
/* One less word to write */
size--;
}/* wait for last command to complete */
while(!FSTAT_FCCF);
return(PASS);
}



The 2024 Embedded Online Conference