Flash programming using uProg1flash and uErasePages / 9S08QG8

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

Flash programming using uProg1flash and uErasePages / 9S08QG8

2,414 Views
eskomj
Contributor I

Hello,

 

I have searched and read several discussions concerning flash erase and program on hcs08 device. Particularly I have to find solution for the 9S08QG8. Most of methods presented in the forum are using their own copyToRam() etc. method. But how can I use methods allready in monitor program; uProg1Flash and uErasePages. As I have understood, those method use doOnStack() subroutine which is also in monitor rom. I shouldn't need anything else than those subroutines and flash register initialization. I am bit confused how to use that pseudo vector mechanism.

 

 

;*********************************************************************
;* Jump table for utility subroutines
;*********************************************************************
uProg1flash:jmp   Prog1flash  ;program (A) into flash at (H:X)
uErasePages:jmp   ErasePages  ;page-erase a block of flash

 

regards,

 

Esko

Labels (1)
0 Kudos
7 Replies

555 Views
eskomj
Contributor I

Here is comments of uProg1Flash subroutine.

 

;*********************************************************************
;* Prog1flash - programs one byte of FLASH
;*  This routine waits for the command to complete before returning.
;*  assumes location was blank. This routine can be run from FLASH
;*
;* On entry... H:X - points at the FLASH byte to be programmed
;*             A holds the data for the location to be programmed
;*
;* Calling convention:
;*          jsr    Prog1flash
;*
;* Uses: DoOnStack which uses SpSub
;* Returns: H:X unchanged and A = FSTAT shifted left by 2 bits
;*  Z=1 if OK, Z=0 if protect violation or access error
;*  uses 32 bytes of stack space + 2 bytes for BSR/JSR used to call it
;*********************************************************************

 

0 Kudos

555 Views
peg
Senior Contributor IV

Hello Esko,

 

There is no ROM in a QG8!

There is no built in monitor in a QG8!

Are you possibly referring to a FLASH resident bootloader? If so then the same restrictions apply, although you would be able to utilise the programming routines from within it.

0 Kudos

555 Views
bigmac
Specialist III

Hello Esko,

 

It is not clear what you are attempting to do.  Are you trying to program your code into the device, or alternatively, from within your code do you require to save some data that must remain non-volatile?

 

As Peg has already asked, if you are programming your code, are you using a resident serial bootloader (that initially also needs to be programmed into the device)?

 

Regards,

Mac

 

0 Kudos

555 Views
eskomj
Contributor I

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++;
   }
}

0 Kudos

555 Views
bigmac
Specialist III

Hello Esko,

 

I think that the source of the confusion is that some of the smaller devices from the older HC908 family did have monitor ROM because there was very limited RAM capacity for RAM based code.

 

However, the more recent HCS08 family, including the 'QG8, do not have an in-built monitor.  The code required for erasing and programming flash is simpler than the older family because the timing requirements are handled within the hardware.

 

The code snippet that you posted shows only the RAM based code, and the means of loading it to RAM. Additional code is required that calls the RAM function with the required parameters.  Refer to the attached files for the full code.

 

The PRM file must also be setup so that the code will be relocated to the required position.  The attached PRM file positions the stack to the top of RAM, and then uses the lower reaches of the stack for the RAM based code.

 

Regards,

Mac

 

0 Kudos

555 Views
eskomj
Contributor I

Thank you Mac,

 

I will try with those.

 

regards,

 

Esko

0 Kudos

555 Views
eskomj
Contributor I
Do I need some modification in .prm file for the code in a previous reply ?
I tried above code in the simulator and it seemed like Flash_Cmd() function was copied into the flash area.  I know, simulator can't simulate flash functions, but I liked to see that Flash_Cmd() function copied correctly into the ram area.
0 Kudos