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.
Please tell me how to solve this problem
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?
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>>
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.
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:
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.
>(|=) 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.
Could you explain a bit of the context of what are you doing? or the steps that you are follow? Thanks