AnsweredAssumed Answered

Saving struct to flash memory using FlashProgram

Question asked by Piotr Cerba on Oct 25, 2015
Latest reply on Oct 28, 2015 by Jorge_Gonzalez

Hello, I have a following problem. I want to save my own struct using the flash_demo example from SDK.

I am using FlashProgram function for that purpose.

What have I tried:

Here is my code (the rest of SDK flash_demo remains unchanged):

typedef struct
  int x, y;
  char name[40];
} myStruct;
int main(void)
/*rest of example code*/

myStruct first = { .x = 1, .y = 123, .name = "George" };

/*rest of example code*/

    *   For devices without SWAP, program some data for demo purposes
    destination = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
    end = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 4*FTFx_PSECTOR_SIZE);
    /*for (i = 0; i < BUFFER_SIZE_BYTE; i++)
         Set source buffer
        program_buffer[i] = i + 100;
    size = sizeof (myStruct);//BUFFER_SIZE_BYTE;

    /* message for user */
    PRINTF("\n\n\r---->Running FlashProgram() and FlashProgramCheck()...");

    while ((destination + (size)) < end)
        ret = FlashProgram(&flashSSDConfig, destination, size, \
                                       first, g_FlashLaunchCommand);
        if (FTFx_OK != ret)
/*rest of example code*/


Unfortunately this gives an error:

D:/Freescale/SDK/examples/frdmkl43z/demo_apps/flash_demo/main.c:354:9: error: incompatible type for argument 4 of 'FlashProgram'

1. Does it mean I am not able to save struct in flash memory? (somewhat contrary to what Mike Butcher said here -> Reading flash - why not by normal memory access? )

2. Is there any way to transform any structure to uint8_t* which is required by FlashProgram?


I will be very grateful for any suggestions!