编译环境:MDK5.25
移植例程:pca10040_ble_debug和pca10040_uart_debug
PC端UART升级master:官方的nrfutil和博客Nordic nRF5 串口固件更新例子(C代码)
一、用mdk打开pca10040_ble_debug工程
目录:…\nRF5_SDK_15.3.0_59ac345\examples\dfu\secure_bootloader\pca10040_ble_debug\arm5_no_packs
二、由于bootloader采用了加密的方式进行升级,升级前比对密匙,正确则进行DFU操作,否则返回错误,具体参照前面网友的博客
三、添加文件
在nRF_DFU目录下添加nrf_dfu_serial.c nrf_dfu_serial_uart.c两个文件
在nRF_Drivers目录下添加nrf_drv_uart.c nrf_nvic.c nrf_soc.c nrfx_prs.c nrfx_uart.c nrfx_uarte.c
在nRF_Libraries目录中添加slip.c
在nRF_Log目录中添加nrf_log_backend_uart.c
四、往MDK添加宏定义
MBR_PRESENT DFU_UART_SUPPORT_EN
五、打开sdk_config.h文件,在文件尾部添加一下宏定义开关,有相同的部分可以删掉,由于官方做了非定义识别,所以也可以不删除
//
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 增加Serial DFU(UART DFU)刷机功能部分 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
//
#if defined (DFU_UART_SUPPORT_EN)
// <q> SLIP_ENABLED - slip - SLIP encoding and decoding
#ifndef SLIP_ENABLED
#define SLIP_ENABLED 1
#endif
// <h> nrf_dfu_serial_uart - UART DFU transport
//==========================================================
// <q> NRF_DFU_SERIAL_UART_USES_HWFC - HWFC configuration
#ifndef NRF_DFU_SERIAL_UART_USES_HWFC
#define NRF_DFU_SERIAL_UART_USES_HWFC 1
#endif
// <o> NRF_DFU_SERIAL_UART_RX_BUFFERS - Number of RX buffers.
// <i> Number of buffers depends on flash access vs.
// <i> transport throughtput. If value is too low it may lead
// <i> to received packets being dropped.
#ifndef NRF_DFU_SERIAL_UART_RX_BUFFERS
#define NRF_DFU_SERIAL_UART_RX_BUFFERS 3
#endif
// <h> nRF_Drivers
//==========================================================
// <e> NRFX_PRS_ENABLED - nrfx_prs - Peripheral Resource Sharing module
//==========================================================
#ifndef NRFX_PRS_ENABLED
#define NRFX_PRS_ENABLED 1
#endif
// <q> NRFX_PRS_BOX_0_ENABLED - Enables box 0 in the module.
#ifndef NRFX_PRS_BOX_0_ENABLED
#define NRFX_PRS_BOX_0_ENABLED 0
#endif
// <q> NRFX_PRS_BOX_1_ENABLED - Enables box 1 in the module.
#ifndef NRFX_PRS_BOX_1_ENABLED
#define NRFX_PRS_BOX_1_ENABLED 0
#endif
// <q> NRFX_PRS_BOX_2_ENABLED - Enables box 2 in the module.
#ifndef NRFX_PRS_BOX_2_ENABLED
#define NRFX_PRS_BOX_2_ENABLED 0
#endif
// <q> NRFX_PRS_BOX_3_ENABLED - Enables box 3 in the module.
#ifndef NRFX_PRS_BOX_3_ENABLED
#define NRFX_PRS_BOX_3_ENABLED 0
#endif
// <q> NRFX_PRS_BOX_4_ENABLED - Enables box 4 in the module.
#ifndef NRFX_PRS_BOX_4_ENABLED
#define NRFX_PRS_BOX_4_ENABLED 1
#endif
// <e> NRFX_PRS_CONFIG_LOG_ENABLED - Enables logging in the module.
//==========================================================
#ifndef NRFX_PRS_CONFIG_LOG_ENABLED
#define NRFX_PRS_CONFIG_LOG_ENABLED 0
#endif
// <o> NRFX_PRS_CONFIG_LOG_LEVEL - Default Severity level
// <0=> Off
// <1=> Error
// <2=> Warning
// <3=> Info
// <4=> Debug
#ifndef NRFX_PRS_CONFIG_LOG_LEVEL
#define NRFX_PRS_CONFIG_LOG_LEVEL 3
#endif
// <o> NRFX_PRS_CONFIG_INFO_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_PRS_CONFIG_INFO_COLOR
#define NRFX_PRS_CONFIG_INFO_COLOR 0
#endif
// <o> NRFX_PRS_CONFIG_DEBUG_COLOR - ANSI escape code prefix.
// <0=> Default
// <1=> Black
// <2=> Red
// <3=> Green
// <4=> Yellow
// <5=> Blue
// <6=> Magenta
// <7=> Cyan
// <8=> White
#ifndef NRFX_PRS_CONFIG_DEBUG_COLOR
#define NRFX_PRS_CONFIG_DEBUG_COLOR 0
#endif