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