Graeme Coakley

Simplified Flash Erase and Write Functions for HCS08GT32

Discussion created by Graeme Coakley on Mar 14, 2006
Latest reply on Mar 29, 2006 by Graeme Coakley
Hello All,
 
I am trying to simplify the slfprg-s08gbgt.asm bootloader code to two basic functions: erase and write.  So far, I have not had much luck at this and the functions do not appear to change anything in memory.  I have attached what I have at the bottom of this posting.  Any help would be appreciated.  If someone has already done this, could you please post your solution.  Thank you.
 
-gcoakley
 
 
 
EraseFlashPage:
     LDHX    Address
     STHX    ADRS
     
     lda  #(mFPVIOL+mFACCERR) ;mask
  sta  FSTAT     ;abort any command and clear errors
  mov  #EraseSubSize, STAT ;length of flash erase routine to STAT
  tsx
  sthx STACK
  ldhx  #EraseSubEnd-1   ;point at last byte to move to stack
DoOnStack2:
  lda  ,x     ;read from flash
  psha      ;move onto stack
  aix  #-1    ;next byte to move
  dbnz STAT, DoOnStack2
EraseSub2:  
  ldhx  ADRS    ;get flash address
  sta  0,x    ;write to flash; latch addr and data
  lda  #mPageErase  ;get flash command
  sta  FCMD    ;write the flash command
  lda  #mFCBEF   ;mask to initiate command
  sta  FSTAT    ;[pwpp] register command
  nop      ;[p] want min 4~ from w cycle to r
ChkDoneErase2:
  lda  FSTAT    ;[prpp] so FCCF is valid
  lsla      ;FCCF now in MSB
  bpl  ChkDoneErase2  ;loop if FCCF = 0
   ldhx STACK
  txs
  rts
 
 
WriteFlashPage:
     LDHX  Address
     STHX  ADRS
     LDA   ALEN                ;load length
     STA   STAT
     STA   LEN
     LDHX  #Array              ;load array address
     STHX  ADRR
     
WR_DATA_L2:
     AIX     #1                ;add 1 to index register
     DBNZ    STAT,WR_DATA_L2   ;decrement & branch if not zero
     
     lda  #(mFPVIOL+mFACCERR) ;mask
     sta  FSTAT           ;abort any command and clear errors
     
     mov  #ProgSubSize, STAT ;length of flash prog routine to STAT
   tsx
   sthx STACK
   ldhx  #ProgSubEnd-1      ;point at last byte to move to stack
 DoOnStack3:
  lda  ,x     ;read from flash
  psha      ;move onto stack
  aix  #-1    ;next byte to move
  dbnz STAT, DoOnStack3
ProgSub2:  
  lda  FSTAT    ;check FCBEF
  and  #mFCBEF   ;mask it
  beq  ProgSub2   ;loop if not empty
  
  ldhx ADRR
  lda  0,x
  aix  #1
  sthx ADRR
  
  ldhx  ADRS    ;get flash address
  sta  0,x    ;write to flash; latch addr and data
  aix  #1
  sthx ADRS
  
  lda  #mBurstProg  ;get flash command
  sta  FCMD    ;write the flash command
  lda  #mFCBEF   ;mask to initiate command
  sta  FSTAT    ;[pwpp] register command
  dbnz LEN,ProgSub2  ;all bytes in a row?
ChkDoneProg2:
  lda  FSTAT    ;[prpp] so FCCF is valid
  lsla      ;FCCF now in MSB
  bpl  ChkDoneProg2  ;loop if FCCF = 0
  
  ldhx STACK
  txs
   rts

Outcomes