nRF DFU

NRF52 DFU

micrc-ecc

Nordic的DFU采用了micro-ecc实现ECDSA算法,需要用到micro-ecc源码编译

pc-nrfutil

生成加密密钥

1.编译micro-ecc库

1.将micro-ecc源码放在SDK\external\micro-ecc下
2.选择对应编译项编译,生成对应的库

2.安装pc-nrfutil

python setup.py install

3.生成private_key和public_key

1
2
nrfutil keys generate private.pem
nrfutil keys display --key pk --format code private.pem --out_file dfu_public_key.c

4.编译bootloader

1.使用生成的dfu_public_key.c替换examples\dfu下的文件
2.编译对应的bootloader,烧录运行后,手机打开nRF Connect,可扫描到DfuTarg

5.打包升级文件

1.对应工程examples\ble_app_buttonless_dfu编译
2.将编译后的hex文件和private.pem放入一个文件夹中
3.输入命令打包
例如:

1
nrfutil pkg generate --hw-version 52 --application-version 1 --application nrf52832_xxaa.hex --sd-req 0xAF --key-file private.pem dfufile.zip

hardware version:硬件版本nRF52832设置为52
softdevice firmware ID:协议栈ID,输入对应版本的ID
application-version 程序版本号
nrfutil pkg generate –help 可查询命令使用说明
可在SDK\components\softdevice\s132\doc\s132_nrf52_7.2.0_release-notes.pdf 查看获取The Firmware ID of this SoftDevice
7.2.0 对应0x0101

6.代码的烧写和合并

预先烧好协议栈和bootloader,然后通过DFU,可以正常运行。如果直接烧写协议栈bootloader和应用程序,是无法正常运行的,因为bootloader会检查settings页面的CRC,如果settings页面不存在,程序会继续停留在bootloader不会跳转

1.生成settings文件的方法

1
nrfutil settings generate --family NRF52 app.hex --application-version 1 --bootloader-version 1 --bl-settings-version 1 settings.hex

2.mergehex合并烧写

mergehex在command line tools中
命令格式

1
mergehex -m file1.hex file2.hex file3.hex -o output output_file.hex
-->

请我喝杯咖啡吧~

支付宝
微信