USB DFU (Device Firmware Upgrade)


Please reference zephyr/samples/subsys/usb/dfu for USB DFU application.
The DFU document at :https://docs.zephyrproject.org/latest/samples/subsys/usb/dfu/README.html#permanent-download-and-automatic-reboot

Testing
The Linux dfu-util tool can be used to backup or update the application image.

Use the following command to backup the SLOT-0 image:

dfu-util --alt 0 --upload slot0_backup.bin
Use the following command to update the application:

dfu-util --alt 1 --download build-hello_world/zephyr/zephyr.signed.bin
Reset the SoC.
MCUboot boot will swap the images and boot the new application, showing this output to the console:



Included the mcuboot in the project.
file CMakeLists.txt
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
#project(NONE)
project(dfu)

file prj.conf

CONFIG_STDOUT_CONSOLE=y
CONFIG_GPIO=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr DFU sample"
CONFIG_USB_DEVICE_PID=0x0005
CONFIG_USB_DFU_CLASS=y
CONFIG_USB_DFU_ENABLE_UPLOAD=y
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_BOOTLOADER_MCUBOOT=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
#preladed code default key
#CONFIG_MCUBOOT_SIGNATURE_KEY_FILE="c:\MyNordicTestV250\dfu_usb\private.pem"
CONFIG_USB_DFU_PERMANENT_DOWNLOAD=y
CONFIG_USB_DFU_REBOOT=y

reference:
https://devzone.nordicsemi.com/f/nordic-q-a/97174/dfu-zephyr-using-usb
https://devzone.nordicsemi.com/f/nordic-q-a/100360/change-gpio-for-trigger-dfu-update/428707



USB DFU

The Linux dfu-util tool can be used to back up or update the application image.

https://dfu-util.sourceforge.net/

Use the following command to back up the SLOT-0 image:


dfu-util --alt 0 --upload slot0_backup.bin
The BLE advertising name is "USB40 DFU1."

Use the following command to update the application:

dfu-util --alt 1 --download USB40F_DFU2app_update.bin
The BLE advertising name is "USB40 DFU2."

If you are testing the USB DFU with the Nordic DK, you should be able to see the following log from the UART. However, please note that USB40F,N does not have a UART interface, so users can't check the UART log with the dongle.

The dongle does not integrate 32K crystal.
Therefore, please setup the clock to internla RC.
The HFXO CAP also does not mount inside the BLE module.
Please also setup the CAP to internal.

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
CONFIG_SOC_LFXO_CAP_INT_7PF=y
CONFIG_SOC_HFXO_CAP_INTERNAL=y
CONFIG_SOC_HFXO_CAP_INT_VALUE_X2=22
CONFIG_BUILD_WITH_TFM=y


##### FEM Config #####
CONFIG_MPSL_FEM_DEVICE_CONFIG_254=y
CONFIG_FEM=y
CONFIG_MPSL=y
CONFIG_MPSL_FEM=y
CONFIG_MPSL_FEM_NRF21540_GPIO=y
CONFIG_MPSL_FEM_NRF21540_GPIO_SPI=n
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB=10
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB_POUTA=10
CONFIG_MPSL_FEM_NRF21540_TX_GAIN_DB_POUTB=10

##### TX Power Config #####
CONFIG_BT_CTLR_TX_PWR_DYNAMIC_CONTROL=y
CONFIG_BT_CTLR_TX_PWR_ANTENNA=17
