I cannot get Zephyr-only DFU over BLE working. Using an NRF52840DK. This is my prj.conf:
---
CONFIG_GPIO=y
CONFIG_LOG=y
# CONFIG_BOARD_HAS_NRF5_BOOTLOADER=n
# Enable zcbor
CONFIG_ZCBOR=y
# Flash related
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_IMG_MANAGER=y
CONFIG_STREAM_FLASH=y
# Enable mcumgr.
CONFIG_MCUMGR=y
CONFIG_MCUMGR_GRP_IMG=y
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_TRANSPORT_BT=y
CONFIG_MCUMGR_TRANSPORT_BT_AUTHEN=n
# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y
# Enable Bluetooth
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Blinker"
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_SMP=y
CONFIG_BT_L2CAP_TX_MTU=498
CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_RX_SIZE=502
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
# Private Key
CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="/*******/keys/mcuboot.pem"
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
---
The main.c file:
---
/**
* @file
*
* LED counter example.
*/
#include <stdlib.h>
#include <zephyr/types.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
/** BLE DFU */
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>
#include <zephyr/mgmt/mcumgr/transport/smp_bt.h>
/** Use standard Zephyr logging. */
LOG_MODULE_REGISTER(blinker);
/** Sleep time between increments. */
#define SLEEP_TIME_MS 100
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios);
/* Register advertising data */
static const struct bt_data ad[] =
{
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
};
static const struct bt_data sd[] =
{
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME)
};
/**
* The main and only function of this example.
*/
int main()
{
int ret;
LOG_INF("Board: %s", CONFIG_BOARD);
LOG_INF("Build time: " __DATE__ " " __TIME__);
if (!device_is_ready(led.port)) {
LOG_ERR("Device is not ready.");
return EXIT_FAILURE;
}
if ((ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE)) < 0) {
LOG_ERR("Error %d: failed to configure pin %d.", ret, led.pin);
return EXIT_FAILURE;
}
/* Enable Bluetooth */
ret = bt_enable(NULL);
if (ret < 0) {
LOG_ERR("Bluetooth init failed (err %d)\n", ret);
return EXIT_FAILURE;
}
/* Start advertising */
ret = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
if (ret < 0) {
LOG_ERR("Advertising failed to start (err %d)\n", ret);
return EXIT_FAILURE;
}
LOG_INF("Starting the LED blinker.");
while (1) {
if ((ret = gpio_pin_toggle_dt(&led)) < 0) {
LOG_ERR("Error %d: failed to toggle pin %d.", ret, led.pin);
return EXIT_FAILURE;
}
k_msleep(SLEEP_TIME_MS);
}
return EXIT_SUCCESS;
}
---
What happens is that nRFConnect does not discover the BLE SMP server. The commands do now work and I fail to upload an image.