Message Edited by rocco on 04-02-200602:00 PM
Hi Rocco & Tony,
The problem on the GP was on some of HC08 family.
QG and GB are S08 and use a completely different technology from HC08.
Therefore we can't make any comparison between these.
I have never heard of any problem on S08 Flash yet.
Cheers,
Alban.
Hi guys,
nah, I'm all right and wasn't getting nervous at all
Still I think you can compare the S08 to the S12 for the Flash but nor really for HC08. First reason being the state machine it uses with commands instead of timings for you to manage...
Alban
Ah, yes, I see your point now, after reading over the flash programming chapters for both parts. I guess I will have to experiment some, as I also need to reduce the ram footprint of my boot loaders.
Alban wrote:. . . First reason being the state machine it uses with commands instead of timings for you to manage...
That's right. I never said there was a problem with Flash programming, just that I was looking for way to reduce the RAM required (especially for the QG8), and that the manuals leave unanswered the question of 'when exactly' flash access is inhibited.
Anyway, I managed to shorten the example code given in Fig. 4-12 of the HCS08 Family Reference Manual from 24 bytes to 21 bytes + 2 for the JSR/BSR.
This was done by making these changes (RAM portion of code listed below):
1. Preload A with the value to write just before calling the routine.
2. Use immediate addressing mode for the loading of the command byte.
3. Have the loader patch the address in STA FLASH with the actual address that eliminating the need to load HX inside the routine and then use STA ,X. (We couldn't possibly avoid using HX for calling the RAM routine because any other method would mean extra stack used by the loader portion, so the benefit would be lost.)
But I had hoped to do even better by being able to the "sta FLASH" and "lda...sta FCMD" outside this routine.
;*******************************************************************************
; Purpose: RAM routine to do the job we can't do from Flash
; Input : A = value to program
; Note(s): This routine is modified in RAM by its loader at @2,3 and @5
; : Stack needed: 21 bytes + 2 for JSR/BSR
?RAM_Execute sta FLASH ;FLASH (@2,@3) is replaced
lda #mByteProg ;mByteProg (@5) is replaced
sta FCMD ;Step 2 - Write command to FCMD
lda #FCBEF_
sta FSTAT ;Step 3 - Write FCBEF_ in FSTAT
nop ;required delay
?RAM_Execute.Loop lda FSTAT ;Step 4 - Wait for completion
lsla ;check FCCF_ for completion
bpl ?RAM_Execute.Loop
?RAM_Execute_End rts ;on exit, A has non-zero if error
?RAM_Needed equ *-?RAM_Execute
Here's an improved version, one byte shorter. Instead of NOP we use LSRA which provides the same delay but also leaves A with only FCCF bit set. Later, instead of "LOOP: LDA FSTAT, LSLA, BPL LOOP" we use the mask already in A to do "LOOP: BIT FSTAT, BEQ LOOP"
We can check for errors once we exit this RAM routine, from the Flash portion, by loading FSTAT and checking for FPVIOL and FACCERR.
;*******************************************************************************
; Purpose: RAM routine to do the job we can't do from Flash
; Input : A = value to program
; Output : None
; Note(s): This routine is modified in RAM by its loader at @2,3 and @5
; : Stack needed: 20 bytes + 2 for JSR/BSR
?RAM_Execute sta EEPROM ;Step 1 - Latch data/address
;EEPROM (@2,@3) replaced
lda #mByteProg ;mByteProg (@5) replaced
sta FCMD ;Step 2 - Write command to FCMD
lda #FCBEF_
sta FSTAT ;Step 3 - Write FCBEF_ in FSTAT
lsra ;min delay before checking FSTAT
;(FCBEF -> FCCF for later BIT)
?RAM_Execute.Loop bit FSTAT ;Step 4 - Wait for completion
beq ?RAM_Execute.Loop ;check FCCF_ for completion
?RAM_Execute_End rts
;after exit, check FSTAT for FPVIOL and FACCERR
?RAM_Needed equ *-?RAM_Execute
Message Edited by tonyp on 04-20-200603:24 PM
Message Edited by rocco on 04-20-200603:45 PM
Message Edited by rocco on 04-20-200603:45 PM
Message Edited by tonyp on 04-21-200602:04 AM
Message Edited by tonyp on 04-21-200602:34 AM