Maker Pro
Maker Pro

for freescaler :9s12,no way to clear CBEIF flag

B

blisca

Jan 1, 1970
0
hi,
i'm trying to save some data on flash with a 9s12e64 freescale MCU,
following instruction on application notes and examples
i did the following steps

1)set FCLKDIV to have the flash clock in the right range
2)do an ordinary write,data does'nt matter, in the sector that i want erase
3)put an erase command($40) in the FCMD register
3)then clear CBEIF bit in FSTAT by LDAA #$80 followed by STAA FSTAT
then i check the bit with a BITA instructtion ,then branching if the bit
results still set

at this point the CBEIF bit remains high

can anyone show me where my error is?thank you!

Diego
 
Y

Yuriy K.

Jan 1, 1970
0
blisca said:
hi,
i'm trying to save some data on flash with a 9s12e64 freescale MCU,
following instruction on application notes and examples
i did the following steps

1)set FCLKDIV to have the flash clock in the right range
2)do an ordinary write,data does'nt matter, in the sector that i want erase
3)put an erase command($40) in the FCMD register
3)then clear CBEIF bit in FSTAT by LDAA #$80 followed by STAA FSTAT
then i check the bit with a BITA instructtion ,then branching if the bit
results still set

at this point the CBEIF bit remains high

can anyone show me where my error is?thank you!

Did you execute this code from RAM? You can not execute from FLASH and
program it.
 
B

blisca

Jan 1, 1970
0
ye
Yuriy K. said:
Did you execute this code from RAM? You can not execute from FLASH and
program it.

Yes i did it,i copied the code in RAM,anyway thanks Yuriy
 
Y

Yuriy K.

Jan 1, 1970
0
blisca said:
Yes i did it,i copied the code in RAM,anyway thanks Yuriy

Did you unsecure the FLASH memory before trying to program/erase?

flash_init:
movb #20,FCLKDIV ; FCLK = 4/(20+1) = 0.180 MHz
movb #0x82,FSEC ; FSEC = 1000 0010 - unsecured
movb #0x00,FCNFG ; see FTS64K Block User guide

movb #0xCF,FPROT ; 7 FPOPEN : 1 - Not protected
; 6 -
; 5 FPHDIS : 0 - Higher
protection enabled
; 4 FPHS1 -: 01 - 4K Boot Block
; 3 FPHS0 /
; 2 FPLDIS : 1 - Lower
protection disabled
; 1 FPLS1 -: 11 - 4K Boot Block
; 0 FPLS0 /
rts

FPROT may be different in your case.
 
B

blisca

Jan 1, 1970
0
Yuriy K. said:
blisca wrote:


Did you unsecure the FLASH memory before trying to program/erase?

flash_init:
movb #20,FCLKDIV ; FCLK = 4/(20+1) = 0.180 MHz
movb #0x82,FSEC ; FSEC = 1000 0010 - unsecured
movb #0x00,FCNFG ; see FTS64K Block User guide

movb #0xCF,FPROT ; 7 FPOPEN : 1 - Not protected
; 6 -
; 5 FPHDIS : 0 - Higher
protection enabled
; 4 FPHS1 -: 01 - 4K Boot Block
; 3 FPHS0 /
; 2 FPLDIS : 1 - Lower
protection disabled
; 1 FPLS1 -: 11 - 4K Boot Block
; 0 FPLS0 /
rts

FPROT may be different in your case.
Thanks again Yuriy,tryin right now
 
B

blisca

Jan 1, 1970
0
blisca said:
Thanks again Yuriy,tryin right now
okthanks to you now something changes in flash ,
but i can't understand why when i erase the sector with 0x40 in FCMD and
sending 80 to FSTAT i have the entire blocks 0x4000 to 0x8000 and
0xC000 to 0xFFFF filled with strange values: 10 and 4F,can you help me again

i do the erasing performing an ordinary write at 0x5200,or 0xC200,expecting
that only the sector containing the address that i choose would be erased
can you or someone help me again ,please?
 
B

blisca

Jan 1, 1970
0
ok,your hints helped me a lot,the last problem was due to a trivial reason,i
deleted erroneously a row in my code so i did'nt program the FCLKDIV
register
(LDAA #$00101001 was not followed by STAA FCLKDIV),now it looks working

thanks thanks thanks Yuriy!!
 
Y

Yuriy K.

Jan 1, 1970
0
blisca said:
okthanks to you now something changes in flash ,
but i can't understand why when i erase the sector with 0x40 in FCMD and
sending 80 to FSTAT i have the entire blocks 0x4000 to 0x8000 and
0xC000 to 0xFFFF filled with strange values: 10 and 4F,can you help me again

No idea. Never seen anything like that.
IT is worth to double check FCLKDIV calculations.
i do the erasing performing an ordinary write at 0x5200,or 0xC200,expecting
that only the sector containing the address that i choose would be erased
can you or someone help me again ,please?

Sector erase:
;================================================
f_e_sec_non_blank:
ldx flash_addr

movb flash_word,0,X ; write aligned word inside sector
movb #0x40,FCMD ; Sector Erase command
movb #0x80,FSTAT ; clear CBEIF - start command
f_e_wait:
brset FSTAT,#0x10,f_e_err ; ACCERR
brset FSTAT,#0x20,f_e_err ; PIVOL
brclr FSTAT,#0x40,f_e_wait ; CCIF = 1 when command is
completed

....

Word programming:
;================================================
flash_func_program:

movb flash_page,PPAGE
ldx flash_addr
ldd 0,X
cpd #0xFFFF
bne f_p_err ; do not write non-erased word

movw flash_word,0,X ; write aligned word inside sector
movb #0x20,FCMD ; Word program
movb #0x80,FSTAT ; clear CBEIF - start command
f_p_wait:
brset FSTAT,#0x10,f_p_err ; ACCERR
brset FSTAT,#0x20,f_p_err ; PIVOL
brclr FSTAT,#0x40,f_p_wait ; CCIF = 1 when command is
completed
f_p_err:
rts
;------------------------------------------------
rseg UDATA1 ; temp variables

flash_func_ok: ds 1
flash_addr: ds 2
flash_page: ds 1
flash_word:
flash_word_h: ds 1
flash_word_l: ds 1
;====================================================================
 
B

blisca

Jan 1, 1970
0
ok,thanks to you now my program looks being able to write data in the
FLASH,i profit of your courtesy for other 2 questions:

I am using the 9s12E64 MCU having 64KB of memory; it looks that with 16bits
i could address linearly the whole memory
so ,why the need of the PPAGE block?Compatibility with 8 bit devices?

In my case i used the upper block(starting from $C000) for the code and i
used the FLASH starting from $ 4000 for variables to be stored,hopin that i
not did a bad choice.
i read in the Application notes and examples that one has to erase the whole
sector prior of writing a byte,and the sector should be 512 bytes wide;
why it happens that 1024 bytes are erased?

thank you for the n-th time!
 
Top