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.

CC2650: How save variable on Flash

Part Number: CC2650
Other Parts Discussed in Thread: CC2640, CC2640R2F, BLE-STACK

Hi Team,

I need to save a variable in flash so I started to refer this link http://software-dl.ti.com/lprf/simplelink_cc2640r2_sdk/1.00.00.22/exports/docs/blestack/html/cc2640/platform.html#flash

in that, I have two doubt where to declare this 

OSAL_SVN = 1 --> in stack where ?

osal_snv_write() --> in app where?

can anyone suggest me related to this

  • Hi Santosh,

    Please clarify whether you are usig CC2650 or CC2640 or CC2640R2F. Please also let us know what version of the BLE-Stack you are using. 

  • Hi Marie,

    Thank you so much for the reply, I am using CC2650 and v2.2.3 ble stack

  • Hi Santosh,

    You can see YK's post for enabling NV Flash Storage driver in a project (thanks YK for sharing!). Additionally, the simple_periperhal example also illustrates how to use the NV Flash Storage driver in the application.

    In summary:

    1. OSAL_SNV=1 is declared in the stack project's preprocessor symbols. To do this:

      CCS:
      1. Right-click stack project (e.g. simple_peripheral_cc2650lp_stack) -> Click Properties
      2. Navigate to Build -> ARM Compiler -> Advanced Options -> Predefined Symbols
      3. Under Pre-define NAME list, add OSAL_SNV=1 if it does not already exist
      IAR:
      1. Right-click stack project (e.g. cc2650lp_stack) -> Click Options
      2. Navigate to C/C++ Compiler -> Preprocessor
      3. Under define symbols, add OSAL_SNV=1 if it does not already exist

    2. osal_snv_write() can be called anywhere in your application's task function.

    Regards,
    Michael

  • Hi YK, Michael

    Thank you so much for the reply, I am so confused I applied Michael method methods but it is not working. I don't why? 

    first i checked in the stack predefind symbol it is already exists

    /**********global declaration ***************************/
    
    #define BUF_LEN 3
    #define SNV_ID_APP 0x80
    uint8_t buf[BUF_LEN];
    
    //buf[0]=121;
    
    //buf[1]=11;
    
    //buff[2]=13;
    
    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
    {
    // Initialize application
    SimpleBLEPeripheral_init();
    
    osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf)

  • Do you try to follow the steps in ?

  • Hi Santosh,

    I was able to use the example code similar to the one provided in the BLE Software Developer's Guide - Flash section (3.10.3) to test writing to NV storage in the simple_peripheral example. Here are some suggestions I recommend to help debugging:

    1. First ensure that the simple_peripheral example has not been modified when you are testing the NV Flash Storage API. We first want to rule out the possibility that other project modifications are not causing any issues.
      1. Also, if you imported the simple_peripheral project from the SDK in your IDE and modified any source files during your tests, you might need to re-install the SDK if you are unsure you reverted changes back to the original state (If you have modified other projects in the SDK, you may want to backup the SDK before uninstalling).
    2. To see display output in the simple_peripheral example, remove the pre-defined symbols "Display_DISABLE_ALL" and either "BOARD_DISPLAY_EXCLUDE_UART", or "BOARD_DISPLAY_EXCLUDE_LCD" if you are using an LCD.
      1. If you are using UART, you will also need to change the call to "Display_open" from using "Display_Type_LCD" to "Display_Type_UART"
    3. You can also use the memory browser in CCS/IAR to see if the NV pages are being written too after calling osal_snv_write. You can do this by setting a breakpoint before calling osal_snv_write, and after stepping over the function, new data should be written to flash. The default address where NV storage is located is at 0x1E000.
      1. Additional debugging documentation can be found in the guide linked above in "Development and Debugging" (section 9). 

    Here is the snippet I used to test for reference:

    static void SimpleBLEPeripheral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimpleBLEPeripheral_init();
    
        #define BUF_LEN 10
        #define SNV_ID_APP 0x80
        uint8 buf[BUF_LEN] = {0,};
    
        uint8 status = SUCCESS;
    
        //Read from SNV flash
        status = osal_snv_read(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
        if(status != SUCCESS)
        {
            Display_print1(dispHandle, 5, 0, "SNV READ FAIL: %d", status);
            //Write first time to initialize SNV ID
            osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
        }
    
        //Increment value and write to SNV flash
        uint8 x;
        for(x = 0; x < BUF_LEN; x++)
            buf[x] = x + 1;
    
        status = osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
    
        if(status != SUCCESS)
        {
            Display_print1(dispHandle, 5, 0, "SNV WRITE FAIL: %d", status);
        }
        else
        {
            Display_print1(dispHandle, 5, 0, "Num of Resets: %d", buf[0]);
        }
    
      // Application main loop
      for (;;)
      {
        ...

    Regards,
    Michael

  • Hi Michae1, YK

    Thank you so much for the reply Finally, I got the result, but still, I have one problem when I followed Michael method it is working fine but 

    I want to apply like this

    for(x = 0; x < BUF_LEN; x++)
    {
    buf[x]=Value[x];
    }

    in this instead of passing 1,2,3 a number which is saving in the NV, but when I followed the above method I am so confused it is also getting value in buf array.

  • Couldn’t understand your question well. Can you elaborate?

  • Hi YK,

    Thank you so much for the reply

    #define  BUF_LEN 3

    for(x = 0; x < BUF_LEN; x++)
    {
    buf[x]=x+1;
    }

    output:

    1

    2

    the value is saving in the NV but when i get the data from the sensor i am not storing the value in the NV same method i used but one different i have done which is i mentioned below

    for(x = 0; x < BUF_LEN; x++)
    {
    buf[x]=Value[x];
    }

    in the Value array is nothing but sensor data i am just sending to the buf .but it is not stroing in the NV

  • How do you know it is not stored in the NV?

  • Hi YK,

    Thank you for your patience, I am viewing in the expression

  • How could you view NV items in the expression?

  • Hi Santhosh,

    Couple of follow-up questions:

    • Which IDE are you using to develop your project?
    • Could you try disabling program optimizations and set a break-point at the end of the loop where assign buf[x]=Value[x]; to verify 'buf' is being populated with data?
    • After the call to osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf), could you inspect the memory location where the NV storage is located (by default, 0x1E000) and post a screenshot (or alternatively, inspect the memory region to see if new data was written)?

    See also chapter 9 in the user's guide on the development and debugging section for additional tips

    Regards,
    Michael

  • Hi Team,

    Thank you so much for the reply, finally, I got some idea form the user guide/ I have implemented successfully. thank you, Michael, and Thank you YK for your patience reply

  • It’s good to know you implement it successfully.