微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > cc1310 flash读写疑问

cc1310 flash读写疑问

时间:12-23 整理:3721RD 点击:

hi~,all。最近在使用cc1310 做开发,需要用到cc1310的flash存储数据,查到一些资料,可以使用NVS API进行操作,碰到一些疑问,请教一下。

在使用NVS进行flash操作时,初始化里面有这么一段:

/*
* Block to be used if making a copy of the flash page is needed.
* Could use another block of flash, but there is not alot of flash on
* these devices...
*/
char myCopyBlock[4096];
const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[CC1310DK_7XD_NVSCOUNT] = {
{
.block = (void *)(0x20000 - 4096), // Flash sector to use is 4096 of flash on a 128K part
.blockSize = 4096,
.copyBlock = myCopyBlock,
.isRam = true
}
};

不太明天的是这里的copyBlock,解释说明可以使用RAM做copyBlock,也可以用flash做copyBlock,进一步查到如下说明:

/*!
* @brief NVSCC26XX attributes
*
* The block is the address of a region in flash of size blockSize bytes.
*
* For CC26XX devices, the smallest erase page size is 4KB, so in most
* cases, blockSize should be set to 4KB for this device. If the
* blockSize is less than the page size, care should be taken not to use
* the rest of the page. A write to the block will cause the entire page
* to be erased! A blockSize greater than the page size is not supported.
* The page size for the device can be obtained through NVS_getAttrs().
*
* When the block is written to, a scratch region is needed to preserve
* the unmodified data in the block. This scratch region, referred to as
* copyBlock, can be a page in flash or a buffer in RAM. The application
* can set copyBlock in the HWAttrs directly, if it is known at compile
* time, or set copyBlock through NVS_control(), for example, if it is
* allocated on the heap. The copyBlock can be shared accross multiple
* NVS instances. It is up to the application to ensure that copyBlock
* is set before the first call to NVS_write().
* Using a blockSize less than the page size decreases RAM or heap only
* if copyBlock is not in flash.
*/
typedef struct NVSCC26XX_HWAttrs {
void *block; /*!< Address of flash block to manage */
size_t blockSize; /*!< The size of block */
void *copyBlock; /*!< A RAM buffer or flash block to use for
* scratch when writing to the block.
*/
bool isRam; /*!< TRUE if copyBlock is a RAM buffer */
} NVSCC26XX_HWAttrs;

描黄的字段是解释,有几点疑问:

(1)当copyBlock在heap上时,可以重复使用该copyBlock于其他instance,按照这个意思是否是说可以进行如下初始化:

char myCopyBlock[4096];
const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[ ] = {
{
.block = (void *)(0x20000 - 4096), // Flash sector to use is 4096 of flash on a 128K part
.blockSize = 4096,
.copyBlock = myCopyBlock,
.isRam = true
}

{

.block = (void *)(0x20000 - 4096 * 2), // Flash sector to use is 4096 of flash on a 128K part

.blockSize = 4096,
.copyBlock = myCopyBlock,
.isRam = true
}
};

使用相同的copyBlock,初始化不同的flash sector。

(2)说明中提出可以使用flash作为copyBlock,在ram资源比较紧张的时候,这是最好的选择。不知使用flash作为copyBlock时该如何进行设置,还望解惑。

感谢!

NVS module可以理解成是对底层Flash操作的一个抽象层,它将底层的Flash操作封装成更方便用户使用的NVS API。

这里所说的copyBlock,你可以理解成是一个buffer。

因为更新Flash中的内容时,需要先将整个sector的内容全部erase,然后再把新的内容写入。NVS就是将这个先读出,再擦除,最后在写入的过程封装在NVS_write()里,方便用户使用。

因为copyBlock只是在写入时起到一个buffer的作用,所以,如果你要对多块Flash区域进行读写时,可以使用同一个copyBlock buffer。

CC1310可以读flash里的内容吗?从CC1310 Driver Library里我没有找到。请问在哪里可以找到?

参见C:\TI\simplelink_cc13x0_sdk_1_40_00_10\source\ti\drivers\nvs\NVSCC26XX.c文件

NVSCC26XX_read()

xian sheng li

flash读可以使用指针

long flashdata;

flashdata=*(long *) 0xfff0;

把0xfff0地址存储的代码读出来保存到变量flashdata

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top