nrf51822教程系列 向nrf51822 flash中写入数据(flash write )
2016-03-28 15:36
597 查看
前言 寄存器介绍
0 .1 [b]Non-Volatile Memory Controller (NVMC)
[/b]
[b]Functional description
The Non-volatile Memory Controller (NVMC) is used for writing and erasing Non-volatile Memory (NVM).
Before a write can be performed the NVM must be enabled for writing in CONFIG.WEN. Similarly, before an
erase can be performed the NVM must be enabled for erasing in CONFIG.EEN. The user must make sure
that writing and erasing is not enabled at the same time, failing to do so may result in unpredictable behavior.
![](http://img.blog.csdn.net/20160328153214058?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
[/b]
0.2 [b]Factory Information Configuration Registers (FICR)
[/b]
[b]Functional description
Factory Information Configuration Registers are pre-programmed in factory and cannot be erased by the
user. These registers contain chip specific information and configuration
[/b]
1 确定写入flash 的位置
通过FICR 寄存器,读取nrf51822的flash page size 和 the number of pages
addr = (uint32_t *)(pg_size * pg_num);
![](http://img.blog.csdn.net/20160328145756957?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2 擦除flash page(写入数据前,先把该page数据擦除)
0 .1 [b]Non-Volatile Memory Controller (NVMC)
[/b]
[b]Functional description
The Non-volatile Memory Controller (NVMC) is used for writing and erasing Non-volatile Memory (NVM).
Before a write can be performed the NVM must be enabled for writing in CONFIG.WEN. Similarly, before an
erase can be performed the NVM must be enabled for erasing in CONFIG.EEN. The user must make sure
that writing and erasing is not enabled at the same time, failing to do so may result in unpredictable behavior.
[/b]
0.2 [b]Factory Information Configuration Registers (FICR)
[/b]
[b]Functional description
Factory Information Configuration Registers are pre-programmed in factory and cannot be erased by the
user. These registers contain chip specific information and configuration
[/b]
1 确定写入flash 的位置
通过FICR 寄存器,读取nrf51822的flash page size 和 the number of pages
uint32_t * addr;
uint32_t pg_size; uint32_t pg_num; pg_size = NRF_FICR->CODEPAGESIZE; pg_num = NRF_FICR->CODESIZE - 1; // Use last page in flash// Start address:
addr = (uint32_t *)(pg_size * pg_num);
2 擦除flash page(写入数据前,先把该page数据擦除)
// Erase page: flash_page_erase(addr);
/** @brief Function for erasing a page in flash. * * @param page_address Address of the first word in the page to be erased. */ static void flash_page_erase(uint32_t * page_address) { // Turn on flash erase enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } // Erase page: NRF_NVMC->ERASEPAGE = (uint32_t)page_address; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } // Turn off flash erase enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } }3 数据写入flash
flash_word_write(++addr, (uint32_t)patwr); /** @brief Function for filling a page in flash with a value. * * @param[in] address Address of the first word in the page to be filled. * @param[in] value Value to be written to flash. */ static void flash_word_write(uint32_t * address, uint32_t value) { // Turn on flash write enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } *address = value; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } // Turn off flash write enable and wait until the NVMC is ready: NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos); while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { // Do nothing. } }
相关文章推荐
- 开发自己的PHP MVC框架(一)
- 看来真不能直接将.so文件直接添加到Android的JAR包了
- iOS: no such file or directionally ....
- git 常用命令
- 海量数据网络部署技术
- GCD -- 倒计时
- python运行时间计算之timeit
- Spring学习笔记 什么是AOP
- 关于定时器或计数器的初值计算
- arm-linux交叉编译之lua
- 平台安装时写入注册表的打包方法
- 替换或者删除Android 4.0的app
- Android中scrollview在Activity初始化过程中, 要指定滚动条位置
- 状态模式(State)
- hdu 3038(种类并查集)
- Spring Task定时任务
- Mongodb C++ Deamon 及API说明
- lubuntu操作及桌面配置(3)
- 树莓派跑OPC2BACnet的评估
- python爬虫学习--pixiv爬虫(1)--p站爬虫的登录