nRF52832 DFU Service
2018-11-14 本文已影响141人
a2633063
为了更好的实现DFU控制升级功能,为设备增加一个DFU Service,实现手机连接设备后修改此service中的Characteristic值,能够直接重启设备至BootLoader实现不需要手动重启就能够自动进入Bootloader进行DFU的功能.
Nordic自身的DFU Service增加非常简单:
正式release时:
// Initialize the async SVCI interface to bootloader.
err_code = ble_dfu_buttonless_async_svci_init();
APP_ERROR_CHECK(err_code);
dfus_init.evt_handler = ble_dfu_evt_handler;
//Initialize the duf
err_code = ble_dfu_buttonless_init(&dfus_init);
APP_ERROR_CHECK(err_code);
如果设备当前没有bootloader,只有softdevice和application,那么ble_dfu_buttonless_async_svci_init
会返回NRF_ERROR_NO_MEM
错误,最开始开发时可能并不会同时吧bootloader一并烧录进去,所以在调试时增加了一个判断返回的错误是否是NRF_ERROR_NO_MEM
的判断.
此处最好再增加#ifdef来判断实现release时编译使用上面那段正式的代码防止出错
// Initialize the async SVCI interface to bootloader.
err_code = ble_dfu_buttonless_async_svci_init();
if(NRF_ERROR_NO_MEM!=err_code) {
//APP_ERROR_CHECK(err_code);
dfus_init.evt_handler = ble_dfu_evt_handler;
//Initialize the duf
err_code = ble_dfu_buttonless_init(&dfus_init);
APP_ERROR_CHECK(err_code);
}
补上需要的头文件及sdk_config.h配置:
时间太久,可能有遗漏
头文件
#include "ble_dfu.h"
sdk_config.h:
使能 nrf_DFU
/ble_dfu
/BLE_DFU_ENABLED
增加这些后,设备的ble service中就会多出这个
![](https://img.haomeiwen.com/i13211701/6c24b67167c7becb.png)