Okey, I had an erroneous impression that monitor program is part of BDC and already resides on protected area (at the end) of the flash memory. I am trying to save some data to the flash memory. I would like to use simplest possible way.
I thought simplest way to do that, is use of monitor program, but then it's not. In the HCS08 Family Reference manual is said like that:
"This bootloader resides in protected FLASH at the high-address end of the FLASH and
works through the asynchronous serial communications interface (SCI1) of the MC9S08GB60 to allow a user to program or erase FLASH, or debug user applications."
I found one (Mac's) solution from forum. Is that what I need ?
extern char __SEG_START_FLASH_ROUTINE[];
extern char __SEG_SIZE_FLASH_ROUTINE[];
/* Private function prototype */
#pragma CODE_SEG FLASH_ROUTINE
void Flash_Cmd( void);
#pragma CODE_SEG DEFAULT
/*****************************************************************************/
#pragma CODE_SEG FLASH_ROUTINE
/* This function is loaded to RAM, and executed from there.
The size of the function is 10 bytes.
On entry, ACC must contain FCBF mask value (0x80),
and H:X the address of FSTAT register */
void Flash_Cmd( void)
{
__asm {
STA ,X ; wp Commence flash command
LDA #$70 ; (2) FCCF|FACCERR|FPVIOL mask
L1: STA SRS ; (3) Reset COP required for page erase
BIT ,X ; rfp Test command status
BEQ L1 ; Loop while incomplete & no error
}
}
#pragma CODE_SEG DEFAULT
/*****************************************************************************/
/* Copies Flash_Cmd() function into RAM, with steps documented in Tech Note 228
Start_data refers to the begining of the flash block to be copied.
*/
#define Start_data __SEG_START_FLASH_ROUTINE
#define Size_data __SEG_SIZE_FLASH_ROUTINE
void CopyInRAM(void)
{
char *srcPtr, *dstPtr;
int count;
srcPtr = (char *)Start_data;
dstPtr = (char *)(void *)&Flash_Cmd;
for (count = 0; count < (int)Size_data; count++) {
*dstPtr = *srcPtr;
dstPtr++;
srcPtr++;
}
}