This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NCS OTA DFU failed in nrf52832

Hi,

 I am trying to test and develop the DFU-OTA in nRF CONNECT SDK for nRF52832

I followed these link to develop  i am using NCS v1.4.2

1. I have copied the peripheral_lbs code to my workspace

2. Based on the link i have added few things and here i attached the related files

main.c

/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
 */

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <sys/printk.h>
#include <sys/byteorder.h>
#include <zephyr.h>
#include <drivers/gpio.h>
#include <soc.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>

#include <bluetooth/services/lbs.h>

#include <settings/settings.h>

#include <dk_buttons_and_leds.h>

// For FOTA
#include <tinycbor/cbor.h>
#include "cborattr/cborattr.h"
#include <mgmt/mgmt.h>
#include <mgmt/mcumgr/smp_bt.h>
#include <mgmt/mcumgr/buf.h>
#include <mgmt/mcumgr/smp.h>
#include "os_mgmt/os_mgmt.h"
#include "os_mgmt/os_mgmt_impl.h"
#include "os_mgmt/os_mgmt_config.h"
#include "img_mgmt/image.h"
#include "img_mgmt/img_mgmt.h"
#include "img_mgmt/img_mgmt_impl.h"
#include "img_mgmt/img_mgmt_config.h"

#define DEVICE_NAME             CONFIG_BT_DEVICE_NAME
#define DEVICE_NAME_LEN         (sizeof(DEVICE_NAME) - 1)


#define RUN_STATUS_LED          DK_LED1
#define CON_STATUS_LED          DK_LED2
#define RUN_LED_BLINK_INTERVAL  1000

#define USER_LED                DK_LED3

#define USER_BUTTON             DK_BTN1_MSK

static bool app_button_state;

static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
	BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
};

static const struct bt_data sd[] = {
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_LBS_VAL),
};

static void connected(struct bt_conn *conn, uint8_t err)
{
	if (err) {
		printk("Connection failed (err %u)\n", err);
		return;
	}

	printk("Connected\n");

	dk_set_led_on(CON_STATUS_LED);
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	printk("Disconnected (reason %u)\n", reason);

	dk_set_led_off(CON_STATUS_LED);
}

#ifdef CONFIG_BT_LBS_SECURITY_ENABLED
static void security_changed(struct bt_conn *conn, bt_security_t level,
			     enum bt_security_err err)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	if (!err) {
		printk("Security changed: %s level %u\n", addr, level);
	} else {
		printk("Security failed: %s level %u err %d\n", addr, level,
			err);
	}
}
#endif

static struct bt_conn_cb conn_callbacks = {
	.connected        = connected,
	.disconnected     = disconnected,
#ifdef CONFIG_BT_LBS_SECURITY_ENABLED
	.security_changed = security_changed,
#endif
};

#if defined(CONFIG_BT_LBS_SECURITY_ENABLED)
static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	printk("Passkey for %s: %06u\n", addr, passkey);
}

static void auth_cancel(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	printk("Pairing cancelled: %s\n", addr);
}

static void pairing_confirm(struct bt_conn *conn)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	bt_conn_auth_pairing_confirm(conn);

	printk("Pairing confirmed: %s\n", addr);
}

static void pairing_complete(struct bt_conn *conn, bool bonded)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	printk("Pairing completed: %s, bonded: %d\n", addr, bonded);
}

static void pairing_failed(struct bt_conn *conn, enum bt_security_err reason)
{
	char addr[BT_ADDR_LE_STR_LEN];

	bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

	printk("Pairing failed conn: %s, reason %d\n", addr, reason);
}

static struct bt_conn_auth_cb conn_auth_callbacks = {
	.passkey_display = auth_passkey_display,
	.cancel = auth_cancel,
	.pairing_confirm = pairing_confirm,
	.pairing_complete = pairing_complete,
	.pairing_failed = pairing_failed
};
#else
static struct bt_conn_auth_cb conn_auth_callbacks;
#endif

static void app_led_cb(bool led_state)
{
	dk_set_led(USER_LED, led_state);
}

static bool app_button_cb(void)
{
	return app_button_state;
}

static struct bt_lbs_cb lbs_callbacs = {
	.led_cb    = app_led_cb,
	.button_cb = app_button_cb,
};

static void button_changed(uint32_t button_state, uint32_t has_changed)
{
	if (has_changed & USER_BUTTON) {
		bt_lbs_send_button_state(button_state);
		app_button_state = button_state ? true : false;
	}
}

static int init_button(void)
{
	int err;

	err = dk_buttons_init(button_changed);
	if (err) {
		printk("Cannot init buttons (err: %d)\n", err);
	}

	return err;
}

void main(void)
{
	int blink_status = 0;
	int err;

	printk("Starting Bluetooth Peripheral LBS example\n");
        printk("Application build time: %s %s \n", __DATE__, __TIME__);
	err = dk_leds_init();
	if (err) {
		printk("LEDs init failed (err %d)\n", err);
		return;
	}

	err = init_button();
	if (err) {
		printk("Button init failed (err %d)\n", err);
		return;
	}

	bt_conn_cb_register(&conn_callbacks);
	if (IS_ENABLED(CONFIG_BT_LBS_SECURITY_ENABLED)) {
		bt_conn_auth_cb_register(&conn_auth_callbacks);
	}

	err = bt_enable(NULL);
	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}

	printk("Bluetooth initialized\n");

	if (IS_ENABLED(CONFIG_SETTINGS)) {
		settings_load();
	}

	err = bt_lbs_init(&lbs_callbacs);
	if (err) {
		printk("Failed to init LBS (err:%d)\n", err);
		return;
	}

	err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad),
			      sd, ARRAY_SIZE(sd));
	if (err) {
		printk("Advertising failed to start (err %d)\n", err);
		return;
	}

	printk("Advertising successfully started\n");
        // For FOTA
  os_mgmt_register_group();
  img_mgmt_register_group();
  smp_bt_register();

	for (;;) {
		dk_set_led(RUN_STATUS_LED, (++blink_status) % 2);
		k_sleep(K_MSEC(RUN_LED_BLINK_INTERVAL));
	}
}

prj.conf

#
# Copyright (c) 2018 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
CONFIG_NCS_SAMPLES_DEFAULTS=y

CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Nordic_Blinky"

# Enable the LBS service
CONFIG_BT_LBS=y
CONFIG_BT_LBS_POLL_BUTTON=y
CONFIG_DK_LIBRARY=y

# Added for FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_OS_MGMT=y
CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_SMP_BT=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048

also added full .zip file here

1447.dfu_app.zip

3. After successful compilation of the code uploaded to the Empty nRF52 DK (there is no bootloader separately added before )

4. Successfully showing the services in the nRF connect APP while entering into DFU

5. On the other-side i have just changed the device name to dfu_nrf_blinky

6. taken the build and app_update.bin is taken to mobile device

7. While initialize the DFU it asked for pairing and also paired with the device with valid key.

8. And on entering to start DFU it was disconnected like this and video is linked below with respective log

Log in the serial

*** Booting Zephyr OS build v2.4.0-ncs2  ***
[00:00:00.528,289] [0m<inf> mcuboot: Starting bootloader[0m
[00:00:00.534,576] [0m<inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3[0m
[00:00:00.545,043] [0m<inf> mcuboot: Boot source: none[0m
[00:00:00.550,781] [0m<inf> mcuboot: Swap type: none[0m
[00:00:00.844,512] [0m<inf> mcuboot: Bootloader chainload address offset: 0xc000[0m
[00:00:00.852,508] [0m<inf> mcuboot: Jumping to the first image slot[0m
*** Booting Zephyr OS build v2.4.0-ncs2  ***
Starting Bluetooth Peripheral LBS example
Application build time: Mar 15 2021 14:36:28 
I: 2 Sectors of 4096 bytes
I: alloc wra: 0, ff0
I: data wra: 0, 0
I: SoftDevice Controller build revision: 
I: cf 5c 0f 11 88 9c d7 02 |.\......
I: 15 27 c7 c3 ca 60 19 85 |.'...`..
I: b7 c4 50 e3             |..P.    
I: No ID address. App must call settings_load()
Bluetooth initialized
Advertising successfully started
Connected
Passkey for 7e:2a:18:a3:a2:3c (random): 757200
Security changed: 7e:2a:18:a3:a2:3c (random) level 4
Pairing completed: 7c:78:7e:78:66:b3 (public), bonded: 1
Disconnected (reason 19)
Connected
Security changed: 7c:78:7e:78:66:b3 (public) level 4
Disconnected (reason 19)
Connected
Security changed: 7c:78:7e:78:66:b3 (public) level 4
Disconnected (reason 19)
Connected
Security changed: 7c:78:7e:78:66:b3 (public) level 4

Log from the nrf connect APP

nRF Connect, 2021-03-15
Nordic_Blinky (FB:B4:FA:11:EB:63)
V	14:54:14.912	Connecting to FB:B4:FA:11:EB:63...
D	14:54:14.912	gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferred PHY = LE 1M)
D	14:54:15.042	[Broadcast] Action received: android.bluetooth.device.action.ACL_CONNECTED
D	14:54:15.096	[Callback] Connection state changed with status: 0 and new state: CONNECTED (2)
I	14:54:15.097	Connected to FB:B4:FA:11:EB:63
D	14:54:15.099	wait(1600ms)
D	14:54:15.360	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDING (11)
D	14:54:15.421	[Broadcast] Action received: android.bluetooth.device.action.BOND_STATE_CHANGED, bond state changed to: BOND_BONDED (12)
I	14:54:15.421	Device bonded
I	14:54:15.616	Connection parameters updated (interval: 7.5ms, latency: 0, timeout: 5000ms)
I	14:54:16.023	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 5000ms)
V	14:54:16.700	Discovering services...
D	14:54:16.700	gatt.discoverServices()
D	14:54:16.713	[Callback] Services discovered with status: 0
I	14:54:16.714	Services discovered
V	14:54:16.737	Generic Attribute (0x1801)
- Service Changed [I] (0x2A05)
   Client Characteristic Configuration (0x2902)
- Client Supported Features [R W] (0x2B29)
- Database Hash [R] (0x2B2A)
Generic Access (0x1800)
- Device Name [R] (0x2A00)
- Appearance [R] (0x2A01)
- Peripheral Preferred Connection Parameters [R] (0x2A04)
Nordic LED Button Service (00001523-1212-efde-1523-785feabcd123)
- Button [N R] (00001524-1212-efde-1523-785feabcd123)
   Client Characteristic Configuration (0x2902)
- LED [W] (00001525-1212-efde-1523-785feabcd123)
SMP Service (8d53dc1d-1db7-4cd3-868b-8a527460aa84)
- SMP Characteristic [N WNR] (da2e7828-fbce-4e01-ae9e-261174997c48)
   Client Characteristic Configuration (0x2902)
D	14:54:16.738	gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
D	14:54:16.740	gatt.setCharacteristicNotification(00001524-1212-efde-1523-785feabcd123, true)
I	14:54:20.973	Connection parameters updated (interval: 45.0ms, latency: 0, timeout: 420ms)
V	14:54:22.707	[McuMgr] Connecting...
D	14:54:22.720	[McuMgr] gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
D	14:54:22.751	[McuMgr] [Callback] Connection state changed with status: 0 and new state: 2 (CONNECTED)
I	14:54:22.767	[McuMgr] Connected to FB:B4:FA:11:EB:63
D	14:54:22.786	[McuMgr] wait(1600)
V	14:54:24.400	[McuMgr] Discovering services...
D	14:54:24.418	[McuMgr] gatt.discoverServices()
I	14:54:24.472	[McuMgr] Services discovered
V	14:54:24.483	[McuMgr] Primary service found
I	14:54:24.500	[McuMgr] Service Changed characteristic found on a bonded device
D	14:54:24.513	[McuMgr] gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
V	14:54:24.550	[McuMgr] Enabling indications for 00002a05-0000-1000-8000-00805f9b34fb
D	14:54:24.561	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x02-00)
I	14:54:24.662	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 02-00
I	14:54:24.672	[McuMgr] Service Changed notifications enabled
V	14:54:24.695	[McuMgr] Requesting new MTU...
D	14:54:24.705	[McuMgr] gatt.requestMtu(515)
I	14:54:24.797	[McuMgr] MTU changed to: 65
D	14:54:24.807	[McuMgr] gatt.setCharacteristicNotification(da2e7828-fbce-4e01-ae9e-261174997c48, true)
V	14:54:24.831	[McuMgr] Enabling notifications for da2e7828-fbce-4e01-ae9e-261174997c48
D	14:54:24.852	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x01-00)
I	14:54:24.979	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
I	14:54:24.992	[McuMgr] Notifications enabled
V	14:54:25.034	[McuMgr] Writing characteristic da2e7828-fbce-4e01-ae9e-261174997c48 (WRITE COMMAND)
D	14:54:25.047	[McuMgr] gatt.writeCharacteristic(da2e7828-fbce-4e01-ae9e-261174997c48)
I	14:54:25.066	[McuMgr] Data written to da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 00-00-00-02-00-01-00-00-BF-FF
A	14:54:25.106	[McuMgr] "Operation: READ
Flags: 0
Length: 2
Group Id: 1 (IMAGE)
Sequence Num: 0
Command Id: 0 (STATE)
Message: {}" sent
I	14:54:25.124	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 01-00-00-86-00-01-00-00-BF-66-69-6D-61-67-65-73-9F-BF-64-73-6C-6F-74-00-67-76-65-72-73-69-6F-6E-65-30-2E-30-2E-30-64-68-61-73-68-58-20-AC-9F-71-AD-D4-4D-30-DB-72-07-FB-55-47-69-4B-33-95
I	14:54:25.161	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 8E-0A-87-5A-57-1A-5A-E0-48-51-DB-E1-28-88-C5-68-62-6F-6F-74-61-62-6C-65-F5-67-70-65-6E-64-69-6E-67-F4-69-63-6F-6E-66-69-72-6D-65-64-F5-66-61-63-74-69-76-65-F5-69-70-65-72-6D-61-6E-65-6E
I	14:54:25.174	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 74-F4-FF-FF-6B-73-70-6C-69-74-53-74-61-74-75-73-00-FF
A	14:54:25.209	[McuMgr] "{"images":[{"slot":0,"version":"0.0.0","hash":"rJ9xrdRNMNtyB/tVR2lLM5WOCodaVxpa4EhR2+EoiMU=","bootable":true,"pending":false,"confirmed":true,"active":true,"permanent":false}],"splitStatus":0}" received
V	14:54:25.227	[McuMgr] Uploading firmware...
I	14:54:46.130	Notification received from 00001524-1212-efde-1523-785feabcd123, value: (0x) 01
A	14:54:46.130	"Button pressed" received
I	14:54:46.488	Notification received from 00001524-1212-efde-1523-785feabcd123, value: (0x) 00
A	14:54:46.488	"Button released" received
I	14:54:47.030	Notification received from 00001524-1212-efde-1523-785feabcd123, value: (0x) 01
A	14:54:47.030	"Button pressed" received
I	14:54:47.431	Notification received from 00001524-1212-efde-1523-785feabcd123, value: (0x) 00
A	14:54:47.431	"Button released" received
V	14:54:55.459	[McuMgr] Connecting...
D	14:54:55.711	[McuMgr] gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
D	14:54:55.828	[McuMgr] [Callback] Connection state changed with status: 0 and new state: 2 (CONNECTED)
I	14:54:55.853	[McuMgr] Connected to FB:B4:FA:11:EB:63
D	14:54:55.887	[McuMgr] wait(1600)
I	14:54:55.906	[McuMgr] MTU changed to: 65
V	14:54:57.503	[McuMgr] Discovering services...
D	14:54:57.522	[McuMgr] gatt.discoverServices()
I	14:54:57.542	[McuMgr] Services discovered
V	14:54:57.558	[McuMgr] Primary service found
I	14:54:57.589	[McuMgr] Service Changed characteristic found on a bonded device
D	14:54:57.602	[McuMgr] gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
V	14:54:57.643	[McuMgr] Enabling indications for 00002a05-0000-1000-8000-00805f9b34fb
D	14:54:57.659	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x02-00)
I	14:54:57.739	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 02-00
I	14:54:57.748	[McuMgr] Service Changed notifications enabled
V	14:54:57.779	[McuMgr] Requesting new MTU...
D	14:54:57.796	[McuMgr] gatt.requestMtu(515)
I	14:54:57.873	[McuMgr] MTU changed to: 65
D	14:54:57.884	[McuMgr] gatt.setCharacteristicNotification(da2e7828-fbce-4e01-ae9e-261174997c48, true)
V	14:54:57.913	[McuMgr] Enabling notifications for da2e7828-fbce-4e01-ae9e-261174997c48
D	14:54:57.923	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x01-00)
I	14:54:58.053	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
I	14:54:58.063	[McuMgr] Notifications enabled
V	14:54:58.092	[McuMgr] Writing characteristic da2e7828-fbce-4e01-ae9e-261174997c48 (WRITE COMMAND)
D	14:54:58.103	[McuMgr] gatt.writeCharacteristic(da2e7828-fbce-4e01-ae9e-261174997c48)
I	14:54:58.118	[McuMgr] Data written to da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 00-00-00-02-00-01-00-00-BF-FF
A	14:54:58.132	[McuMgr] "Operation: READ
Flags: 0
Length: 2
Group Id: 1 (IMAGE)
Sequence Num: 0
Command Id: 0 (STATE)
Message: {}" sent
I	14:54:58.206	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 01-00-00-86-00-01-00-00-BF-66-69-6D-61-67-65-73-9F-BF-64-73-6C-6F-74-00-67-76-65-72-73-69-6F-6E-65-30-2E-30-2E-30-64-68-61-73-68-58-20-AC-9F-71-AD-D4-4D-30-DB-72-07-FB-55-47-69-4B-33-95
I	14:54:58.252	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 8E-0A-87-5A-57-1A-5A-E0-48-51-DB-E1-28-88-C5-68-62-6F-6F-74-61-62-6C-65-F5-67-70-65-6E-64-69-6E-67-F4-69-63-6F-6E-66-69-72-6D-65-64-F5-66-61-63-74-69-76-65-F5-69-70-65-72-6D-61-6E-65-6E
I	14:54:58.267	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 74-F4-FF-FF-6B-73-70-6C-69-74-53-74-61-74-75-73-00-FF
A	14:54:58.316	[McuMgr] "{"images":[{"slot":0,"version":"0.0.0","hash":"rJ9xrdRNMNtyB/tVR2lLM5WOCodaVxpa4EhR2+EoiMU=","bootable":true,"pending":false,"confirmed":true,"active":true,"permanent":false}],"splitStatus":0}" received
V	14:54:58.335	[McuMgr] Uploading firmware...
V	14:55:15.765	Disconnecting...
D	14:55:15.765	gatt.disconnect()
D	14:55:15.809	[Callback] Connection state changed with status: 0 and new state: DISCONNECTED (0)
I	14:55:15.809	Disconnected
D	14:55:16.833	[Broadcast] Action received: android.bluetooth.device.action.ACL_DISCONNECTED

nRF Connect, 2021-03-15
Nordic_Blinky (FB:B4:FA:11:EB:63)
V	15:07:18.490	[McuMgr] Connecting...
D	15:07:18.500	[McuMgr] gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, LE 1M)
D	15:07:18.520	[McuMgr] [Callback] Connection state changed with status: 0 and new state: 2 (CONNECTED)
I	15:07:18.534	[McuMgr] Connected to FB:B4:FA:11:EB:63
D	15:07:18.548	[McuMgr] wait(1600)
V	15:07:20.167	[McuMgr] Discovering services...
D	15:07:20.176	[McuMgr] gatt.discoverServices()
I	15:07:20.198	[McuMgr] Services discovered
V	15:07:20.229	[McuMgr] Primary service found
I	15:07:20.257	[McuMgr] Service Changed characteristic found on a bonded device
D	15:07:20.268	[McuMgr] gatt.setCharacteristicNotification(00002a05-0000-1000-8000-00805f9b34fb, true)
V	15:07:20.290	[McuMgr] Enabling indications for 00002a05-0000-1000-8000-00805f9b34fb
D	15:07:20.299	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x02-00)
I	15:07:20.379	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 02-00
I	15:07:20.390	[McuMgr] Service Changed notifications enabled
V	15:07:20.417	[McuMgr] Requesting new MTU...
D	15:07:20.427	[McuMgr] gatt.requestMtu(515)
I	15:07:20.514	[McuMgr] MTU changed to: 65
D	15:07:20.525	[McuMgr] gatt.setCharacteristicNotification(da2e7828-fbce-4e01-ae9e-261174997c48, true)
V	15:07:20.561	[McuMgr] Enabling notifications for da2e7828-fbce-4e01-ae9e-261174997c48
D	15:07:20.577	[McuMgr] gatt.writeDescriptor(00002902-0000-1000-8000-00805f9b34fb, value=0x01-00)
I	15:07:20.741	[McuMgr] Data written to descr. 00002902-0000-1000-8000-00805f9b34fb, value: (0x) 01-00
I	15:07:20.760	[McuMgr] Notifications enabled
V	15:07:20.816	[McuMgr] Writing characteristic da2e7828-fbce-4e01-ae9e-261174997c48 (WRITE COMMAND)
D	15:07:20.832	[McuMgr] gatt.writeCharacteristic(da2e7828-fbce-4e01-ae9e-261174997c48)
I	15:07:20.853	[McuMgr] Data written to da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 00-00-00-02-00-01-00-00-BF-FF
A	15:07:20.874	[McuMgr] "Operation: READ
Flags: 0
Length: 2
Group Id: 1 (IMAGE)
Sequence Num: 0
Command Id: 0 (STATE)
Message: {}" sent
I	15:07:20.923	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 01-00-00-86-00-01-00-00-BF-66-69-6D-61-67-65-73-9F-BF-64-73-6C-6F-74-00-67-76-65-72-73-69-6F-6E-65-30-2E-30-2E-30-64-68-61-73-68-58-20-AC-9F-71-AD-D4-4D-30-DB-72-07-FB-55-47-69-4B-33-95
I	15:07:20.938	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 8E-0A-87-5A-57-1A-5A-E0-48-51-DB-E1-28-88-C5-68-62-6F-6F-74-61-62-6C-65-F5-67-70-65-6E-64-69-6E-67-F4-69-63-6F-6E-66-69-72-6D-65-64-F5-66-61-63-74-69-76-65-F5-69-70-65-72-6D-61-6E-65-6E
I	15:07:20.978	[McuMgr] Notification received from da2e7828-fbce-4e01-ae9e-261174997c48, value: (0x) 74-F4-FF-FF-6B-73-70-6C-69-74-53-74-61-74-75-73-00-FF
A	15:07:21.028	[McuMgr] "{"images":[{"slot":0,"version":"0.0.0","hash":"rJ9xrdRNMNtyB/tVR2lLM5WOCodaVxpa4EhR2+EoiMU=","bootable":true,"pending":false,"confirmed":true,"active":true,"permanent":false}],"splitStatus":0}" received
V	15:07:21.044	[McuMgr] Uploading firmware...

Parents
  • Hi,

    I do not see any indication on what goes wrong. Can you try with another DFU master (other phone and/or other app)? Still same behavior? Perhaps you could get more debug information from the nRF log by adding this in you rprj.conf:

    CONFIG_LOG_DEFAULT_LEVEL=4
    CONFIG_DEBUG_OPTIMIZATIONS=y

  • This line is adding when i use iphone

    W: Ignoring data for unknown CID 0x003a

    Before uploading the first application code

    where we need to upload bootloader code as like nRF5 SDK?

  • As per the note I have changed the .dts file

    partitions {
    		compatible = "fixed-partitions";
    		#address-cells = <1>;
    		#size-cells = <1>;
    
    		boot_partition: partition@0 {
    			label = "mcuboot";
    			reg = <0x00000000 0xc000>;
    		};
    		slot0_partition: partition@c000 {
    			label = "image-0";
    			reg = <0x0000C000 0x32000>;
    		};
    		slot1_partition: partition@3e000 {
    			label = "image-1";
    			reg = <0x0003E000 0x32000>;
    		};
    		scratch_partition: partition@70000 {
    			label = "image-scratch";
    			reg = <0x00070000 0xa000>;
    		};
    		storage_partition: partition@7a000 {
    			label = "storage";
    			reg = <0x0007a000 0x00006000>;
    		};
    	};

    check the size whether i made it correct ?

    Even though I changed it like above I got same no free space issue

    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    [00:00:00.271,820] [0m<inf> mcuboot: Starting bootloader[0m
    [00:00:00.278,137] [0m<inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3[0m
    [00:00:00.288,543] [0m<inf> mcuboot: Boot source: none[0m
    [00:00:00.294,281] [0m<inf> mcuboot: Swap type: perm[0m
    [00:00:00.613,555] [1;33m<wrn> mcuboot: Not enough free space to run swap upgrade[0m
    [00:00:00.935,668] [0m<inf> mcuboot: Bootloader chainload address offset: 0xc000[0m
    [00:00:00.943,664] [0m<inf> mcuboot: Jumping to the first image slot[0m
    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    Starting Bluetooth Peripheral LBS example
    Application build time: Mar 19 2021 21:43:44
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fd0
    I: data wra: 0, 29
    I: SoftDevice Controller build revision:
    I: cf 5c 0f 11 88 9c d7 02 |.\......
    I: 15 27 c7 c3 ca 60 19 85 |.'...`..
    I: b7 c4 50 e3             |..P.    
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    Advertising successfully started
    Connected
    Disconnected (reason 19)

    additionally I want to show you

    before DFU

    size after DFU

  • Here I am Attaching the zip file of currently working DFU application with the board changes.

    dfu_lbs.zip

  • Hi Einar,

    Have you check the code. Is anything i have missed or need to change ?

  • Hi,

    The memory layout you have in this post is the same as in the SDK and fits the nRF52832 with 512 kB flash. So this is correct. this means that your application size must be less than the size of the slots, which is 0x32000 bytes = 200 kB. So to make this work you need to shrink your application slightly or use a nRF device with more flash or use an external flash  memory for slot 1.

  • Hi Einar, Actually seeing I doesn't change any application file rather . i have use only the example of  LBS code with DFU.

    Is it means that example code has more than 200KB?

Reply Children
  • Hi,

    The unmodified peripheral_lbs sample from NCS 1.5 is 162872 byte, so that would fit. But if you build it with debug optimization the size increases to 184388 which is still within the limit. What is the size you get when you build it?

  • After built and upload it shows

    But i can't able to see in the SEGGER

  • For peripheral_lbs default code

    For dfu_lbs (default peripheral_lbs + DFU enabled)

    Still receiving log as 

    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    [00:00:00.258,361] [0m<inf> mcuboot: Starting bootloader[0m
    [00:00:00.264,709] [0m<inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3[0m
    [00:00:00.275,207] [0m<inf> mcuboot: Boot source: none[0m
    [00:00:00.280,944] [0m<inf> mcuboot: Swap type: none[0m
    [00:00:00.601,928] [0m<inf> mcuboot: Bootloader chainload address offset: 0xc000[0m
    [00:00:00.609,954] [0m<inf> mcuboot: Jumping to the first image slot[0m
    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    Starting Bluetooth Peripheral LBS example
    Application build time: Mar 24 2021 23:25:54 
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fb0
    I: data wra: 0, 69
    I: SoftDevice Controller build revision: 
    I: cf 5c 0f 11 88 9c d7 02 |.\......
    I: 15 27 c7 c3 ca 60 19 85 |.'...`..
    I: b7 c4 50 e3             |..P.    
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    Advertising successfully started
    Connected
    W: Ignoring data for unknown CID 0x003a
    I: Erasing page at offset 0x00045000
    I: Erasing page at offset 0x00046000
    I: Erasing page at offset 0x00047000
    I: Erasing page at offset 0x00048000
    I: Erasing page at offset 0x00049000
    I: Erasing page at offset 0x0004a000
    I: Erasing page at offset 0x0004b000
    I: Erasing page at offset 0x0004c000
    I: Erasing page at offset 0x0004d000
    I: Erasing page at offset 0x0004e000
    I: Erasing page at offset 0x0004f000
    I: Erasing page at offset 0x00050000
    I: Erasing page at offset 0x00051000
    I: Erasing page at offset 0x00052000
    I: Erasing page at offset 0x00053000
    I: Erasing page at offset 0x00054000
    I: Erasing page at offset 0x00055000
    I: Erasing page at offset 0x00056000
    I: Erasing page at offset 0x00057000
    I: Erasing page at offset 0x00058000
    I: Erasing page at offset 0x00059000
    I: Erasing page at offset 0x0005a000
    I: Erasing page at offset 0x0005b000
    I: Erasing page at offset 0x0005c000
    I: Erasing page at offset 0x0005d000
    I: Erasing page at offset 0x0005e000
    I: Erasing page at offset 0x0005f000
    I: Erasing page at offset 0x00060000
    I: Erasing page at offset 0x00061000
    I: Erasing page at offset 0x00062000
    I: Erasing page at offset 0x00063000
    I: Erasing page at offset 0x00064000
    I: Erasing page at offset 0x00065000
    I: Erasing page at offset 0x00066000
    I: Erasing page at offset 0x00067000
    I: Erasing page at offset 0x00068000
    I: Erasing page at offset 0x00069000
    I: Erasing page at offset 0x0006a000
    I: Erasing page at offset 0x0006b000
    I: Erasing page at offset 0x0006c000
    I: Erasing page at offset 0x0006d000
    I: Erasing page at offset 0x0006e000
    I: Erasing page at offset 0x0006f000
    I: Erasing page at offset 0x00070000
    I: Erasing page at offset 0x00071000
    I: Erasing page at offset 0x00072000
    I: Erasing page at offset 0x00073000
    I: Erasing page at offset 0x00074000
    I: Erasing page at offset 0x00075000
    I: Erasing page at offset 0x00076000
    I: Erasing page at offset 0x00077000
    I: Erasing page at offset 0x00078000
    I: Erasing page at offset 0x00079000
    I: Erasing page at offset 0x0007a000
    I: Erasing page at offset 0x0007b000
    I: Erasing page at offset 0x0007c000
    I: Erasing page at offset 0x0007d000
    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    [00:00:00.258,392] [0m<inf> mcuboot: Starting bootloader[0m
    [00:00:00.264,709] [0m<inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3[0m
    [00:00:00.275,177] [0m<inf> mcuboot: Boot source: none[0m
    [00:00:00.280,944] [0m<inf> mcuboot: Swap type: test[0m
    [00:00:00.601,898] [1;33m<wrn> mcuboot: Not enough free space to run swap upgrade[0m
    [00:00:00.925,537] [0m<inf> mcuboot: Bootloader chainload address offset: 0xc000[0m
    [00:00:00.933,563] [0m<inf> mcuboot: Jumping to the first image slot[0m
    *** Booting Zephyr OS build v2.4.0-ncs2  ***
    Starting Bluetooth Peripheral LBS example
    Application build time: Mar 24 2021 23:25:54 
    I: 2 Sectors of 4096 bytes
    I: alloc wra: 0, fa0
    I: data wra: 0, 89
    I: SoftDevice Controller build revision: 
    I: cf 5c 0f 11 88 9c d7 02 |.\......
    I: 15 27 c7 c3 ca 60 19 85 |.'...`..
    I: b7 c4 50 e3             |..P.    
    I: No ID address. App must call settings_load()
    Bluetooth initialized
    Advertising successfully started
    Connected
    W: Ignoring data for unknown CID 0x003a
    Disconnected (reason 19)
    

    [00:00:00.601,898] [1;33m<wrn> mcuboot: Not enough free space to run swap upgrade[0m

  • I should note that the sizes from my last answer was with unmodified sample, so not including mcu_mgr which you need.

    The point remains that your slots must be equally sized and the application most fit in the slot. If it does not this will not work, no matter how much you try. If you are unable to make the application fit then you need to either not include DFU support (typically a bad idea for real products) or use a nRF device with more internal flash or use an external flash memory for slot 1.

  •  Hi Einar,

     How do i manage the memory in NCS DFU example for nrf52832.

    Does NCS DFU support have any limitation ?

Related