nRF52832 BLE_DFU空中升级OTA(三)准备升级工程(SDK14.2.0)

准备需要加入DFU功能的工程

在工程main文件services_init函数中加入DFU服务

 1 uint32_t err_code;
 2 
 3 // Initialize the async SVCI interface to bootloader.
 4 err_code = ble_dfu_buttonless_async_svci_init();
 5 //APP_ERROR_CHECK(err_code);
 6 if(NRF_ERROR_NO_MEM != err_code) 
 7 {
 8     ble_dfu_buttonless_init_t dfus_init =
 9     {
10         .evt_handler = ble_dfu_evt_handler
11     };
12  
13     err_code = ble_dfu_buttonless_init(&dfus_init);
14     APP_ERROR_CHECK(err_code);
15 }

 

加入DFU事件处理函数

 1 // YOUR_JOB: Update this code if you want to do anything given a DFU event (optional).
 2 /**@brief Function for handling dfu events from the Buttonless Secure DFU service
 3  *
 4  * @param[in]   event   Event from the Buttonless Secure DFU service.
 5  */
 6 static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
 7 {
 8     switch (event)
 9     {
10         case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE:
11             NRF_LOG_INFO("Device is preparing to enter bootloader mode.");
12             // YOUR_JOB: Disconnect all bonded devices that currently are connected.
13             //           This is required to receive a service changed indication
14             //           on bootup after a successful (or aborted) Device Firmware Update.
15             break;
16 
17         case BLE_DFU_EVT_BOOTLOADER_ENTER:
18             // YOUR_JOB: Write app-specific unwritten data to FLASH, control finalization of this
19             //           by delaying reset by reporting false in app_shutdown_handler
20             NRF_LOG_INFO("Device will enter bootloader mode.");
21             break;
22 
23         case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:
24             NRF_LOG_ERROR("Request to enter bootloader mode failed asynchroneously.");
25             // YOUR_JOB: Take corrective measures to resolve the issue
26             //           like calling APP_ERROR_CHECK to reset the device.
27             break;
28 
29         case BLE_DFU_EVT_RESPONSE_SEND_ERROR:
30             NRF_LOG_ERROR("Request to send a response to client failed.");
31             // YOUR_JOB: Take corrective measures to resolve the issue
32             //           like calling APP_ERROR_CHECK to reset the device.
33             APP_ERROR_CHECK(false);
34             break;
35 
36         default:
37             NRF_LOG_ERROR("Unknown event from ble_dfu_buttonless.");
38             break;
39     }
40 }

 

加入几个必要的文件到工程

SDK_14.2.0工程\components\ble\ble_services\ble_dfu下的

 

SDK_14.2.0工程\components\libraries\bootloader\dfu下的

 

并加入以下头文件路径

SDK_14.2.0工程\components\libraries\bootloader\dfu

SDK_14.2.0工程\components\libraries\svc

 

Main.c 头文件中加入

#include "ble_dfu.h"

 

记得修改sdk_config.hNRF_SDH_BLE_VS_UUID_COUNT

1 // <o> NRF_SDH_BLE_VS_UUID_COUNT - The number of vendor-specific UUIDs. 
2 #ifndef NRF_SDH_BLE_VS_UUID_COUNT
3 #define NRF_SDH_BLE_VS_UUID_COUNT 1    //默认为0
4 #endif 

 

开启RTT打印LOG

1 //==========================================================
2 // <e> NRF_LOG_ENABLED - Logging module for nRF5 SDK
3 //==========================================================
4 #ifndef NRF_LOG_ENABLED
5 #define NRF_LOG_ENABLED 1
6 #endif

以及

1 //==========================================================
2 // <e> NRF_LOG_BACKEND_RTT_ENABLED - nrf_log_backend_rtt - Log RTT backend
3 //==========================================================
4 #ifndef NRF_LOG_BACKEND_RTT_ENABLED
5 #define NRF_LOG_BACKEND_RTT_ENABLED 1
6 #endif

 

编译一下,下载观察RTT信息修改RAM地址,再次编译后没有问题,就可以用新生成的hex文件来制作升级zip了。

posted @ 2018-12-10 11:38  将就一下  阅读(2041)  评论(0编辑  收藏  举报