This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF-LAUNCHXL: CC3220SF Store data in internal flash

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

      I want to store some(configuration) data in internal flash. I read some thread after that i can understand that is possible. i know we can access external flash also(chapter 7) but we want internal flash.

Refereed thread:

  1) swru465.pdf(chapter 21).

  2) C3220: (SF): Writing to flash at runtime.

  3)CC3220SF-LAUNCHXL: Internal and external flash storage.

  etc....

  But i don,t know how to access internal flash(flash.h) api and what address i need to give for store user data please anyone help me.

Thank you...

  • Hi Dhevan,

    There is this E2E post I wrote a while ago that explains how you could use the internal flash to store user data:

    https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/t/608297?CCS-CC3220SF-LAUNCHXL-How-do-I-store-my-code-in-FLASH-so-I-can-have-my-read-write-memory-in-SRAM-

    Basically, you will want to use the linker command file to define a internal flash section that will be used just for your data. This way, there is no possibility of anything overwriting that section of memory making it persistent. From there, you can have a pointer to that memory location that you can cast as appropriate to your data:

    //set the location of int array in flash to static, undeclared location, set aside in linker file
    int *persistentFlashArray;
    persistentFlashArray = (int*)0x10C0000;

    While this method is potentially dangerous since you'll have to keep track of your own memory instead of allowing the compiler to handle data allocation, it's the most straightforward method of storing data in the internal flash persistently. There are other methods such as using compiler directives to move data storage to the internal flash, but it's quite complex and the method above should be sufficient for simple data storage.

    Once you have your data allocated and pointed to, accessing it for read is trivial. All memory in the internal flash of the CC3220SF can be read just like data in RAM, so a read operation like this is perfectly fine:

    //read an integer stored in the internal flash to RAM for manipulation:
    int temp;
    temp = persistentFlashArray[x];
    myFunc(temp);


    Writing to the internal flash is far more complicated. The main rules to keep track of are that you have to write to it with 32bit aligned data, you have to write in multiples of 32bits, and that once you have written to an address in flash you can only erase it through doing a erase of the entire 2KB block containing that address. Furthermore, you must use the Flash driverlib APIs for all writes/erase operations.

    While there is no example of writing to the internal flash to store data persistently, attached is some code that I've used in project that stores application data persistently in the internal flash that you can use as a guide:

    /cfs-file/__key/communityserver-discussions-components-files/968/flash_5F00_write_5F00_erase.c

    Unfortunately, since this project is a private internal project, I cannot share the context in which you would call this function. Also, I had to rename variables and do some obfuscation on the code so that it doesn't contain references to TI proprietary code. Thus, you might be confused at the data-packing I do in the write function. Sorry about that.

    Let me know if you have more questions on how to use the internal flash on the CC3220SF.

    Regards,
    Michael

  • Hiii Michael Reymond,

    Thank you for your reply,

         Thank you so much for you brief explanation that is really useful. Now i tested with simple string i can able to read and write and erase.

         One more doubt is there  for this api (FlashProgram(unsigned long *pulData, unsigned long ulAddress, unsigned long ulCount) 

            1) How to give last argument (unsigned long ulCount)  count value in string and array.

            2) How to handle address ex: first i store hello string in 0x01C0000 but next time i want store some data that time how can i found what's last stored address(otherwise based on first data size increase the address count).

    Thank you...

      

  • Hi Dhevan,

    The ulCount is the amount of bytes you want to write. For strings, you can use strlen(yourString)+1 for ulCount. For other arrays, you'll have to know how large is the array through other means if you wanted to write the entire array at once. Given that you had to know the size of array at declaration, or at dynamic memory allocation, you can save that in some variable to use as ulCount as needed.

    For the case where you have stored something at 0x01C0000, what you'd probably want to do is increment the flash address immediately after writing by the amount of bytes written. Other than doing that, there are a variety of methods you can use to keep track of what internal memory is free. For example, you can make fixed-size structs, where the first byte is a flag indicating that the struct has been written to. Then, you can check the first byte of each possible struct location to see what's free. Another method is to use a struct with size data, where for each bit of data you write to flash, you also include the length of the data. By doing so, you can count how much data is being used in flash and increment your address appropriately for your next write.

    Regards,
    Michael
  • Hi Michael Reymond,

    Thank you for your reply,

    Thank you so much this information really useful. Your explanation is very good.