Flash cannot be erased with "FTFE Erase Flash Sector Command"

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Flash cannot be erased with "FTFE Erase Flash Sector Command"

2,872 次查看
tera
Contributor I

I am using MKE16F256VLL16

Even if I execute the "Erase Flash Sector Command" of the FTFE function, the flash is not erased normally.

The sector you want to erase is the memory starting at 0x00010000

FTFE execution is done from RAM.

The execution result is error free.
However, when I check the memory, it is erased in spots.

tera_0-1676594473081.png

Please tell me how to solve this problem

0 项奖励
回复
9 回复数

2,793 次查看
tera
Contributor I

I think so.

The spec sheet has the following:
Erase Flash Sector execution time—max 115ms

I think it is necessary to wait the above time after executing FTFE_CommandExecute().
That's because when I ran the program a little and checked the memory, it was erased.

Therefore, I made a program to check the memory after waiting for the above time, but the erasure was never completed.
I think it's probably due to time and other conditions.

Are there any conditions for flash erasing other than time and security?
Also, is my thinking correct?

0 项奖励
回复

2,799 次查看
tera
Contributor I

uint8_t FTFE_CommandExecute() __attribute__((section(".ARM.__at_0x20000000")));

uint8_t FTFE_CommandExecute()

{

    FTFE->FSTAT |= ( FTFE_FSTAT_RDCOLERR(1) | FTFE_FSTAT_ACCERR(1) | FTFE_FSTAT_FPVIOL(1) );
    FTFE->FSTAT |= FTFE_FSTAT_CCIF(1);
    while( (FTFE->FSTAT & FTFE_FSTAT_CCIF_MASK) ){
        __asm("NOP");
    }
    while( !(FTFE->FSTAT & FTFE_FSTAT_CCIF_MASK) ){
        __asm("NOP");
    }
    return FTFE->FSTAT;
}

 

main()

{

    address=0x00010000;

    FTFE->FCCOB0 = 0x09;
    FTFE->FCCOB1 = (address>>16) & 0x000000FF;
    FTFE->FCCOB2 = (address>> & 0x000000FF;
    FTFE->FCCOB3 = address & 0x000000FF;

    __disable_irq(); 
    FTFE_CommandExecute();
    __enable_irq(); 

}

If you break here and check the FLASH, it will look like the image above.

0 项奖励
回复

2,788 次查看
bobpaddock
Senior Contributor III
NXP documentation is full of bad examples where they use "|=" when they should not. What is FSTAT starting out as? Make sure an OR (|=) is what you really want, rather than a simple assignment (=). First line should probably be (=) and second (|=).

The nop should be marked as volatile. If the 'small' model is used, '-oS', GCC can be aggressive and remove the wait loop because it has no side effects.
0 项奖励
回复

2,779 次查看
tera
Contributor I

thank you for your reply.
The first line of FSTAT is OR(|=) to clear the error.
This is because CCIF is not cleared even if 0 is written.

"nop" seems to work without being optimized as far as the assembler list file is concerned.

 

.LBB19_1: @ =>This Inner Loop Header: Depth=1
movs r0, #0
movt r0, #16386
ldrb r0, [r0]
lsls r0, r0, #24
cmp r0, #0
bpl .LBB19_3
b .LBB19_2
.LBB19_2: @ in Loop: Header=BB19_1 Depth=1
.Ltmp39:
@app
nop
@no_APP
.Ltmp40:
b .LBB19_1
.LBB19_3:

0 项奖励
回复

2,739 次查看
bobpaddock
Senior Contributor III
The Write-1-to-Clear (W1C) bits are exactly that write a '1'. FSTAT = [Appropriate bit].

Using OR can lead to clearing bits that were not meant to be cleared. A bit could be lost by unintentional clearing if they are clearing interrupt flags. I realize that is not the case here.
0 项奖励
回复

2,731 次查看
tera
Contributor I

Thank you for your reply.
I'm sorry, but I'm not good at English, so I couldn't understand what you said.
very sorry.

>Using OR can lead to clearing bits that were not meant to be cleared.
I don't think OR clears extra BITs.
Set only the necessary bits to 1.

>A bit could be lost by unintentional clearing if they are clearing interrupt flags.
Interrupt flag is not cleared.

0 项奖励
回复

2,723 次查看
bobpaddock
Senior Contributor III
(|=) Is a Read-Modify-Write operation.
If a bit in a register is a '1' when it is read, then it will be cleared when it is written.

Some registers can have bits that transition to a '1' at any time.

If that happens immediately before a (|=) operation to that register that '1' bit can be lost, because the bit is now a '1' and it will be written back to the register clearing the related Write-1-to-Clear (W1C) bit, without it ever being seen by the firmware.

Some places using (|=) is required. Some places using it is bad. It depends on the register and the intention.
0 项奖励
回复

2,717 次查看
tera
Contributor I

>(|=) Is a Read-Modify-Write operation.
>If a bit in a register is a '1' when it is read, then it will be cleared when it is written.

I am doing OR with that intention

Writing a 1 clears the FSTAT flags.
There is no problem because OR is used to clear the flag.

0 项奖励
回复

2,830 次查看
CarlosGarabito
NXP TechSupport
NXP TechSupport

Could you explain a bit of the context of what are you doing? or the steps that you are follow? Thanks

0 项奖励
回复