EmbeddedRelated.com
Forums
Memfault Beyond the Launch

How to erase Block 0

Started by montserret_maxime January 13, 2006
Hi,

I'm working on MC9S12DG256B chip and I'd like to erase first block in
flash : boot block.
For that, I think I must erase sector by sector but I don't know which
value I must put in PPAGE register and FCNFG register.

Many thanks in advance for your help.


Hi Maxime.

I did not get any time to review your previously posted code.
But you can surely translate the following script in C code.

wb = write byte
ww = write short (word)

note that the WAIT should be replaced by " while(FSTAT_CCIF == 0); ".

Also note that if some registers are set twice, this is due to the fact
that the original script has a "reset" in the middle.

Don't forget to run this from ram.

Regards,
Gilles //mass erase flash

wb 0x03c 0x00 //disable cop
wb 0x100 0x49 // set FCLKDIV clock divider
wb 0x104 0xFF // FPROT all protection disabled
wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
ww 0x108 0xFFFE
ww 0x10A 0xFFFF
wb 0x106 0x41 // write MASS ERASE command in FCMD register
wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
wait 20 // wait for command to complete
// program security byte to "unsecure" state

wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
wb 0x100 0x49 // set twice FCLKDIV clock divider
wb 0x100 0x49
wb 0x104 0xFF // FPROT all protection disabled
wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
wb 0x105 0x02
ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
wait 20 // wait for command to complete
At 10:31 AM 1/13/2006, you wrote:
>Hi,
>
>I'm working on MC9S12DG256B chip and I'd like to erase first block in
>flash : boot block.
>For that, I think I must erase sector by sector but I don't know which
>value I must put in PPAGE register and FCNFG register.
>
>Many thanks in advance for your help. >
>
>Yahoo! Groups Links >
>




Many thanks for a new time.
But I don't want to erase entire Flash in one time but only some
sectors in Block 0 (Boot Block).
I don't know the way to do that.
Thanks a lot. --- In 68HC12@68HC..., Gilles Blanquin <gilles.blanquin@f...>
wrote:
>
> Hi Maxime.
>
> I did not get any time to review your previously posted code.
> But you can surely translate the following script in C code.
>
> wb = write byte
> ww = write short (word)
>
> note that the WAIT should be replaced by " while(FSTAT_CCIF == 0); ".
>
> Also note that if some registers are set twice, this is due to the fact
> that the original script has a "reset" in the middle.
>
> Don't forget to run this from ram.
>
> Regards,
> Gilles > //mass erase flash
>
> wb 0x03c 0x00 //disable cop
> wb 0x100 0x49 // set FCLKDIV clock divider
> wb 0x104 0xFF // FPROT all protection disabled
> wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> wb 0x105 0x02
> wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
> ww 0x108 0xFFFE
> ww 0x10A 0xFFFF
> wb 0x106 0x41 // write MASS ERASE command in FCMD register
> wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> wait 20 // wait for command to complete >
> // program security byte to "unsecure" state
>
> wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> wb 0x105 0x02
> wb 0x100 0x49 // set twice FCLKDIV clock divider
> wb 0x100 0x49
> wb 0x104 0xFF // FPROT all protection disabled
> wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> wb 0x105 0x02
> ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
> wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
> wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> wait 20 // wait for command to complete >
> At 10:31 AM 1/13/2006, you wrote:
> >Hi,
> >
> >I'm working on MC9S12DG256B chip and I'd like to erase first block in
> >flash : boot block.
> >For that, I think I must erase sector by sector but I don't know which
> >value I must put in PPAGE register and FCNFG register.
> >
> >Many thanks in advance for your help.
> >
> >
> >
> >
> >
> >
> >
> >Yahoo! Groups Links
> >
> >
> >
> >
>



Hi Maxime.
In assembler.
I hope this help.
If you erase around $FF00, don't forget to reprogram the security byte to
$FE (if necessary)
Regards,
Gilles ; erase sector
MOVB #$3F, PPAGE ; force to page $3F
movb #0, FCNFG ; assert block 0
movb #$A4, FPROT ; remove all access protection
MOVB FSTAT, FSTAT ; to clear an unknown flag
clr FTSTMOD ; clear WRALL
movb #2, FSTAT ; set RESERR
std $F000 ; latch address for erase command (sector
at $F000 to $F1FF / 512 bytes)
ldab #ERASE ; perform a sector erase. #$40
stab FCMD
ldab #CBEIF
stab FSTAT ; run command.
brset FSTAT,#ACCERR, ACCError ; Check ACCError
brset FSTAT,#PVIOL, PviolError ; Check PviolError
brclr FSTAT,#CCIF,* ; wait until the command has
completed.
At 01:49 PM 1/13/2006, you wrote:
>Many thanks for a new time.
>But I don't want to erase entire Flash in one time but only some
>sectors in Block 0 (Boot Block).
>I don't know the way to do that.
>Thanks a lot. >--- In 68HC12@68HC..., Gilles Blanquin <gilles.blanquin@f...>
>wrote:
> >
> > Hi Maxime.
> >
> > I did not get any time to review your previously posted code.
> > But you can surely translate the following script in C code.
> >
> > wb = write byte
> > ww = write short (word)
> >
> > note that the WAIT should be replaced by " while(FSTAT_CCIF == 0); ".
> >
> > Also note that if some registers are set twice, this is due to the fact
> > that the original script has a "reset" in the middle.
> >
> > Don't forget to run this from ram.
> >
> > Regards,
> > Gilles
> >
> >
> >
> >
> >
> > //mass erase flash
> >
> > wb 0x03c 0x00 //disable cop
> > wb 0x100 0x49 // set FCLKDIV clock divider
> > wb 0x104 0xFF // FPROT all protection disabled
> > wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
> > ww 0x108 0xFFFE
> > ww 0x10A 0xFFFF
> > wb 0x106 0x41 // write MASS ERASE command in FCMD register
> > wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> > wait 20 // wait for command to complete
> >
> >
> >
> > // program security byte to "unsecure" state
> >
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > wb 0x100 0x49 // set twice FCLKDIV clock divider
> > wb 0x100 0x49
> > wb 0x104 0xFF // FPROT all protection disabled
> > wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
> > wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
> > wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> > wait 20 // wait for command to complete
> >
> >
> >
> > At 10:31 AM 1/13/2006, you wrote:
> > >Hi,
> > >
> > >I'm working on MC9S12DG256B chip and I'd like to erase first block in
> > >flash : boot block.
> > >For that, I think I must erase sector by sector but I don't know which
> > >value I must put in PPAGE register and FCNFG register.
> > >
> > >Many thanks in advance for your help.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >Yahoo! Groups Links >
>




--- In 68HC12@68HC..., "montserret_maxime"
<montserret_maxime@y...> wrote:
>
> Hi,
>
> I'm working on MC9S12DG256B chip and I'd like to erase first block in
> flash : boot block.
> For that, I think I must erase sector by sector but I don't know which
> value I must put in PPAGE register and FCNFG register.
>
> Many thanks in advance for your help.
>

Do you know that "block" means only 4 consecutive PPAGE numbers? So
Bulk erase is not All 256K, just one 64K block. I ask because I did
not see how many sectors you want erased. If less than 64K to erase,
then only way is sector by sector. Hopefully the other responses have
answered how to do that. --jeffs


Hi,

Freescale application note AN2400/D, "HCS12 NVM Guidelines", available on
the Freescale web site, tells you almost everything you need to know about
flash and flash programming in one place.

If you haven't read it, you will likely find it interesting and informative.

Steve Russell
Nohau Emulators

At 04:49 AM 1/13/2006, "montserret_maxime" <montserret_maxime@mont...> wrote:
>Many thanks for a new time.
>But I don't want to erase entire Flash in one time but only some
>sectors in Block 0 (Boot Block).
>I don't know the way to do that.
>Thanks a lot. >--- In 68HC12@68HC..., Gilles Blanquin <gilles.blanquin@f...>
>wrote:
> >
> > Hi Maxime.
> >
> > I did not get any time to review your previously posted code.
> > But you can surely translate the following script in C code.
> >
> > wb = write byte
> > ww = write short (word)
> >
> > note that the WAIT should be replaced by " while(FSTAT_CCIF == 0); ".
> >
> > Also note that if some registers are set twice, this is due to the fact
> > that the original script has a "reset" in the middle.
> >
> > Don't forget to run this from ram.
> >
> > Regards,
> > Gilles
> >
> >
> >
> >
> >
> > //mass erase flash
> >
> > wb 0x03c 0x00 //disable cop
> > wb 0x100 0x49 // set FCLKDIV clock divider
> > wb 0x104 0xFF // FPROT all protection disabled
> > wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > wb 0x102 0x10 // set the WRALL bit in FTSTMOD to affect all blocks
> > ww 0x108 0xFFFE
> > ww 0x10A 0xFFFF
> > wb 0x106 0x41 // write MASS ERASE command in FCMD register
> > wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> > wait 20 // wait for command to complete
> >
> >
> >
> > // program security byte to "unsecure" state
> >
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > wb 0x100 0x49 // set twice FCLKDIV clock divider
> > wb 0x100 0x49
> > wb 0x104 0xFF // FPROT all protection disabled
> > wb 0x105 0x30 // clear PVIOL and ACCERR in FSTAT register
> > wb 0x102 0x00 // clear the WRALL bit in FTSTMOD
> > wb 0x105 0x02
> > ww 0xFF0E 0xFFFE // write security byte to "Unsecured" state
> > wb 0x106 0x20 // write MEMORY PROGRAM command in FCMD register
> > wb 0x105 0x80 // clear CBEIF in FSTAT register to execute the command
> > wait 20 // wait for command to complete
> >
> >
> >
> > At 10:31 AM 1/13/2006, you wrote:
> > >Hi,
> > >
> > >I'm working on MC9S12DG256B chip and I'd like to erase first block in
> > >flash : boot block.
> > >For that, I think I must erase sector by sector but I don't know which
> > >value I must put in PPAGE register and FCNFG register.
> > >
> > >Many thanks in advance for your help.
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >Yahoo! Groups Links
> > >
> > >
> > >
> > >
> >Yahoo! Groups Links >
>





Memfault Beyond the Launch