DFU over USB, can ignore the erase the external flash data?

Hi,

    I just try to use the DFU over USB to upgrade the FW but i found one problem which is the process will erase the external flash data 

but i put the some sensor FW data in the external flash so that means i will lose these FW after doing the DFU update FW. Do you have any

configuration settings or other way to keep this data to use the other partition. please help to take a look thanks.

    By the way, i got another questions about the USB CDC chosen, can i set the console and shell-uart and uart-mcumgr all set to the &cdc_acm_uart0.

Does it will cause the console and shell-uart can not work at the same time.

/ {
chosen {
nordic,pm-ext-flash = &mx66l1g;
//zephyr,console = &cdc_acm_uart0;
//zephyr,shell-uart = &cdc_acm_uart0;
zephyr,uart-mcumgr = &cdc_acm_uart0;
};

Here is the mcuboot.conf

CONFIG_LOG=y
CONFIG_CBPRINTF_NANO=y
CONFIG_MCUBOOT_LOG_LEVEL_INF=y
CONFIG_PM_PARTITION_SIZE_MCUBOOT=0x18000

# Size of mcuboot partition
CONFIG_SIZE_OPTIMIZATIONS=y

# MCUBoot serial
# Enable Serial Recovery over UART
CONFIG_UART_CONSOLE=n
CONFIG_MCUBOOT_SERIAL=y
CONFIG_BOOT_SERIAL_UART=y
CONFIG_BOOT_SERIAL_CDC_ACM=y
# Configure boolader to use two slots
CONFIG_SINGLE_APPLICATION_SLOT=n
# Step 8.2 - Enable QSPI driver for external flash
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_BOOT_MAX_IMG_SECTORS=256

7028.mcuboot.conf

mcuboot.overlay

/ {
chosen {
nordic,pm-ext-flash = &mx66l1g;
};
};


&qspi {
mx25r64: mx25r6435f@0 {
status = "disabled";
};
mx66l1g: MX66L1G45G@0 {
compatible = "nordic,qspi-nor";
reg = <0>;
status = "okay";
/* MX66L1G45G supports only pp and pp4io */
writeoc = "pp4io";
/* MX66L1G45G supports all readoc options */
readoc = "read4io";
sck-frequency = <8000000>;
jedec-id = [c2 20 1b];
has-dpd;
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
sfdp-bfp = [
e5 20 fb ff ff ff ff 3f 44 eb 08 6b 08 3b 04 bb
fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52
10 d8 00 ff d6 49 c5 00 85 df 04 e3 44 03 67 38
30 b0 30 b0 f7 bd d5 5c 4a 9e 29 ff f0 50 f9 85
];
//size = <536870912>;
size = <1073741824>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

lfs1_part: partition@0 {
label = "data";
reg = <0x00000000 0x3000000>;
};
};
};
};

3718.mcuboot.overlay

pm_static.yml

# Name of partition
littlefs_storage:
address: 0
end_address: 0x3000000
placement:
before:
- end
region: external_flash
size: 0x3000000

nrf5340dk_nrf5340_cpuapp.overlay

/delete-node/ &storage_partition;
&qspi {
mx25r64: mx25r6435f@0 {
status = "disabled";
};
mx66l1g: MX66L1G45G@0 {
compatible = "nordic,qspi-nor";
reg = <0>;
status = "okay";
/* MX66L1G45G supports only pp and pp4io */
writeoc = "pp4io";
/* MX66L1G45G supports all readoc options */
readoc = "read4io";
sck-frequency = <8000000>;
jedec-id = [c2 20 1b];
has-dpd;
t-enter-dpd = <10000>;
t-exit-dpd = <35000>;
sfdp-bfp = [
e5 20 fb ff ff ff ff 3f 44 eb 08 6b 08 3b 04 bb
fe ff ff ff ff ff 00 ff ff ff 44 eb 0c 20 0f 52
10 d8 00 ff d6 49 c5 00 85 df 04 e3 44 03 67 38
30 b0 30 b0 f7 bd d5 5c 4a 9e 29 ff f0 50 f9 85
];
//size = <536870912>;
size = <1073741824>;
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

lfs1_part: partition@0 {
label = "data";
reg = <0x00000000 0x3000000>;
};
};
};
};

/ {
chosen {
nordic,pm-ext-flash = &mx66l1g;
//zephyr,console = &cdc_acm_uart0;
//zephyr,shell-uart = &cdc_acm_uart0;
zephyr,uart-mcumgr = &cdc_acm_uart0;
};
zephyr,user {
io-channels = <&adc 3>;
io-channel-names = "Battery_adc";
};

fstab {
compatible = "zephyr,fstab";
lfs1: lfs1 {
compatible = "zephyr,fstab,littlefs";
mount-point = "/lfs1";
partition = <&lfs1_part>;
automount;
read-size = <16>;
prog-size = <16>;
cache-size = <64>;
lookahead-size = <32>;
block-cycles = <512>;
};
};

//msc_disk0 {
// compatible = "zephyr,flash-disk";
// partition = <&lfs1_part>;
// disk-name = "NOR";
// cache-size = <4096>;
//};

buttons {
compatible = "gpio-keys";
button0: button_0 {
status = "disabled";
};
button1: button_1 {
status = "disabled";
};
button2: button_2 {
gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button 3";
};
button3: button_3 {
status = "disabled";
};
};

leds {
compatible = "gpio-leds";
led0: led_0 {
gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
label = "Green LED 0";
};
led1: led_1 {
gpios = <&gpio0 23 GPIO_ACTIVE_LOW>;
label = "Green LED 1";
};
led2: led_2 {
gpios = <&gpio0 9 GPIO_ACTIVE_LOW>;
label = "Green LED 2";
};
led3: led_3 {
gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;
label = "Green LED 3";
};
led4: led_4 {
gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
label = "Green LED 4";
};
led5: led_5 {
gpios = <&gpio1 8 GPIO_ACTIVE_LOW>;
label = "Green LED 5";
};
};
};

&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
tx-fifo-size = <4096>;
rx-fifo-size = <4096>;
};
};

&adc {
#address-cells = <1>;
#size-cells = <0>;

channel@3 {
reg = <3>;
zephyr,gain = "ADC_GAIN_1_6";
zephyr,reference = "ADC_REF_INTERNAL";
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
zephyr,input-positive = <NRF_SAADC_AIN3>; /* P0.07 */
zephyr,resolution = <12>;
};
};

/* Remove flow control pins*/
&gpio_fwd {
uart {
gpios = <&gpio1 0 0>; //<&gpio1 1 0>,
};
};

prj.conf

#
# Copyright (c) 2019 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
#
# General config
CONFIG_ASSERT=y

# Make sure printk is printing to the UART console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y


CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Laminar P1"
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_MAX_CONN=1
CONFIG_BT_MAX_PAIRED=1

# Enable the NUS service
CONFIG_BT_NUS=y

CONFIG_BT_CONN_TX_MAX=30
CONFIG_BT_L2CAP_TX_BUF_COUNT=30
CONFIG_BT_L2CAP_TX_MTU=247
#CONFIG_BT_L2CAP_TX_MTU=498
CONFIG_BT_BUF_ACL_TX_COUNT=18
#CONFIG_BT_BUF_ACL_TX_SIZE=251
CONFIG_BT_BUF_ACL_TX_SIZE=502
CONFIG_BT_BUF_ACL_RX_SIZE=502

CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
CONFIG_BT_CTLR_DATA_LENGTH_MAX=251
CONFIG_BT_CONN_PARAM_UPDATE_TIMEOUT=300
CONFIG_BT_USER_PHY_UPDATE=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_DM=y
CONFIG_BT_DATA_LEN_UPDATE=y
CONFIG_BT_USER_DATA_LEN_UPDATE=y


# This example requires more workqueue stack
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
CONFIG_SYSTEM_WORKQUEUE_PRIORITY=-10

# Logging
CONFIG_SERIAL=y
CONFIG_LOG=y
CONFIG_LOG_PRINTK=y
CONFIG_USE_SEGGER_RTT=n
CONFIG_LOG_BUFFER_SIZE=4096

# Stacks and heaps
CONFIG_MAIN_STACK_SIZE=16384
CONFIG_BT_RX_STACK_SIZE=16384
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_SHELL_STACK_SIZE=8192
CONFIG_SHELL_THREAD_PRIORITY_OVERRIDE=y
CONFIG_SHELL_PRINTF_BUFF_SIZE=4096

# I2C
CONFIG_I2C=y
CONFIG_NRFX_TWIM1=y

# I2S
CONFIG_I2S=y
CONFIG_I2S_NRFX=y
CONFIG_I2S_NRFX_TX_BLOCK_COUNT=300

#SPIM
CONFIG_SPI=y
CONFIG_SPI_SLAVE=n
CONFIG_SPI_ASYNC=y
CONFIG_NRFX_SPIM3=y
CONFIG_NRFX_SPIM4=y
CONFIG_POLL=y

# Rebooot
CONFIG_REBOOT=n
CONFIG_RESET_ON_FATAL_ERROR=n

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y

# file system
CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_SHELL=y
CONFIG_FILE_SYSTEM_LITTLEFS=y
CONFIG_FAT_FILESYSTEM_ELM=n

CONFIG_SHELL=y


#USB related configs
CONFIG_USB_DEVICE_STACK=y
#CONFIG_USB_DEVICE_PRODUCT="Zephyr MSC sample"
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE=n
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_USB_MASS_STORAGE_LOG_LEVEL_ERR=n
#CONFIG_USB_DEVICE_PID=0x0008
CONFIG_DISK_DRIVER_FLASH=y
CONFIG_APP_MSC_STORAGE_FLASH_FATFS=n
CONFIG_APP_MSC_STORAGE_FLASH_LITTLEFS=y

# enable QSPI flash
CONFIG_NORDIC_QSPI_NOR=y
CONFIG_NORDIC_QSPI_NOR_FLASH_LAYOUT_PAGE_SIZE=4096
CONFIG_MPU_ALLOW_FLASH_WRITE=y

CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_DSP_FASTMATH=y
CONFIG_NEWLIB_LIBC=y
CONFIG_FPU=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y

# Enable CAF_BUTTONS
CONFIG_CAF=y
CONFIG_CAF_BUTTONS=y
CONFIG_CAF_BUTTONS_POLARITY_INVERSED=y
CONFIG_CAF_CLICK_DETECTOR=y
CONFIG_CAF_CLICK_DETECTOR_LONG_CLICK_MSEC=1000

# normal voltage mode
CONFIG_BOARD_ENABLE_DCDC_HV=n
# disable NFC pin to GPIO
CONFIG_NFCT_PINS_AS_GPIOS=y
# Enable the memory DMA
CONFIG_DMA=n

# ADC config
CONFIG_ADC=y

# Power manager
CONFIG_PM=n

# USB CDC ACM
CONFIG_STDOUT_CONSOLE=y
#CONFIG_USB_DEVICE_PID=0x0001
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y

# DFU and bootloader
CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# Enable MCUmgr and dependencies.
CONFIG_NET_BUF=y
CONFIG_ZCBOR=y
CONFIG_CRC=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_STAT=y

# Enable logging
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

# Enable mcumgr DFU in application
CONFIG_MCUMGR=y

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

# Configure MCUMGR transport to UART
CONFIG_MCUMGR_TRANSPORT_UART=y

# Configure dependencies for CONFIG_MCUMGR_TRANSPORT_UART
CONFIG_BASE64=y

Stanly

    

Parents
  • Hi Stanly,

    By the way, i got another questions about the USB CDC chosen, can i set the console and shell-uart and uart-mcumgr all set to the &cdc_acm_uart0.

    Yes, you can set a single UART interface for multiple properties like console, shell, and mcumgr. But, if possible, considering different UART interfaces for these functionalities might be a better approach. If there are hardware limitations, you can stick to the single UART interface approach.

    I just try to use the DFU over USB to upgrade the FW but i found one problem which is the process will erase the external flash data 

    but i put the some sensor FW data in the external flash so that means i will lose these FW after doing the DFU update FW. Do you have any

    configuration settings or other way to keep this data to use the other partition. please help to take a look thanks.

    I'm not sure why this is happening, but I guess it might be because of the partition layout. Partition layout might be setup in a way that the DFU process overlaps with external flash memory. Is there any detailed log indicating which area is being erased? I recommend checking the DTS and partition manager files (see that there is no overlapping). Assuming you are working with nRF5340, let me know if this is not the case, but is this a custom board or a DK? Could you also share which SDK version you are using here?

    Regards,

    Swathy

Reply
  • Hi Stanly,

    By the way, i got another questions about the USB CDC chosen, can i set the console and shell-uart and uart-mcumgr all set to the &cdc_acm_uart0.

    Yes, you can set a single UART interface for multiple properties like console, shell, and mcumgr. But, if possible, considering different UART interfaces for these functionalities might be a better approach. If there are hardware limitations, you can stick to the single UART interface approach.

    I just try to use the DFU over USB to upgrade the FW but i found one problem which is the process will erase the external flash data 

    but i put the some sensor FW data in the external flash so that means i will lose these FW after doing the DFU update FW. Do you have any

    configuration settings or other way to keep this data to use the other partition. please help to take a look thanks.

    I'm not sure why this is happening, but I guess it might be because of the partition layout. Partition layout might be setup in a way that the DFU process overlaps with external flash memory. Is there any detailed log indicating which area is being erased? I recommend checking the DTS and partition manager files (see that there is no overlapping). Assuming you are working with nRF5340, let me know if this is not the case, but is this a custom board or a DK? Could you also share which SDK version you are using here?

    Regards,

    Swathy

Children
  • Hi Swathy,

        I'm using a custom board with SDK version v2.4.2. Below, I've attached the log, partition layout, and pm_static.yml files. Could you please review them? If you notice anything wrong, kindly let me know. Thank you!

    Here is the error log after mcumgr reset.

    Here is the partition layout

    pm_static.yml

    # Name of partition
    littlefs_storage:
      address: 0
      end_address: 0x3000000
      placement:
      before:
      - end
      region: external_flash
      size: 0x3000000
     
    Stanly
Related