Prgramming HCS08 Flash - Help Needed

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

Prgramming HCS08 Flash - Help Needed

1,648 Views
Davo
Contributor II
I am creating some code to save configs in Flash on a HCS908QG8.  Single byte writes are fine. I created the code from scratch, but find it is locking-up the micro.  I then lifted the code from AN2496 and I get the same result. The problem occurs as soon as I issue the program command.
 
Any help is appreciated.  The code is listed below.
 
 
byte_pgm:    equ    $20           ;Command to program a single byte
; bit position masks
mFCBEF:     equ   %10000000   ;flash command buffer empty flag
mFCCF:      equ   %01000000   ;flash command complete flag
mFPVIOL:    equ   %00100000   ;flash protection violation
mFACCERR:   equ   %00010000   ;flash access error
mFBLANK:    equ   %00000100   ;flash verified as all blank (erased =$ff) flag
  sei
* Flash Routines Initialisation
 
  lda #!45
  sta rFCDIV   ;Set the flash clock divider register to produce 186kHz clock
  ldhx #vNVStorageStart ;Set up an address pointer
  sthx wAddrFlashWrite  ; "
  lda #'a'   ;Create some test data
  sta yFlashByte  ; "
  jsr COP_Reset

ProgFlashByte lda #mFPVIOL|mFACCERR ;error flag bits to clear if set
  sta rFSTAT   ;clear any error flags
  ldhx wAddrFlashWrite  ;Get address to program
  lda yFlashByte  ;Store the byte in flash
  sta ,X   ; "
  aix #1   ;Save address of next free config space in flash
  sthx wAddrFlashWrite  ; "
  lda #byte_pgm  ;page write command
  sta rFCMD   ;initiate the programming sequence
  lda rFSTAT
  ora #mFCBEF
  sta rFSTAT   ;launch the command
         nop    ;burn bus cycs before chking status
  nop
  nop
  nop
  nop
  lda rFSTAT   ;look at status register for errors
  and #mFPVIOL|mFACCERR ;error flag bits
  bne flash_error  ;check for programming errors
pgm_loop: lda rFSTAT   ;wait around unil prog'ing complete
  and #mFCCF   ;command complete yet?
  beq pgm_loop  ;not done yet..loop until complete
 
Labels (1)
0 Kudos
1 Reply

269 Views
thisobj
Contributor III
Hi Davo,

You didn't mention code location in your post, but code that programs flash memory locations must run in RAM.

Regards,

Frank

0 Kudos