Store a variable inside a Flash

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Store a variable inside a Flash

495 Views
utsavikalpesh
Contributor V

Hi

I am working with TWR-K60D100M a CodeWarrior v10.6 and of MQXv4.0.

I am working on FNET Demo of Ethernet Bootloader. Demo works perfectly.

I am trying to shape FNET demo as per my requirements.

What problem I am facing is, I am using a variable that I need to store inside Flash (Read and write from Flash).

When I tried to assign a static Flash address say 0x00008000 compiler will not show me error but when I am debugging code, The code is stuck at the point.

Say int *p;

p = 0x00008000;

{

//my stuff..

}

*p = 4;  <-- Debugging Stuck at this point.

So What I tried is to put the Variable inside fapp_params_flash

like.,

struct fapp_params_flash

{

    char signature[FAPP_PARAMS_SIGNATURE_SIZE]; /**< @brief Signature string.@n

                                                 * It's used for simple check if configuration

                                                 * structure is present in a persistent storage.*/

     int My_Bit;                              //Variable that Need to store in Flash.

    struct fapp_params_fnet fnet_params;        /**< @brief FNET TCP/IP stack specific

                                                 * configuration parameters.*/

    struct fapp_params_boot boot_params;        /**< @brief Bootloader specific

                                                 * configuration parameters*/

    struct fapp_params_tftp tftp_params;        /**< @brief TFTP loader specific

                                                 * configuration parameters.*/

};

(which is storing a data into flash from address 0x7F800) what that doesn't work (I removed all error and download code).

Can anybody tell me exactly procedure that how to store a variable inside a flash? if any further information then please let me inform.

Regards,

Utsavi Bharuchwala

0 Kudos
1 Reply

296 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Utsavi Bharuchwala:

The flash memory cannot be erased or written directly just with a pointer. Instead the flash memory module (FTFL in this case) requires to launch some commands as specified in the FTFL chapter of the K60 reference manual.

Since you are using MQX v4.0, you can use the integrated flashx driver. There should be an example project in your MQX installation. In my case I have MQX v4.1 and the example is in the next path:

C:\Freescale\Freescale_MQX_4_1\mqx\examples\flashx

If you need to have the variable at a specific address, such as the 0x00008000, then please refer to the next document in the community, which tells you how to manipulate the CodeWarrior GCC linker for this purpuse:

Relocating Code and Data Using the CW GCC Linker File for Kinetis


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos