AnsweredAssumed Answered

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

Question asked by Lim Heesun on Jan 4, 2016
Latest reply on Jan 13, 2016 by Lim Heesun

·         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


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

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


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


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


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


    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.