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.

RTOS/CC2640R2F: Read / write flash

Part Number: CC2640R2F
Other Parts Discussed in Thread: SIMPLICITI

Tool/software: TI-RTOS

Hi there, 

I would like to understand better how the flash memory is organized in CC2640R2F.

I'm working with modified versions of SimpleBLEPeripheral and emptyProject.

Basically, I have a sensor from which I need to sample 10s of data at 1 kSa/s. Using the onboard 12 bits ADC, that would be roughly 15 kB. On those, I plan to do some processing before sending results over BLE. 

Given 20 kB of SRAM, I am unable to keep all these samples in SRAM for processing and thus I would like to save them in flash.

I am aware of NVS functions to read / write flash memory and I have a few doubts:

  1. I read only 2 pages of 4 kB are available. If I have more free flash memory, why can't I use it?
  2. Following this thread I was able to allocate an array into flash. When I try to write into it using basic C syntax ( array[index] = foo; ), the program hangs. How can I write into it then?
  3. I've also tried to change the linker .cmd file and place the .bss section into flash. I succeded in allocating my global big array into flash but I noticed that when debugging the program starts immediately after loading finishes (normally the program stops at the beginning of main after loading) but I cannot understand where it hangs (similar to point 2).

What would you recommend? Notice I don't really need persistent storage, data can be erased after processing and transmisison over BLE.

Best regards,

Jack

  • I think it's no good to keep writing internal flash from your application and I would suggest you to use external EEPROM or FLASH for such storage.
  • Hello YK Chen,
    Thanks for your answer.

    The board includes also a SPI micro SD card which will be normally used for storage. However, the device must be operational also in case the micro SD is not present. In that situation, I thought of using the internal flash.

    A future revision will surely consider removing the SD card and adding external memory. Meanwhile, could you suggest the best approach for my problem?

    Best regards,
    Jack
  • Hi Jack,

    I read only 2 pages of 4 kB are available. If I have more free flash memory, why can't I use it?

    You could in theory use any number of free pages for your flash regions, per default our NVS examples are setup to use only 2. Assuming you are using the NVS driver, this is configured in the board file.

    Following this thread 

    I was able to allocate an array into flash. When I try to write into it using basic C syntax ( array[index] = foo; ), the program hangs. How can I write into it then?

    You can not write to a flash region like you would when addressing RAM space. The flash has to be programmed, this could for example be done by using the NVS driver.

     

    I've also tried to change the linker .cmd file and place the .bss section into flash. I succeded in allocating my global big array into flash but I noticed that when debugging the program starts immediately after loading finishes (normally the program stops at the beginning of main after loading) but I cannot understand where it hangs (similar to point 2).

    Why would you want to put your .bss section in flash (or your global big array?)? While having constants in flash, any other variable that is not constant would not make sense to put there. 

    In general, using your internal flash for this purpose is not recommended as your flash would eventually break as the write/erase cycles are limited. As suggest above you should probably use some kind of external storage more suited for this.

    If you have no other option, I recommend looking in to how the GpRAM and AUX RAM can be used to extend your available RAM space. You could potentially use these as temporary storage for your data.

  • Hi M-W,

    Thanks for your answer.

    I tried other options with respect to NVS driver because I had not found any point in the documentation regarding the number of supported flash pages. This is great news, I'll give it a try and let you know.

    I cannot use AUX RAM for this purpose because I need sensor controller to ensure analog data are sampled according to the specified timing. Using the main processor I fear the ADC might get interrupted by other tasks. Following on this, can a ISR interrupt a higher priority task? What if I had a few priority 1 tasks (for management of I2C and SPI sensors), a few ISR (for interrupts of the sensors) and a priority 2 task for ADC? I believe interrupts should have priority on tasks, is that right? Is there any way to change this behaviour for a particular task?

    I will try tu use GPRAM. However I've read this is much slower than regular RAM.

    Best regards,

    Jack

  • Hi Jack,

    A ISR always has higher priority then a task, the priority basically is Hwi > Swi > Task where you can adjust the inter-priority in any the Hwi, Swi or Task.

    Even with the fact that GPRAM could be slower, flash operations would still be much slower then this.
  • Hi M-W,

    I come back on this conversion because I couldn't modify my board file in the way you suggested.

    M-W said:

    You could in theory use any number of free pages for your flash regions, per default our NVS examples are setup to use only 2. Assuming you are using the NVS driver, this is configured in the board file.

    I read the doc a little more carefully though, and I understood that SNV storage is managed through IDs which range from 0x80 to 0x8F by default. Since each ID can be used to store 256 bytes, the total available space is 4kB, as the documentation clearly states. Now, you said I can increase this space in theory but in this thread:

    it is I cannot. I wonder what is the limitation of SNV driver to allow only 16 IDs to be used for user storage.

    Best regards,

    Jack

  • Hi Jack,

    There is a difference between the NVS Driver and the SNV implementation that is part of the stacks. The NVS driver (as in TI Drivers) do not impose any limit to the amount of flash available as long as you actually have free flash to spare.

    Just to highlight this again, I don't think saving the ADC values to flash as temporary storage is a good idea as this will wear your flash down quickly while also consuming a lot of time. You are better of by trying to extending the amount of available RAM to fit the data when the SD Card is not available.