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.

CC2640R2F: External Flash integration using NVS spi

Part Number: CC2640R2F

Hi All,

We were using Winbond 4Mbit external flash and ExtFlash .c & ExtFlash.h files to integrate it with CC2640R2F ,Now we are using FM25Q044M  and trying to use NVS instead of ExtFlash files ,i have written code as mentioned below

CC2640R2DK_5XD.c

#define SPISECTORSIZE 0x1000
#define SPIREGIONSIZE (SPISECTORSIZE * 32)
#define VERIFYBUFSIZE 64

static uint8_t verifyBuf[VERIFYBUFSIZE];

/* Allocate objects for NVS External Regions */
NVSSPI25X_Object nvsSPI25XObjects[1];

/* Hardware attributes for NVS External Regions */
const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = {
{
.regionBaseOffset = 0,
.regionSize = SPIREGIONSIZE,
.sectorSize = SPISECTORSIZE,
.verifyBuf = verifyBuf,
.verifyBufSize = VERIFYBUFSIZE,
.spiHandle = NULL,
.spiIndex = 0,
.spiBitRate = 4000000,
.spiCsnGpioIndex = CC2640R2DK_5XD_GPIO_SPI_CS,
},

};

const NVS_Config NVS_config[CC2640R2_5XD_NVSCOUNT] = {

{
.fxnTablePtr = &NVSSPI25X_fxnTable,
.object = &nvsSPI25XObjects[0],
.hwAttrs = &nvsSPI25XHWAttrs[0],
},

}

const uint_least8_t NVS_count = CC2640R2_5XD_NVSCOUNT;

Application code:

Flash_write()

{

uint32_t status;
NVS_Handle gapFlashHandle = NVS_open(Board_NVSEXTERNAL, NULL);
if (gapFlashHandle == NULL)
{
}
status = NVS_erase(gapFlashHandle,0, 4096);
if (status != 0)
{
       NVS_close(gapFlashHandle);
}
gapBufferData2[0] = gapBufferData2[0] + 2;
status = NVS_write(gapFlashHandle,0, gapBufferData2, 4, NVS_WRITE_POST_VERIFY);
if (status == 0)
{
      NVS_close(gapFlashHandle);
}
NVS_close(gapFlashHandle);

}

Flash_read()

{

VOID GAPRole_StartDevice(&SimpleBLEPeripheral_gapRoleCBs);
uint32_t status;
NVS_Handle gapFlashHandle = NVS_open(Board_NVSEXTERNAL, NULL);
if (gapFlashHandle == NULL)
{
// LCD_WRITE_STRING("open failed");
// return -1;
}//
status = NVS_read(gapFlashHandle,0, gapBufferData2, 4);
if (gapBufferData2[0] != 0xFF && status == 0)
{
NVS_close(gapFlashHandle);
//return 0;
}
NVS_close(gapFlashHandle);
// return -1;

Util_startClock(&periodicClock);

}

}

the above code is working fine whatever was written was restored back.

but using ExtFlash files we are able to write to particular location by passing the address for example:

#define extbuffer                         0x60000

 

ExtFlash_open();

writereturn = ExtFlash_write(extbuffer+(writecount*buf_size),buf_size,buf);

ExtFlash_close();

and same data written can be read by using 

ExtFlash_open();
readreturn = ExtFlash_read(extbuffer+(readcount*buf_size),buf_size,buf);
ExtFlash_close();

same way in case i want to read write to particular location and multiple data on multiple locations how it can be done using NVS 

how to define NVS settings for accessing particular location for storing and retrieving , which commands can do that or what changes needed in above mentioned code for achieving that.

NVS read and write has offset as one  argument i tried passing address like we give while using ExtFlash.c & ExtFlash.h files,but it didn't work.

Plz suggest some references or any inputs on this will be helpful for me.

Thanks in advance..!!

Regards,

Atul

  • Hey Atul,

    There doesn't seem to be a way of writing to a particular address like you mentioned. Can you elaborate the attempt to pass in the offset using the NVS driver? You should be able to use the offset.

    Additionally, which SDK are you working with? Is there an example project you've based your work on?

  • Hi Ammar N,

    Thanks for the response....!!

    i have tried this in SDK 4.20 also in 1.40 both gave same results.

    i have tried to implement by referring to this thread: as per the thread i did the changes ,and while calling the read and write i tried to give offset as 0 it writes ti first sector and working fine for second sector i pass offset 4096 as mentioned below 

    status = NVS_erase(gapFlashHandle,4096, 4096);

    status = NVS_write(gapFlashHandle,4096, gapBufferData2, 4, NVS_WRITE_POST_VERIFY);

    status = NVS_read(gapFlashHandle,4096, gapBufferData2, 4);

    but this doesn't write or retrieve anything .

    which way offset should be passed is not clear for me, nor the way how different sectors can be created  i have no idea.

    so can you guide me in this how to create  a new region and how to write to external flash in particular region using offset?

    Thanks in Advance.....!!

    Regards, 

    Atul

  • Hey Atul,

    I apologize for the delay. Which project are you using? I recommend starting with a basic driver example first as it's hard to get a solid understanding if the application you're using is already making use of NVS (then you'll have to make sure there are no conflicts in address space).

    If you're using a BLE project, like Project Zero, refer to the following thread:

    https://e2e.ti.com/support/wireless-connectivity/bluetooth/f/538/t/683310?CC2640R2F-Using-NVS-drivers-in-ProjectZero