nRF52基于SDK16 UART DFU移植

本文详细介绍了如何在nRF52 SDK16中移植UART Device Firmware Upgrade (DFU),包括添加C文件、设置头文件路径、宏定义修改、sdk_config.h配置以及主程序代码的调整。同时,文章还提到了Markdown语法和编辑器功能,如代码片段、列表、表格、居中对齐、注脚、KaTeX公式、甘特图、UML图表和Flowchart流程图的使用。
摘要由CSDN通过智能技术生成

1、添加C文件:
nRF5_SDK_16.0.0_98a08e2\components\ble\ble_services\ble_dfu\ble_dfu.c
nRF5_SDK_16.0.0_98a08e2\components\ble\ble_services\ble_dfu\ble_dfu_bonded.c
nRF5_SDK_16.0.0_98a08e2\components\ble\ble_services\ble_dfu\ble_dfu_unbonded.c
nRF5_SDK_16.0.0_98a08e2\components\libraries\bootloader\dfu\nrf_dfu_svci.c
2、添加头文件路径
…\Libraries\components\libraries\svc
…\Libraries\components\libraries\bootloader
…\Libraries\components\libraries\bootloader\dfu
…\Libraries\components\libraries\bootloader\ble_dfu
…\Libraries\components\ble\ble_services\ble_dfu
…\Libraries\components\softdevice\mbr\nrf52832\headers
3、添加宏
1)BLE_SETTINGS_ACCESS_ONLY
2)NRF_DFU_SVCI_ENABLED
3)NRF_DFU_TRANSPORT_BLE=1
4.修改sdk_config.h文件
1)使能DFU模块
#ifndef BLE_DFU_ENABLED
#define BLE_DFU_ENABLED 1
#endif
2)修改使用的自定义UUID数量,每添加一个都要修改工程中RAM的开始地址和使用大小,1个UUID占用的RAM大小为0x10 根据实际使用的自定义UUID个数修改
#ifndef NRF_SDH_BLE_VS_UUID_COUNT
#define NRF_SDH_BLE_VS_UUID_COUNT 2
#endif
5、修改主程序代码
1)包含头文件

#include "nrf_power.h"
#include "nrf_bootloader_info.h"
#include "nrf_dfu_ble.h"
#include "ble_dfu.h"
#include "nrf_dfu_ble_svci_bond_sharing.h"
#include "nrf_svci_async_function.h"
#include "nrf_svci_async_handler.h"

2)添加DFU初始化代码并将其加入服务初始化函数
//获取广播参数

static void advertising_config_get(ble_adv_modes_config_t * p_config)
{
   
    memset(p_config, 0, sizeof(ble_adv_modes_config_t));

    p_config->ble_adv_fast_enabled  = true;
    p_config->ble_adv_fast_interval = APP_ADV_INTERVAL;
    p_config->ble_adv_fast_timeout  = APP_ADV_DURATION;
}

//断开连接

static void disconnect(uint16_t conn_handle, void * p_context)
{
   
    UNUSED_PARAMETER(p_context);

    ret_code_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    if (err_code != NRF_SUCCESS)
    {
   
        NRF_LOG_WARNING("Failed to disconnect connection. Connection handle: %d Error: %d", conn_handle, err_code);
    }
    else
    {
   
        NRF_LOG_DEBUG("Disconnected connection handle %d", conn_handle);
    }

//初始化DFU服务

static void dfu_s_init(void)
{
   
	    uint32_t err_code;
	    ble_dfu_buttonless_init_t dfus_init = {
   0};
	
	    memset(&dfus_init, 0, sizeof(dfus_init));
	    
	    dfus_init.evt_handler = ble_dfu_evt_handler; //注册DFU回调函数
	    err_code = ble_dfu_buttonless_init(&dfus_init);
	    APP_ERROR_CHECK(err_code);  
}

//将DFU服务添加进services_init()函数

static void services_init(void)
{
   
    dfu_s_init();
}

//DFU回调函数

static void ble_dfu_evt_handler(ble_dfu_buttonless_evt_type_t event)
{
   
    switch (event)                                        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

200801030254

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值