解决NRF52832正常添加OTA代码后无法进入app一直运行在bootloader的问题!

问题现象描述:

SDK版本17.1.0
在 mergehex工具 合并以下文件

setting.hex
bootloader.hex
app.hex
sortdevice.hex

之后烧录固件第一次运行
程序一直运行在bootloader,蓝牙名称显示 DFUTARG ,必须要进行一次OTA才进入APP
注意:如果你连DFUTARG都没有搜到,说明打包步骤不对,以下步骤只适用于能搜带DFUTARG蓝牙后

在这里插入图片描述
!!! 仔细检查打包程序步骤,不能有误,不然依然进入不了app

方法1:更改芯片型号

keil工程是52810,但是自己的芯片是52832
只需修改keil里面的芯片型号为52832即可

方法2 :通过修改宏定义方法

1:用 keil 打开bootloader工程:
nRF5_SDK_17.1.0_ddde560\examples\dfu\secure_bootloader\pca10040e_s112_ble\arm5_no_packs
2:打开keil 工程设置的 C\C++ 的define 
	添加芯片型号 NRF52832_XXAA的宏定义,
	注意,如果用的是52832,但是里面却出现了52810_XXAA类似的其他型号的宏定义记得删掉

在这里插入图片描述

方法2步骤 :修改代码
3: 打开这个文件 :
nrf_bootloader_app_start_final.c
4:修改函数:
这个值有问题:BOOTLOADER_SETTINGS_ADDRESS
直接换成我们自己的型号setting.hex的起始位置

ret_code_t nrf_bootloader_flash_protect(uint32_t address, uint32_t size)
{
    if ((size & (CODE_PAGE_SIZE - 1)) || (address > BOOTLOADER_SETTINGS_ADDRESS))
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    。。。

修改后代码如下:
0x0007E000UL是根据宏定义追代码进去看到的,
52832的setting是放在flash顶部的;512k大小型号的是放在0x0007E000UL地址,版本2的setting占了2page
ret_code_t nrf_bootloader_flash_protect(uint32_t address, uint32_t size)
{
    if ((size & (CODE_PAGE_SIZE - 1)) || (address > 0x0007E000UL)) //BOOTLOADER_SETTINGS_ADDRESS
    {
        return NRF_ERROR_INVALID_PARAM;
    }
    。。。
修改main.c中代码:
屏蔽led的无用代码
/**
 * @brief Function notifies certain events in DFU process.
 */
static void dfu_observer(nrf_dfu_evt_type_t evt_type)
{
    switch (evt_type)
    {
        case NRF_DFU_EVT_DFU_FAILED:
        case NRF_DFU_EVT_DFU_ABORTED:
        case NRF_DFU_EVT_DFU_INITIALIZED:
            // bsp_board_init(BSP_INIT_LEDS);
            // bsp_board_led_on(BSP_BOARD_LED_0);
            // bsp_board_led_on(BSP_BOARD_LED_1);
            // bsp_board_led_off(BSP_BOARD_LED_2);
            break;
        case NRF_DFU_EVT_TRANSPORT_ACTIVATED:
            // bsp_board_led_off(BSP_BOARD_LED_1);
            // bsp_board_led_on(BSP_BOARD_LED_2);
            break;
        case NRF_DFU_EVT_DFU_STARTED:
            break;
        default:
            break;
    }
}

步骤3 :检查falsh中固件存放位置

使用工具 Programmer v4.2.0
点击add file 把setting bootloader app 加进去看flash位置有没有冲突
把bootloader放在挨着setting.hex的地方 ,这个只需要去修改keil里面ROM的位置就行了

在这里插入图片描述
我的seting放在0x7E000的位置 减去bootloader的大小,刚刚好从0x78000开始放
bootloader的大小用上面的progammer软件就可以确定,鼠标放在途中红色位置就会显示大小和起始位置
在这里插入图片描述

最后 编译bootloader

以下是基于nrf52832的空中升级(OTA代码示例: ``` #include <stdint.h> #include <stdbool.h> #include "nrf.h" #include "nrf_sdm.h" #include "nrf_gpio.h" #include "nrf_delay.h" #include "nrf_drv_clock.h" #include "nrf_drv_power.h" #include "nrf_dfu.h" #include "nrf_dfu_flash.h" #include "nrf_dfu_handling_error.h" #include "nrf_dfu_settings.h" #include "nrf_dfu_transport.h" #include "nrf_dfu_utils.h" #include "nrf_dfu_validation.h" #include "nrf_bootloader_info.h" #define LED_PIN 13 static void leds_init() { nrf_gpio_cfg_output(LED_PIN); } static void leds_on() { nrf_gpio_pin_clear(LED_PIN); } static void leds_off() { nrf_gpio_pin_set(LED_PIN); } /** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; // Initialize the clock. err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); // Start the low-frequency clock. nrf_drv_clock_lfclk_request(NULL); // Initialize the power module. err_code = nrf_drv_power_init(NULL); APP_ERROR_CHECK(err_code); // Initialize the LED pins. leds_init(); // Wait for the power module to be initialized. while (!nrf_drv_power_usb_detected()) { nrf_delay_ms(100); } // Turn on the LED. leds_on(); // Initialize the DFU module. err_code = nrf_dfu_settings_init(true); APP_ERROR_CHECK(err_code); // Register the transport layer. err_code = nrf_dfu_transport_register(nrf_dfu_uart_transport); APP_ERROR_CHECK(err_code); // Start the DFU module. err_code = nrf_dfu_init(); APP_ERROR_CHECK(err_code); // Turn off the LED. leds_off(); // Enter the main loop. while (true) { nrf_dfu_continue(); } } ``` 以上代码实现了空中升级(OTA)的基本流程,具体实现方式可以根据实际需要进行调整。在使用该代码之前,需要确保已经在芯片中烧录了DFU bootloader,并且已经在固件中添加OTA升级的相关代码
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

漏洞百出

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

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

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

打赏作者

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

抵扣说明:

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

余额充值