Mcumgr to transfer file from host to nrf52840 device over uart

"I'm working with nRF Connect SDK v2.2.0 for nrf52840 and I'm trying to implement file transfer functionality using mcumgr over UART in Application. I've successfully configured and verified firmware upgrade using mcumgr in mcuboot , but now I need to transfer ordinary files, not firmware files in Application. Can you provide a step-by-step guide on how to set up and use mcumgr for transferring regular files over UART in nRF Connect SDK v2.2.0? 
And suggest any other method apart from using mcumgr to tranfer file from hos to nrf52840 over uart?
Here is my config

CONFIG_STDOUT_CONSOLE=y
CONFIG_USB_DEVICE_STACK=y

CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_MAIN_STACK_SIZE=24576
CONFIG_LOG=y 
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_SPI=y
CONFIG_CBPRINTF_FP_SUPPORT=y


CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_GPIO=y
CONFIG_PRINTK=y

CONFIG_RTT_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y

CONFIG_NEWLIB_LIBC=y
CONFIG_PTHREAD_IPC=y
CONFIG_POSIX_API=y
CONFIG_MAX_PTHREAD_COUNT=20

CONFIG_TIMESLICING=y
CONFIG_TIMESLICE_SIZE=2


CONFIG_UART_CONSOLE=n 
#CONFIG_APP_WIPE_STORAGE=y

CONFIG_FILE_SYSTEM=y
CONFIG_FILE_SYSTEM_LITTLEFS=y

CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_FLASH_PAGE_LAYOUT=y

CONFIG_NEWLIB_LIBC_NANO=n 

CONFIG_STDOUT_CONSOLE=y

CONFIG_NORDIC_QSPI_NOR=y

CONFIG_NCS_SAMPLES_DEFAULTS=y
CONFIG_BT=n # BT disabling completely
CONFIG_BT_PERIPHERAL=n # BT disabling completely

CONFIG_MCUMGR=y
CONFIG_MCUMGR_CMD_FS_MGMT=y
# CONFIG_MCUMGR_GRP_FS=Y

CONFIG_BASE64=y
CONFIG_FLASH=y
# CONFIG_IMG_MANAGER=y

CONFIG_NET_BUF=y
CONFIG_ZCBOR=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
#CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK=y
#MGMT_DEF_EVT_OP_ALL
# Enable most core commands.
# CONFIG_MCUMGR_CMD_IMG_MGMT=y
CONFIG_MCUMGR_CMD_OS_MGMT=y

# Ensure an MCUboot-compatible binary is generated.
CONFIG_BOOTLOADER_MCUBOOT=y

# Allow for large Bluetooth data packets.
#CONFIG_BT_L2CAP_TX_MTU=252
#CONFIG_BT_BUF_ACL_RX_SIZE=256

# Allow for large Bluetooth data packets.
 # BT disabling completely
#CONFIG_BT_L2CAP_TX_MTU=498
#CONFIG_BT_BUF_ACL_RX_SIZE=502
#CONFIG_BT_BUF_ACL_TX_SIZE=502
#CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

# Enable the Bluetooth (unauthenticated) and shell mcumgr transports.
CONFIG_MCUMGR_SMP_BT=n  # BT disabling completely
CONFIG_MCUMGR_SMP_BT_AUTHEN=n
CONFIG_MCUMGR_SMP_BT_CONN_PARAM_CONTROL=n  # BT disabling completely
CONFIG_MCUMGR_SMP_REASSEMBLY_BT=n # BT disabling completely
CONFIG_MCUMGR_BUF_SIZE=2475
#CONFIG_OS_MGMT_MCUMGR_PARAMS=y


# Some command handlers require a large stack.
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096

# Enable file system commands
#CONFIG_MCUMGR_CMD_FS_MGMT=y


# Required by the `taskstat` command.
CONFIG_THREAD_MONITOR=y

# Enable logging
CONFIG_MCUBOOT_UTIL_LOG_LEVEL_WRN=y

CONFIG_MCUMGR_SMP_SHELL=y

CONFIG_LOG_MODE_IMMEDIATE=y
#SMP for UART
CONFIG_MCUMGR_SMP_UART=y


#To increase the UART/USB transfer speed for DFU Upload FW
CONFIG_CONSOLE_INPUT_MAX_LINE_LEN=1240
CONFIG_UART_MCUMGR_RX_BUF_SIZE=1240
Parents
  • Hi, 

    You can refer to the SMP server sample. 

    I use this command

    west build -p -b nrf52840dk_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DOVERLAY_CONFIG='overlay-fs.conf;overlay-serial.conf' && west flash --recover

    and get 

    Regards,
    Amanda H.

  • Hi Amanda,

    Thank you for your reply!

    I could be able to run the smp server, that you cited and able to transfer small files.
    My use case is to transfer 300kB of file to Filesystem, but It did not succeed. Even I tried low sized file, 108kB of file size, but it also failed with timeout.



    Here 

    mu.txt file size is 1kB

    mu108_kb.txt file size is108kB

    C:\Users\MK\Downloads\serial_upgrade>mcumgr --conntype serial --connstring "COM10,baud=115200" fs upload mu.txt /lfs1/mu.txt
    12
    Done

    C:\Users\MK\Downloads\serial_upgrade>mcumgr --conntype serial --connstring "COM10,baud=115200" fs upload mu108_kb.txt /lfs1/mu108_kb.txt
    Error: NMP timeout

    Any suggestion?

    Thanks,

    MK V

  • Hi Amanda, 
    Any config changes help to break this limitation?
    Could you able to upload 500kb of file using mcumgr over UART?


    Thanks,

    MK V

  • Hi, 

    500KiB uploads work fine, but you need to have a flash device that you can store it on. For our DKs, that would mean having to move the fatfs/lfs partition to QSPI/SPI flash with CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL. You can execute "ninja partition_manager_report" command under the build folder to check the memory layout and size large enough for the upload file:


    My test project for nRF52840DK with spi external flash: smp_svr.7z

    -Amanda H.

  • Hi Amanda, 

    Thank you for providing the test project.

    I have incorporated some of the configuration settings from your code into my custom board's source code. Setting CONFIG_MCUMGR_BUF_SIZE=2475 resolved the UART issue for mcumgr in the application.

    Now I could be able to successfully transfer my complete file to the External Flash.

    However, I have noticed that transferring a 137 KB file takes approximately 1 minute and 10 seconds. Is there any potential to reduce this transfer time?

    I have attempted to increase CONFIG_MCUMGR_BUF_SIZE and utilize MTU values of 512 and 1024 as arguments for mcumgr, but these adjustments have not yielded any improvement.

    I would appreciate any insights or suggestions on how to optimize this transfer process.

    Thanks,

    MK V

  • Hi, 

    MK_V said:
    Is there any potential to reduce this transfer time?

    Check out this post. Maybe you can try the latest version of NCS v2.8.0.

    MK_V said:
    I have attempted to increase CONFIG_MCUMGR_BUF_SIZE and utilize MTU values of 512 and 1024 as arguments for mcumgr, but these adjustments have not yielded any improvement.

    I can increase CONFIG_MCUMGR_BUF_SIZE and CONFIG_MCUMGR_SMP_UART_MTU to 2475 without issue by using the following command with my test project. 

    west build -p -b nrf52840dk_nrf52840 zephyr/samples/subsys/mgmt/mcumgr/smp_svr -- -DOVERLAY_CONFIG='overlay-fs.conf;overlay-serial.conf' -DCONFIG_MCUMGR_BUF_SIZE=2475 -DCONFIG_MCUMGR_SMP_UART_MTU=2475 && west flash --recover

    -Amanda H.

  • I can increase CONFIG_MCUMGR_BUF_SIZE and CONFIG_MCUMGR_SMP_UART_MTU to 2475 without issue by using the following command with my test project. 

    After this change, could you able to observe improvement in file transfer speed and overall upload time?

    Check out this post. Maybe you can try the latest version of NCS v2.8.0.

    Thanks! I will check it out!

Reply Children
Related