DFU on nrf52832

Hi, I am having problem making DFU work on nrf52832 using nrf connect sdk 2.6.0.  Below is my mcuboot.conf under child_image and prj.conf. Please guide me where I am wrong. Also when I set CONFIG_SINGLE_APPLICATION_SLOT, it builds fine but when I disables it, it doesn't build due to size issue.

&flash0 {

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 0x2C000>;
};
slot1_partition: partition@38000 {
label = "image-1";
reg = <0x00038000 0x2C000>;
};
storage_partition: partition@64000 {
label = "storage";
reg = <0x00064000 0x4000>;
};
};

};
# Logging
CONFIG_LOG=y
CONFIG_MCUBOOT_LOG_LEVEL_WRN=y
# CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x15000
CONFIG_SINGLE_APPLICATION_SLOT=y

and prj.conf
#
# Copyright (C) 2024 Walk With Path Corp. All Rights Reserved.
# Project Configuration File
#
# This file contains configuration settings for Bluetooth, logging, peripherals,
# memory optimization, DFU support, and other key features for Zephyr-based applications.
#

# ==============================
# General Debugging and Logging
# ==============================

CONFIG_LOG=y # Enable logging framework
CONFIG_LOG_BACKEND_UART=y # Use UART backend for logs
CONFIG_LOG_PRINTK=y # Allow printk for logs
CONFIG_CBPRINTF_FP_SUPPORT=y # Enable floating-point support in logs

# Enable console for debug purposes
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

CONFIG_DEBUG=y # Enable debugging
CONFIG_PRINTK=y # Enable printk debugging

CONFIG_SHELL=n # Enable Zephyr Shell for debugging
CONFIG_SHELL_LOG_BACKEND=y
CONFIG_SHELL_CMD_BUFF_SIZE=128

# Enable RTT (Real-Time Transfer) for logs (alternative to UART)
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=y # Disable UART console if RTT is enabled
CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=512
CONFIG_SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL=y

CONFIG_LOG_BLOCK_IN_THREAD=y
CONFIG_LOG_BUFFER_SIZE=256
CONFIG_DEBUG=y # Enable debugging
CONFIG_DEBUG_INFO=y
CONFIG_DEBUG_THREAD_INFO=y

# CONFIG_NCS_BOOT_BANNER=y # Enable NCS boot banner
CONFIG_BOOT_BANNER=y
CONFIG_PRINTK=y

# Enable UART support
CONFIG_SERIAL=y

# ==============================
# Peripheral and Sensor Drivers
# ==============================

CONFIG_I2C=y # Enable I2C interface
CONFIG_SPI=y # Enable SPI interface
CONFIG_ADC=y # Enable ADC driver

CONFIG_SENSOR=y # Enable generic sensor support
CONFIG_TMP116=y # Enable TMP116 temperature sensor
CONFIG_BMI270=y # Enable BMI270 accelerometer
CONFIG_BMI270_TRIGGER_GLOBAL_THREAD=y

CONFIG_WATCHDOG=y # Enable watchdog timer
CONFIG_WDT_LOG_LEVEL_DBG=y
CONFIG_WDT_DISABLE_AT_BOOT=n

# Enable LED and regulator drivers
CONFIG_LED=y
CONFIG_REGULATOR=y

# Enable power management IC (NPMX)
# CONFIG_NPMX=y
# CONFIG_NPMX_DEVICE_NPM1300=y

# Enable Nordic Fuel Gauge and BMI270 (Accelerometer and Gyroscope)
CONFIG_NRF_FUEL_GAUGE=y

# Disable SPI NOR flash driver (if not used)
CONFIG_SPI_NOR=n

# ==============================
# Power and Memory Optimizations
# ==============================

# Power management configuration
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y

# ==============================
# Memory Optimizations
# ==============================

# Configure memory pool and stack sizes
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_HEAP_MEM_POOL_SIZE=1024

# ==============================
# Flash Configuration
# ==============================

CONFIG_FLASH=y # Enable flash memory support
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_BT_SETTINGS=y # Enable Bluetooth settings
CONFIG_SETTINGS=y # Enable settings subsystem
CONFIG_NVS=y # Enable Non-Volatile Storage
CONFIG_NVS_LOG_LEVEL_DBG=y

# ==============================
# Bluetooth Settings
# ==============================

CONFIG_NCS_SAMPLES_DEFAULTS=y

# Enable Bluetooth and controller settings
CONFIG_BT=y
CONFIG_BT_HCI=y
CONFIG_BT_CTLR=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_BROADCASTER=n
CONFIG_BT_SMP=y
CONFIG_BT_BONDABLE=y
CONFIG_BT_CTLR_ADV_EXT=n
CONFIG_BT_DEVICE_APPEARANCE=1345
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_GATT_CLIENT=y

# Bluetooth security and bonding settings
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE=y
CONFIG_BT_ID_UNPAIR_MATCHING_BONDS=y
CONFIG_BT_PRIVACY=n
CONFIG_BT_TINYCRYPT_ECC=y
CONFIG_BT_CTLR_PHY_2M=y
CONFIG_BT_USER_PHY_UPDATE=y

# Bluetooth buffer and connection settings
CONFIG_BT_BUF_ACL_RX_SIZE=247
CONFIG_BT_ATT_PREPARE_COUNT=2
CONFIG_BT_BUF_ACL_TX_SIZE=256
CONFIG_BT_BUF_ACL_TX_COUNT=10
CONFIG_BT_L2CAP_TX_MTU=247
CONFIG_BT_L2CAP_TX_BUF_COUNT=10
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
CONFIG_BT_CTLR_DATA_LENGTH_MAX=247
CONFIG_BT_CTLR_RX_BUFFERS=2
CONFIG_BT_CONN_TX_MAX=10
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n

CONFIG_BT_GATT_DM=y

# Allow only LESC pairing
# CONFIG_BT_SMP_SC_PAIR_ONLY=y

# Configure Bluetooth connection settings
CONFIG_BT_CTLR_TX_PWR_0=y
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1

# Enable PHY updates
CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_USER_DATA_LEN_UPDATE=y

# Enable Bluetooth shell for debugging
CONFIG_BT_SHELL=n

# Enable BT NUS (Nordic UART Service) shell for testing
# CONFIG_SHELL_BT_NUS=y

# Enable Battery Service (BAS) for battery level reporting
CONFIG_BT_BAS=y

# ==============================
# Cryptography
# ==============================

CONFIG_TINYCRYPT=y # Enable TinyCrypt for secure operations
CONFIG_BT_TINYCRYPT_ECC=y

# ==============================
# Reboot and Misc Settings
# ==============================

CONFIG_REBOOT=y # Enable reboot functionality

# ==============================
# DFU Support and Bootloader
# ==============================

# Enable mcumgr.
CONFIG_MCUMGR=y

# Enable MCUboot and FOTA
CONFIG_BOOTLOADER_MCUBOOT=y
# CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="bootloader/mcuboot/root-rsa-2048.pem"
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU=y
CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU_SPEEDUP=y

# Enable image management
CONFIG_MCUMGR_TRANSPORT_BT=y
CONFIG_MCUMGR_TRANSPORT_BT_AUTHEN=n
CONFIG_MCUMGR_TRANSPORT_BT_CONN_PARAM_CONTROL=y

CONFIG_IMG_MANAGER=n
CONFIG_MCUBOOT_IMG_MANAGER=y
CONFIG_IMG_ERASE_PROGRESSIVELY=y

# Enable logging for mcumgr (DFU)
CONFIG_MCUMGR_LOG_LEVEL_DBG=y
CONFIG_MCUMGR_LOG_LEVEL_INF=y

# Enable logging for image management subsystem
CONFIG_IMG_MANAGER_LOG_LEVEL_DBG=y
CONFIG_IMG_MANAGER_LOG_LEVEL_INF=y

# # Enable mcumgr DFU in application
# # Enable MCUMGR

# # Enable MCUMGR management for both OS and Images
# CONFIG_MCUMGR_GRP_OS=y
# CONFIG_MCUMGR_GRP_IMG=y

# Support for taskstat command
CONFIG_MCUMGR_GRP_OS_TASKSTAT=y

# Enable statistics and statistic names.
CONFIG_STATS=y
CONFIG_STATS_NAMES=y

# Enable most core commands.
CONFIG_MCUMGR_GRP_IMG=y
CONFIG_MCUMGR_GRP_OS=y
CONFIG_MCUMGR_GRP_STAT=y


Parents Reply
  • Hi Andreas, I have managed to build https://docs.zephyrproject.org/latest/samples/drivers/spi_flash/README.html with below dts

    &spi2 {
        compatible = "nordic,nrf-spi";
        status = "okay";
        pinctrl-0 = <&spi2_default>;
        pinctrl-1 = <&spi2_sleep>;
        pinctrl-names = "default", "sleep";
        cs-gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
    	at25xe321d: at25xe321d@0 {
            #address-cells = <1>;
            #size-cells = <1>;
    		partitions {
    			compatible = "fixed-partitions";
    			#address-cells = <1>;
    			#size-cells = <1>;
    
    			slot1_partition: partition@0 {
    				label = "image-1";
    				reg = <0x0000000 DT_SIZE_K(472)>;
    			};
    			/* to be used in firmware */
    			store_partition: partition@100000 {
    				label = "store";
    				reg = <0x00100000 0x00400000>;
    			};
    		};
    		compatible = "jedec,spi-nor";
            reg = <0>; // Chip select 0
            spi-max-frequency = <100000000>;
            jedec-id = [1F 47 0C];
            // size = <0x400000>;  // 4 MB
    		size = <DT_SIZE_M(4)>;
    		has-dpd;
    		t-enter-dpd = < 3000 >;
    		t-exit-dpd = < 1200000 >;
        };
    };

    When I try to build my application without mciboot/DFU, it doesn't build. When I commented out 

    bt_enable(NULL); from my code base, it builds. I am figuring out why this is the case as I need BLE enabled in my application.
Children
  • Here is the generated dts as part of the failed build for your reference.4571.zephyr.dts

  • Hi,

    AHaug said:
    Did you see the expected output when hooking the device up to a terminal? If you ran the JESD216 sample as well, which output did you get?

    I still want a confirmation on this. Please attach the device logs or let me know if you need help in getting the logs from the device.

    AHaug said:

    Next after getting these two samples up and running, which means that if you got the correct output, then the external flash would've been correctly configured, I intended for you to compare those two samples with https://github.com/aHaugl/samples_for_NCS/tree/main/bootloader/spi/smp_ble_feat_spi and replace the mx25 flash I've used here with your at25x flash. One difference I can spot immedeatly is the difference between the mcuboot.overlay in the smp_ble_feat_spi sample with your application and your mcuboot.overlay is that you're missing to add the spi device into mcuboot.overlay (which you've done in your board file. MCUboot also needs to be aware of the external flash for it to use it.

    Try to get https://github.com/aHaugl/samples_for_NCS/blob/main/bootloader/spi/smp_ble_feat_spi/child_image up and running with your external flash and compare the setup there with your application

    How about https://github.com/aHaugl/samples_for_NCS/blob/main/bootloader/spi/smp_ble_feat_spi? Are you able to run this sample with your external flash and board?

    Kind regards,
    Andreas

  • Hi Andreas, sorry for late reply. Here is output of JESD216 sample. It doesn't seem working as expected though

    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    
    spi@40023000 SPI flash testing
    ==========================
    
    Perform test on single sector
    Test 1: Flash erase
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    
    spi@40023000 SPI flash testing
    ==========================
    
    Perform test on single sector
    Test 1: Flash erase
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    
    spi@40023000 SPI flash testing
    ==========================
    
    Perform test on single sector
    Test 1: Flash erase
    *** Booting nRF Connect SDK v3.5.99-ncs1 ***

    I have good news is that I have managed to build my app with mcuboot with slot 1 using external flash. Issue I noticed that It builds if I use conf file as prj.conf but when I build the app with either prj_debug.conf or prj_release.conf, it doesn't build. I have no idea why it does. See prj.conf attached.8877.prj.conf

    I do manage to run DFU using the device manager app, but when I select Test & Confirm, I am expecting MCU to reset towards the completion of update firmware, but it doesn't. When I try to reset from the app, it doesn't either. I can read two slots though.

    7217.mcuboot.conf

    Lastly, how I can erase external flash from nrfjprog or Jlink?

    Thanks, Moh

  • Hi Moh,

    Looks to me that you're stuck in an infinite restart-loop when setting up the JESD216 sample. Please zip the project you were using for your custom board together with the build log and I'll have a look.

    Do you see the same thing with the SPI NOR flash sample?. I can't really help you isolating the issue in your application unless you verify that your configuring of the external flash is working in NCS 2.6.0 with a reference sample.

    Moh said:
    I have good news is that I have managed to build my app with mcuboot with slot 1 using external flash. Issue I noticed that It builds if I use conf file as prj.conf but when I build the app with either prj_debug.conf or prj_release.conf, it doesn't build. I have no idea why it does. See prj.conf attached.8877.prj.conf

    Thats good and all, but I unfortunally can't extract anything from this. What build command did you use and/or how did you select the debug/release configuration? What did the build logs look like?

    Moh said:
    Lastly, how I can erase external flash from nrfjprog or Jlink?

    As of now we only have the -qspierasell in nrfjprog. This does unfortunately not work for SPI devices, so what other developers have done is to create their own solution based that handles this. I know this is a WIP to implement for SPI eraseall, but with an unkown ETA.

    Kind regards,
    Andreas

  • Hi Andreas, sorry for the late reply as away on holiday. Please find the cut down version of my project. FYI I have ran on my board and I am till seeing the same behavior. 

    Problem I am facing is that when I ran the update via the app, the update runs fine but when it completes, it doesn't reset the MCU automatically.

    dfu_spi.zip

Related