MC9S12KG256 FLASH bank 1 erased, but not programming
I am working the MC9S12KG256 and writing flash driver to program CPU. Code executed from RAM.
FLASH memory is fully unsecured, FPROT for bank 0 is $84, for bank 1 is $FF.
Call to EraseFL (B=$00,A=$00) succesfully erases all FLASH sectors except protected.
Call to WriteFL succesfully program only bank 0. For bank 1 it doesn't return any error on programming stage, but there is no data programmed, so comparsion always failed.
Is it my fault or i miss something from datasheet?
Driver code below:
InitFLASH: brset FCLKDIV,#%10000000,IF_Skip
IF_Skip: movb #%110000,FSTAT
ExecFLASHCmd: ; C set on error
EFC_Wait: jsr AckCOP
WaitFLASHCmd: ; C set on error
EraseFL: ; > B - StartPage; A - Count
EraseFL_Loop: ldab 0,sp
EFL_Error: bsr WaitFLASHCmd
SelectFLASH: brset PPAGE,#$08,SFL_M0
SFL_M0: clr FCNFG
; program $40 bytes from PgmPtr to PgmAddr[8000..BFFF] (PPAGE already set)
WriteFL: ; < B - 0=OK
WriteFL_PLoop: movw 2,x+,2,y+
WriteFL_Wait: bsr WaitFLASHCmd
WriteFL_CLoop: ldab a,x
WriteFL_Err: ldab FSTAT
WriteFL_CErr: ldab #$CE
I am trying to write a routine that will
program flash bytes at the security location in fixed memory at location
$ff00. The flash is unsecured (FSEC = 0xfe) All the code is executed
from RAM. The first thing I want to do is erase the sector with command
$40. The FCLKDIV is set to program at just under 200khz, PVIOL and
ACCERR is checked for all banks, the bank is reset to bank 0 (FCNFG = 0)
the sector address is sent by writing something to $fe00, then the
command to erase the sector is sent (0x40 to FCMD). But as soon as that
is done, the ACCERR is set in the FSTAT register. I can't understand
why, this is a valid command and all the other conditions seem to be OK.
Does anyone have any insight on this?, thanks in advance. Oh, and PPAGE
is $3f, but the doc says it doesn't matter when programming fixed
- Kevin Longworth
absolute rather than relative addressing? Is the subroutine located
in a common page?
At 12:52 PM 3/26/2010, you wrote:
>I am working the MC9S12KG256 and writing flash driver to program
>CPU. Code executed from RAM.
>ExecFLASHCmd: ; C set on error
> movb #%10000000,FSTAT
>EFC_Wait: jsr AckCOP
> brclr FSTAT,#%10000000,EFC_Wait
> ldab FSTAT
> andb #$30
> addb #$FF
>WaitFLASHCmd: ; C set on error
> jsr AckCOP
> brclr FSTAT,#%1000000,WaitFLASHCmd
> bra ChkFLASH
26/03/2010, 22:23:26 you wrote:
WRE> Where is the subroutine 'AckCOP' located? Does this call use
WRE> absolute rather than relative addressing? Is the subroutine located
WRE> in a common page?
AckCOP is also in RAM (at $30CE). FLASH routines located from $3625.
AckCOP: movb #$55,ARMCOP
>>I am working the MC9S12KG256 and writing flash driver to program
>>CPU. Code executed from RAM.
>>ExecFLASHCmd: ; C set on error
>> movb #%10000000,FSTAT
>>EFC_Wait: jsr AckCOP
>> brclr FSTAT,#%10000000,EFC_Wait
>> ldab FSTAT
>> andb #$30
>> addb #$FF
>>WaitFLASHCmd: ; C set on error
>> jsr AckCOP
>> brclr FSTAT,#%1000000,WaitFLASHCmd
>> bra ChkFLASH