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.

CC2642R: How to read/write data from/to CC2642R internal flash with OAD function?

Part Number: CC2642R
Other Parts Discussed in Thread: SYSCONFIG

Hi everone,

I'm using NVS to write and read some data in the flash memory and I use simple_peripheral_oad_offchip_CC26X2R1_LAUNCHXL_tirtos_ccs project.

I have found the regionAttrs.regionBase is 0xFFFFFFFF, regionAttrs.sectorSize is 0x00001000, regionAttrs.regionSize is 0x00200000. These values doesn't match with the following syscfg.

My syscfg:


ti_drivers_config.c:

#if defined(__TI_COMPILER_VERSION__) || defined(__clang__)

static char flashBuf0[0x4000] __attribute__ ((retain, noinit, location(0x48000)));
static char flashBuf1[0x4000] __attribute__ ((retain, noinit, location(0x52000)));

#elif defined(__IAR_SYSTEMS_ICC__)

__no_init static char flashBuf0[0x4000] @ 0x48000;
__no_init static char flashBuf1[0x4000] @ 0x52000;

#elif defined(__GNUC__)

__attribute__ ((section (".nvs")))
static char flashBuf0[0x4000];
__attribute__ ((section (".nvs")))
static char flashBuf1[0x4000];

#endif

NVSCC26XX_Object nvsCC26XXObjects[2];

static const NVSCC26XX_HWAttrs nvsCC26XXHWAttrs[2] = {
/* CONFIG_NVSINTERNAL */
{
.regionBase = (void *) flashBuf0,
.regionSize = 0x4000
},
/* CONFIG_NVS_0 */
{
.regionBase = (void *) flashBuf1,
.regionSize = 0x4000
},
};


#include <ti/drivers/nvs/NVSSPI25X.h>

/*
* NVSSPI25X External NVS flash region definitions
*/

/*
* Provide write verification buffer whose size is
* the largest specified Verification Buffer Size
*/

static uint8_t verifyBuf[64];

NVSSPI25X_Object nvsSPI25XObjects[1];

static const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = {
/* CONFIG_NVSEXTERNAL */
{
.regionBaseOffset = 0x0,
.regionSize = 0x200000,
.sectorSize = 0x1000,
.verifyBuf = verifyBuf,
.verifyBufSize = 64,
/* NVS opens SPI */
.spiHandle = NULL,
/* SPI driver index */
.spiIndex = CONFIG_SPI_0,
.spiBitRate = 4000000,
/* GPIO driver pin index */
.spiCsnGpioIndex = CONFIG_GPIO_0,
.statusPollDelayUs = 100
},
};

#define CONFIG_NVS_COUNT 3

const NVS_Config NVS_config[CONFIG_NVS_COUNT] = {
/* CONFIG_NVSINTERNAL */
{
.fxnTablePtr = &NVSCC26XX_fxnTable,
.object = &nvsCC26XXObjects[0],
.hwAttrs = &nvsCC26XXHWAttrs[0],
},
/* CONFIG_NVS_0 */
{
.fxnTablePtr = &NVSCC26XX_fxnTable,
.object = &nvsCC26XXObjects[1],
.hwAttrs = &nvsCC26XXHWAttrs[1],
},
/* CONFIG_NVSEXTERNAL */
{
.fxnTablePtr = &NVSSPI25X_fxnTable,
.object = &nvsSPI25XObjects[0],
.hwAttrs = &nvsSPI25XHWAttrs[0],
},
};

const uint_least8_t CONFIG_NVSINTERNAL_CONST = CONFIG_NVSINTERNAL;
const uint_least8_t CONFIG_NVSEXTERNAL_CONST = CONFIG_NVSEXTERNAL;
const uint_least8_t CONFIG_NVS_0_CONST = CONFIG_NVS_0;
const uint_least8_t NVS_count = CONFIG_NVS_COUNT;

I'm a beginner with TI-RTOS. Could someone helps me?

Thanks a lot.

  • Hi,

    Thank you for reaching out.

    I assume you are trying to write to the internal Flash. I would recommend to review this piece of documentation.

    I have found the regionAttrs.regionBase is 0xFFFFFFFF, regionAttrs.sectorSize is 0x00001000, regionAttrs.regionSize is 0x00200000. These values doesn't match with the following syscfg.

    These parameters are not correct and won't work. The one displayed on the SysConfig screenshot look better. However, based on the first part of my answer, I am not sure you need to do this...

    I hope this will help,

    Best regards,

  • Hi,

    I tried to use osal snv but it didn't work too.

    By the way, I used GapBondMgr in my project.

    May it write some data to the internal Flash used by CONFIG_NVSINTERNAL (regionBase: 0x48000) ?

  • Hi,

    Yes, you can write some data in the internal Flash. However, make sure to not use the NVID used by the stack. You can refer to the documentation for more details.

    Best regards,

  • Hi,

    Thank you for your suggestion.
    I copy OSAL SNV Example to my project. It doesn't work.

  • Hi,

    It doesn't work.

    Could you please provide details regarding the implementation of the code snippet, the test process followed, the results seen, etc. ?

    Thanks and regards,

  • Hi,

    The code is:

    #define BUF_LEN 4
    #define SNV_ID_APP 0x100
    #define SP_NVS_DEBUG         (TBM_ROW_APP + 10)
    uint8 buf[BUF_LEN] ={0,};
    static void SimplePeripheral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimplePeripheral_init();
      uint8 status = SUCCESS;
    
      status = osal_snv_read(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
      if(status != SUCCESS)
      {
        Display_printf(dispHandle, 0, SP_NVS_DEBUG, "SNV READ FAIL: %d", status);
        //Write first time to initialize SNV ID
        osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
      }
    
      //Increment first element of array and write to SNV flash
      buf[0]++;
      status = osal_snv_write(SNV_ID_APP, BUF_LEN, (uint8 *)buf);
      if(status != SUCCESS)
      {
        Display_printf(dispHandle, 0, SP_NVS_DEBUG, "SNV WRITE FAIL: %d", status);
      }
      else
      {
        Display_printf(dispHandle, 0, SP_NVS_DEBUG, "Num of Resets: %d", buf[0]);
      }
    
      // Application main loop
      for (;;)
      {
      //...
      }
    }

    Syscfg is:

    I used CCS debug mode and breakpoint after I found that SimplePeripheral_taskFxn was not executed.

    But SimplePeripheral_createTask was executed.

    As follwing screenshot, you can see the region base 0x48000 of the memory is not correct.

    Thanks and regards,

  • Hi,

    I am surprised the code could in fact prevent the device to create the task.

    Could you please verify if by commenting it out you could manage to get the task created?

    Best regards,

  • Hi,

    After a few tries, the code working now.

    Could you please help me  how to make sure the data write in the internal Flash?

    As following screenshot, it looks not successfully.

    Thanks and regards,

  • Hi,

    Could you please help me  how to make sure the data write in the internal Flash?

    I guess a simple test would be to verify the value read is identical to the value written.

    When using the memory browser, make sure to refresh the view (yellow buttons on the right of the screen).

    Best regards,

  • Hi Clément,

    I have resolved the issue.

    Thank you so much for helping me.

    Best Regards,

  • Hi Clément,

    May I use another regionBase?