Re:(MPC5553)How can I configure global variable in flash memory

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

Re:(MPC5553)How can I configure global variable in flash memory

1,341 次查看
limheesun
Contributor II

·         Thank you for your help and I checked the code of your example.

 

I think, I don't understand yet. T.T

 

I have a global variable, 'Offset'. This variable is modified at once( when

the main application is start) by auto calibration function.

 

So, The auto calibration function will find the 'Offset' value, then I need

to save this value in flash address.

 

And then, after the value save in flash address, I will use this

value(Offset) on the main application's operation without the auto

calibration after Power Reset.

 

Therefore, I made the flash routine, but there're bus error.

 

So, I used #pragma to configure the variable direct in flash address.

 

This way has a problem the only constant value can save in flash.

 

 

 

#pragma push

 

#pragma section all_types ".__my_Flash" ".__my_Flash"

 

static const vuint32_t WVar=0xAAAAAAAA;

 

#pragma pop

 

 

 

I want make operation like 'WVar=Offset'.

 

 

 

void Program_FLASH(void)

{

    #define FLASH_HLR_PASSWORD      0xB2B22222

 

    /* enable high address space */

    FLASH.HLR.R = FLASH_HLR_PASSWORD; // unlock register

    FLASH.HLR.B.HBLOCK = 0x00000000;         // unlock all high blocks

 

    /* step1. erase H1 (0xC0000-0xFFFFF) */

    FLASH.MCR.B.ERS = 1;

    FLASH.HSR.B.HBSEL = 0x00000001;           // select H1 block

    ((unsigned int) p_test) = 0xFFFFFFFF;  // interlock write

    FLASH.MCR.B.EHV = 1;                    // start the erase operation

    while(FLASH.MCR.B.DONE == 0){};         // wait for DONE

    FLASH.MCR.B.EHV = 0;

    FLASH.MCR.B.ERS = 0;

 

    /* step2. program data */

    FLASH.MCR.B.PGM = 1;

((unsigned int)p_test) = Offset; //Is this valid?? This is my main

question

//    ((unsigned int) p_test++) = data_to_be_written[0]; // first write

//    ((unsigned int) p_test++) = data_to_be_written[1]; // additional

write

//    ((unsigned int) p_test++) = data_to_be_written[2]; // additional

write

//    ((unsigned int) p_test) = data_to_be_written[3];   // additional

write

    FLASH.MCR.B.EHV = 1;                                //start the erase

operation

    while(FLASH.MCR.B.DONE == 0){}; //wait for DONE

    FLASH.MCR.B.EHV = 0;

    FLASH.MCR.B.PGM = 0;

}

 

 

 

What I miss? T.T

 

Flash permission only constant like 0x0001?

 

I hope your help, please and thank you.

 

--

标签 (1)
0 项奖励
回复
6 回复数

1,126 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

it doesn't matter if immediate value or integer variable is used for interlock write. The result is the same.

Could you share some simple test project, so I can see the behavior?

Regards,

Lukas

0 项奖励
回复

1,126 次查看
limheesun
Contributor II

Thank you for your kind. And I successed flash erase and write the variable's value. But I don't know what I've done. So, I share the test project. Please, Would you see that for me? I successed this operation with unsigned integer value. And now I try with float value and there're bus error too!.

when I used integer value, on erase and write operation, bus error occures at just moment. After, I can see the result.

But when I use float value, bus error occures and I have to reset. I can't get the Result.

flash erasing (Integer)

flash_erase_ing.png

flash erase result(Integer)

flash_erase_end.png

flash writing(Integer)

flash_wirte_ing.png

flash writing result(Integer)

flash_write_end.png

flash erase result(float)

float_erase_result.png

flash write bus error

float_write_result_buserror.png

I use the Trace32 PowerPC. I hope your help. If you help me, I really really Thank you.

0 项奖励
回复

1,126 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I did quick test of your project and it is not working using the float too. I created simplified project (attached) using the same scenario and here it is working as expected. Could you compare the projects? Unfortunately I'm very busy now.

Regards,

Lukas

0 项奖励
回复

1,126 次查看
limheesun
Contributor II

I did test of your project. And the project is working well. Really I appreciate for your help. Thank you.

And I compared the projects, then I found something difference.

First, 'FlashWatch' function what I used in my project. And Second, FLASH.HLR.B.HBLOCK(interlock selcect register)'s value.

I tested the project with some case.

This is the result.

                              FlashWatch()                              FLASH.HLR.B.HBLOCK

1. (success)               not use                                             0b00000000

2. (success)               not use                                             0x00000000

3. (success)               not use                                             0x01111111

4. (success)               not use                                             0b01111111

--------------------------------------------------------------------------------------------------------

5. (Fail)                         use                                                0b00000000

6. (Fail)                         use                                                0x00000000

7. (success)                  use                                                0x01111111

8. (success)                  use                                                0x11111111

9. (Fail)                         use                                                0b01111111

10. (Fail)                       use                                                0b11111111

When 'FLASH.HLR.B.HBLOCK''s value is 0b00000000 The register set--> HBLOCK 00-07 :  0

                                                                    0x00000000 The register set--> HBLOCK 00-07 :  0

                                                                    0x01111111 The register set--> HBLOCK 00, 04 : 1

                                                                    0b01111111 The register set--> HBLOCK 07 : 0

                                                                    0x11111111 The register set--> HBLOCK 00, 04 : 1

I saw the register settings by Trace32 PPC.

In order to unlock the block HBLOCK bit set to 0. My target block is H7. So HBLOCK 07 value have to set 0.

But when other blocks set to 0 too, If I don't use 'FlashWatch' function, the operation is working well.

The other hand, when I use 'FlashWatch' function, only two case successed when 0x01111111, 0x11111111.

These settings configure the HBLOCK bit set to 00010001 

                      

                                                              HBLOCK

                                                  |07|06|05|04|03|02|01|00|

                                                   0    0   0   1   0  0   0   1

What is the correlation of the function and register setting? Could you help me one more time with this Question?

You are my lifesaver! Thank you.

0 项奖励
回复

1,126 次查看
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I was playing with your original project and it looks like it is caused by erratum e989:

http://www.nxp.com/files/32bit/doc/errata/MPC5553revAE.pdf

The prefetch should be disabled during erase/program operation. I just simply cleared the control bits in FLASH_BIUCR register and then it passed...

Also take a look at erratum e2075 - this one could be important for you too.

Regards,

Lukas

0 项奖励
回复

1,126 次查看
limheesun
Contributor II

Sorry, my reply is late.

I took a look at that file. That's very useful to me.

I feel that I have to study more and more.

I'm a student who study the embedded system. I want to be a software engineer.

Your kindness is very helpful to me. I appriciate to you.

Thank you so very very very much and have a nice day!

0 项奖励
回复