NVMC
复制代码
1
2
3
4
5
61.写flash之前必须配置写寄存器CONFIG.EEN=1对flash的扇区进行擦除,否则无法进行写操作(全部置1,页操作) 2.配置写寄存器CONFIG.WEN=1 对flash进行写使能。(只能由1写为0) 3.flash写入时都是以一个字(32位)对齐到地址上。 4.nrf52832具有512kbyte的flash,可分为128页,每页4kbyte;每页分为8个数据块,每块512byte;每个块有128个字。 5.写入数据时,cpu会被挂起。
NVMC常用函数
复制代码
1
2
31.flash擦除页函数:nrf_nvmc_page_erase(uint32_t addr) 2.向flash写字函数:nrf_nvmc_write_word(uint32_t addr,uint32_t value)
flash的读写示例程序
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118#include <stdbool.h> #include <stdint.h> #include "nrf_delay.h" #include "boards.h" /* 包含log头文件 */ #include "nrf_log.h" #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" /* 包含uart头文件 */ #include "app_uart.h" #if defined (UART_PRESENT) #include "nrf_uart.h" #endif #if defined (UARTE_PRESENT) #include "nrf_uarte.h" //带easydma的串口 #endif #include "nrf_nvmc.h" /* 定义uart收接发缓冲区 */ #define UART_TX_BUF_SIZE 256 #define UART_RX_BUF_SIZE 256 /** * log初始化函数 */ static void log_init(void) { ret_code_t err = NRF_LOG_INIT(NULL); //log初始化 APP_ERROR_CHECK(err); //检测log配置信息 NRF_LOG_DEFAULT_BACKENDS_INIT(); //开启log } /** * uart事件回调函数 */ void uart_event_handle(app_uart_evt_t* event) { //uart通讯出错事件 if(event->evt_type == APP_UART_COMMUNICATION_ERROR) { APP_ERROR_HANDLER(event->data.error_communication); } //fifo错误事件 else if(event->evt_type == APP_UART_FIFO_ERROR) { APP_ERROR_HANDLER(event->data.error_code); } } /** * uart初始化参数配置函数 */ void uart_config(void) { uint32_t err; /* 串口结构体参数 */ const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, //接收引脚p0.08 TX_PIN_NUMBER, //发送引脚p0.06 RTS_PIN_NUMBER, //输出信号引脚p0.05 CTS_PIN_NUMBER, //输入信号引脚p0.07 APP_UART_FLOW_CONTROL_DISABLED, //使能软件控制流 false, //不校验 NRF_UART_BAUDRATE_115200 //串口波特率115200 }; /* 串口初始化 */ APP_UART_FIFO_INIT(&comm_params, //串口结构体 UART_RX_BUF_SIZE, //串口接收缓冲区大小 UART_TX_BUF_SIZE, //串口发送缓冲区大小 uart_event_handle, //串口事件回调函数 APP_IRQ_PRIORITY_LOWEST, //串口中断优先级最低 err); //配置信息 APP_ERROR_CHECK(err); //检测配置是否成功 } /** * uart初始化函数 */ int main(void) { uint32_t addr; uint32_t* pdata; log_init(); uart_config(); NRF_LOG_INFO("uart example start"); NRF_LOG_FLUSH(); addr = 0x0007F000; //最后一页的首地址,由于程序存储在flash中,防止出错 nrf_nvmc_page_erase(addr); //页擦除 nrf_nvmc_write_word(addr,0x12345678); //写入一个字数据 pdata = (uint32_t *)addr; //指针指向字所在地址 while(1) { printf("data is 0x%xrn",*pdata); nrf_delay_ms(1000); } }
最后
以上就是魔幻超短裙最近收集整理的关于九、nrf52832的NVIC(非易失存储器flash)的全部内容,更多相关九、nrf52832内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复