Erasing Flash sectors in KL25 on the Freedom Board.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Erasing Flash sectors in KL25 on the Freedom Board.

5,519件の閲覧回数
embeddedcontrac
Contributor II

Processor Expert has a Flash component which I used for the freedom board. I am able to successfully execute the Read Method. I can successfully execute the Write Method, but only once. If I try to write the 2nd time at the same memory location, it fails. It seems this is because the Write method does not Erase before writing.

I tried to execute the Erase and EraseBlock Method, but it did not work. It seems the "safe launch and wait" property of the Flash component prevented me from using the Erase Methods. Has anyone been able to use the Erase/EraseBlock Methods? If yes, can you please post some sample code, similar to sample code for Write and Read Methods examples given in the "Typical Usage" section of the Flash Component Help documentation.

ラベル(2)
7 返答(返信)

1,883件の閲覧回数
亚男张
Contributor I

Hi there, i want to store some data to the flash, but i don't know how to do it, i use cw 10.5 and set up of user memory areas is grey, and it doesn't have the FLASH1_GetOperationStatus function.and what should I send to the FLASH1Pointer parameter?

0 件の賞賛

1,883件の閲覧回数
charlespalmer
Contributor I

I found that you must erase a block size equivalent to the minimum block size of the processor. Trying to erase a smaller amount gives an error. This sounds sensible, though the comment in the PE definition of FLASH1_Erase() is not clear about this.

This works:

// don't try to erase 64 bytes!

//OpStatus = FLASH1_Erase(FLASH1Pointer, 0x1F000, sizeof(savedData));

OpStatus = FLASH1_Erase(FLASH1Pointer, 0x1F000, FLASH1_ERASABLE_UNIT_SIZE);

if (OpStatus != ERR_OK){

    printf("Erase error. Status code is: %02x\n", OpStatus);

    break;

}


0 件の賞賛

1,883件の閲覧回数
pengliang
Contributor III

How did you write the flash with longword? I am trying to write. buy I am confused about FCCOB 1:3 registers Flash address.  I know the flash address ranges from 0x0000_0000 - 0x07FF_FFFF. which is 128K byte. how come FCCOB 1-3 registers only specify flash adress from 0 - 23 bits? supposed to be 0 -26 bits, right?

0 件の賞賛

1,883件の閲覧回数
pengliang
Contributor III

I figured out~

0 件の賞賛

1,883件の閲覧回数
HeronBR
Contributor I

Hi Luis:

I implemented your code and it worked fine, but using the same code under FreeRtos, after erase operation I got the message :

No source available for "0xFFFFFFFE (0xFFFFFFFE)() "

I also tried disable interruptions during this operation but it didn't worked fine.

Do You have any suggestion ?

Thanks

0 件の賞賛

1,883件の閲覧回数
LuisCasado
NXP Employee
NXP Employee

Hello,

First, you have to reserve some Flash pages for data storage. Do that in the CPU Build Options, Reduce the Flash for code, for example :

1.bmp

Then, configure those pages to be used by Flash component:

2.bmp

Then, enable the Flash methods you need:

3.bmp

Now, you can save the data in the code:

Read:

FLASH1_Read(FLASH1Pointer,0x1F000, &savedData.red, sizeof(savedData));

   do {

               FLASH1_Main(FLASH1Pointer);

       OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

   } while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));

Erase one page, in case is not 0xFF the locations to write:

FLASH1_Erase(FLASH1Pointer, 0x1F000, 1024);

               do {

                              FLASH1_Main(FLASH1Pointer);

                              OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

               } while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));

And then write the data in Flash:

FLASH1_Write(FLASH1Pointer, FromPtr, 0x1F000, Size);

              

               do {

                       FLASH1_Main(FLASH1Pointer);

                       OpStatus = FLASH1_GetOperationStatus(FLASH1Pointer);

               } while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));

I hope this helps,

Luis

1,883件の閲覧回数
lander
Contributor IV

I'm not able to change the section "User memory areas", it's grey and will not let me make "Use user memory areas" to yes. I did step one, is there something else I'm missing?

Thank you.

0 件の賞賛