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.

CCS/CC3220SF-LAUNCHXL: How do I store my code in FLASH so I can have my read/write memory in SRAM?

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

Tool/software: Code Composer Studio

Yesterday I asked how best to store 200kb of data on my CC3220SF, I was pointed toward the FATSD example and told that I can write to serial flash with that, however after (failing for a while then) checking the TRM SWRU465 I learned that I could store the code in flash freeing up the SRAM for my data.

Now I'm really confused...  From SWRU465:

1.3.2.3
Flash Memory
The CC3220SF comes with an on-chip flash memory of 1024 KB, allowing application code to execute in- place while freeing up SRAM to be used exclusively for read-write data. The flash memory is used for code and constant data sections, and is directly attached to the ICODE/DCODE bus of the Cortex-M4 core.

A 128-bit wide instruction pre-fetch buffer allows maximum performance to be maintained for linear code, or loops that fit inside the buffer. The flash memory is organized as 2-KB sectors that can be independently erased. Reads and writes can be performed at word (32-bit) level.



So does this mean I can keep the code and constant variables in the Flash memory and use the 256kB of SRAM to collect and manipulate my sensor data?!?!  That's what I was trying to do before I was told to look at the SD card example to write to flash instead?

  • Hi James,

    In the CC3220SF, the linker will place your compiled object files, constants, and other read-only data into the internal XiP flash for you automatically when you build your project in CCS.

    If you look in the CC3220SF_LAUNCHXL_TIRTOS.cmd file, you will notice that there are some instructions given to the linker on how to allocate memory and where to place things. As you can see, the text (your code) and the const is already being placed in the FLASH memory region.

    While this means that the RAM won't be used up storing your program, you won't be able to use the full 256kB of RAM for your array. The stack and heap need to be placed in RAM, among other things. You might be able to get ~180kB or so for your array depending on the memory requirements of the rest of your program.

    Going to back to your original idea of placing your array in the internal flash, it is actually very possible to do that as well, albeit messy. What you would want to do is first tell the linker to set aside a block of memory for your array in flash in the .cmd file, something like so:

    MEMORY
    {
        /* Bootloader uses FLASH_HDR during initialization */
        FLASH_HDR (RX)  : origin = 0x01000000, length = 0x7FF      /* 2 KB */
        FLASH     (RX)  : origin = 0x01000800, length = 0x0BF800   /* 766KB */
        FLASH_W   (RWX) : origin = 0x010C0000, length = 0x40000   /* 256KB */
        
        SRAM      (RWX) : origin = 0x20000000, length = 0x00040000 /* 256KB */
    }

    That will create a FLASH_W memory region that won't have anything allocated to it by the linker, which means you can use that memory for your array safely.

    Keep in mind that while you can read from internal flash freely, there are a few restrictions on writing to the internal flash. Specifically, you have to write to it with 32bit aligned data, you have to write in a multiple 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, all flash writes have to be done using the lower-level driverlib API. I suggest you read through chapter 21 of the TRM for a better understanding of how the internal flash can be used, and which APIs you will need to call to write to it properly.

    Regards,

    Michael

  • Thank you so much for you very thorough response, Michael! I realize it must be difficult responding to questions when the asker doesn't really know what they're doing yet, but you have given me a great answer and the perfect opportunity to learn from this.

    Thanks again!
    James