This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF5340 - UART programming option

Hello,

I'm in the process of developing the HW board for a nRF5340-based product.
I need the customer could update the firmware using a serial port (USB or Bluetooth is not acceptable).
Is it possible to do that ? Where to found documentation on this ?

Regards,
Gabriele

Parents
  • Hi Gabriele, 

    I afraid the nrfutil tool that Igor pointed wouldn't work with the nRF53 (only support nRF52 and nRF5 SDK). 

    The nRF53 is not supported by our nRF5SDK (which the nrfutil supports) 

    For nRF53 you would need to use NRF Connect SDK. To do DFU with UART on nRF Connect SDK you would need to use mcumgr and smpsvr. 
    Please read about the smpsvr here

    And mcumgr here.

    We have an example of using smpsvr and mcumgr via UART for the Thingy91 here. It's for the nRF9160 but it should be similar syntax for the nRF53.

  • Hi Hung,
    at first glance this seems a very complicated path. It makes me wonder if it will work in the end.
    I'll try to understand the documents you've linked

  • Hi Hung,
    Thank you, this is a clean step-by-step recipe. I'm sorry I cannot test this in real time. These days much of my effort is on the PCB design. Consider that the DFU must get started from a Windows host, because the product is linked to a Windows PC where the user application runs. Thus, as for the first step, I think I have to install Go for Windows, right ? 

  • I don't think Go is needed for the UART dfu application. 

    However, DFU update is a quite complex application. I would suggest you to get started with testing normal UART application. You will need to have normal SWD programming (not UART DFU) for the development, make sure you have the SWD accessible and has the programmer (can be a nRF53 DK). 

  • Hi Hung

    Let me sum up the state of art as follow-up to this thread.

    I've a nRF5340 custom board and a working Zephyr application I can build (under NCS v1.2.0), flash (using SWD), and run.
    The UART works fine, either as console and generic user data.
    Now, I want to perform DFU through the UART.
    I need to include MCUBoot with MCUmgr with SMP server and Uart transport.

    Here is what I've done

    1. Add Uart support for mcumgr into board file <ncs>/zephyr/boards/arm/qi2m_nrf5340/qi2m_nrf5340_cpuapp_common.dts
    chosen {
    ...
    zephyr,uart-mcumgr = &uart0;
    };

    2. Change prj.conf of my application by adding
    CONFIG_MCUMGR=y
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_NET_BUF=y
    CONFIG_MCUMGR_SMP_UART=y

    3. Rebuilding the application with
    $ west build -b qi2m-nrf5340_cpuapp --build-dir buildout

    I get the error

    ..
    FAILED: zephyr/autogen/pubkey.c
    ModuleNotFoundError: No module named 'cbor'

    Is there anything missed ?
    Does it help to move to NCS 1.3.0 ?

    Thanks

  • Hi Hung
    I'm trying to follow your initial recipe

    a) Build and flash mcuboot
      $ cd <ncs>/bootloader/mcuboot/boot/zephyr
      $ west build -b qi2m_nrf5340_cpuapp --build-dir buildout
      $ nrfjprog -f nrf53 --program buildout/zephyr/zephyr.hex

      I check out reading flash. One image found at
        0x00000000 - 0x0000891f (35104 B)

    b) Build and flash smp_svr
      $ cd <ncs>/zephyr/samples/subsys/mgmt/mcumgr/smp_svr
      $ vim prj.conf
      Add these lines
        CONFIG_MCUMGR_SMP_UART=y
        CONFIG_NET_BUF_USER_DATA_SIZE=7
      $ west build -b qi2m_nrf5340_cpuapp --build-dir buildout
      $ nrfjprog -f nrf53 --program buildout/zephyr/zephyr.hex

      I check out reading flash. Two images found at
        0x00000000 - 0x0000891f (35104 B)
        0x00010200 - 0x0001a62b (42028 B)

    On board restart I get out of UART

      *** Booting Zephyr OS build v2.3.0-rc1-ncs1 ***
      [00:00:00.003,051] <inf> mcuboot: Starting bootloader
      [00:00:00.009,063] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
      [00:00:00.019,165] <inf> mcuboot: Boot source: none
      [00:00:00.024,566] <wrn> mcuboot: Failed reading image headers; Image=0
      [00:00:00.032,012] <err> mcuboot: Unable to find bootable image

    Issuing from host the test command

      $ mcumgr -t 20 --conntype serial --connstring='/dev/ttyUSB0,baud=115200' image list

    I get "Error: NMP timeout"

    What a hell to do ?

Reply
  • Hi Hung
    I'm trying to follow your initial recipe

    a) Build and flash mcuboot
      $ cd <ncs>/bootloader/mcuboot/boot/zephyr
      $ west build -b qi2m_nrf5340_cpuapp --build-dir buildout
      $ nrfjprog -f nrf53 --program buildout/zephyr/zephyr.hex

      I check out reading flash. One image found at
        0x00000000 - 0x0000891f (35104 B)

    b) Build and flash smp_svr
      $ cd <ncs>/zephyr/samples/subsys/mgmt/mcumgr/smp_svr
      $ vim prj.conf
      Add these lines
        CONFIG_MCUMGR_SMP_UART=y
        CONFIG_NET_BUF_USER_DATA_SIZE=7
      $ west build -b qi2m_nrf5340_cpuapp --build-dir buildout
      $ nrfjprog -f nrf53 --program buildout/zephyr/zephyr.hex

      I check out reading flash. Two images found at
        0x00000000 - 0x0000891f (35104 B)
        0x00010200 - 0x0001a62b (42028 B)

    On board restart I get out of UART

      *** Booting Zephyr OS build v2.3.0-rc1-ncs1 ***
      [00:00:00.003,051] <inf> mcuboot: Starting bootloader
      [00:00:00.009,063] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
      [00:00:00.019,165] <inf> mcuboot: Boot source: none
      [00:00:00.024,566] <wrn> mcuboot: Failed reading image headers; Image=0
      [00:00:00.032,012] <err> mcuboot: Unable to find bootable image

    Issuing from host the test command

      $ mcumgr -t 20 --conntype serial --connstring='/dev/ttyUSB0,baud=115200' image list

    I get "Error: NMP timeout"

    What a hell to do ?

Children
  • Hi Gabriele, 

    I'm sorry that it's been a long time and you still having issue with FOTA on nRF53. 

    We now have better documentation for nRF53 including FOTA instruction. 

    Please have a look here: 
    https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_nrf5340.html#fota-upgrades

    The instruction is for FOTA using BLE. And I think you should test first using this transport. Just to make sure smpsvr is working fine. After that you can change CONFIG_MCUMGR_SMP_BT to CONFIG_MCUMGR_SMP_UART to support UART (and add CONFIG_SERIAL=y) 

  • Thank you for your reply.
    I think the problem was due to flashing non signed binary for smp_srv.
    Now I'm able to
    a) Build and flash mcuboot in bootloadr_partition (using JLink)
    b) Build and flash smp_svr in slot0_partition (using JLink)
    c) Build and flash MyApp in slot1_partition (using DFU)
    This is the resulting mcumgr image list
    Images:
     image=0 slot=0
        version: 0.0.0
        bootable: true
        flags: active confirmed
        hash: 6645ebafd4a33787a52b5f76c18f9b66038a25b3413238e22d2432e6bba47677
     image=0 slot=1
        version: 1.3.0
        bootable: true
        flags:
        hash: 17563829483019977c328c7c89114dcb2f872c65b9b5c8d663011e617b9915ad
    Split status: N/A (0)
    Now I see a problem.
    On system restart I get out of UART
     *** Booting Zephyr OS build v2.3.0-rc1-ncs1  ***
     [00:00:00.003,051] <inf> mcuboot: Starting bootloader
     [00:00:00.009,246] <inf> mcuboot: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
     [00:00:00.019,348] <inf> mcuboot: Boot source: none
     [00:00:00.024,810] <inf> mcuboot: Swap type: none
     [00:00:00.138,214] <inf> mcuboot: Bootloader chainload address offset: 0x10000
     [00:00:00.146,026] <inf> mcuboot: Jumping to the first image slot
     *** Booting Zephyr OS build v2.3.0-rc1-ncs1  ***
     [00:00:00.004,425] <inf> smp_sample: build time: Sep 11 2020 13:29:22
    The smp_srv is running, not MyApp !
    How to switch from smp_srv to MyApp, and viceversa ?
    Thank you
  • Hi,

    After you have flashed the smp_svr you can use the mcumgr to DFU your image . 


    After you have your image list with 2 images, you need to either test or confirm the image and trigger a reset for your app to run. 
    Call `Image test <image sha>` or `image confirm <image sha>` and then do a reset. Your application should run after that. 

  • Hi,
    The swap mechanism went well!
    After a "image confirm" the new image (My App) is the active one, persistently.
    But what ? I cannot upload a brand new image.
    How to restore the DFU functionality ?
  • Hi Gabriele, 
    You would need to integrate smpsvr into your application. 
    It's pretty simple. You can just follow the instruction here
    The instruction is for BLE , to do UART DFU you use CONFIG_MCUMGR_SMP_UART = y instead of CONFIG_MCUMGR_SMP_BT. 
    In your main.c you need to call 

    os_mgmt_register_group();
    img_mgmt_register_group();

    In the example, I have prepared the .bin files that you can use to update. Note that after you do : 

    mcumgr -t 20 --conntype serial --connstring=COM37 image upload app_update_new.bin

    You still need to confirm the image "image confirm <img_sha>" and then do a reset. I haven't looked into how you can confirm the image and reset automatically yet.

    peripheral_lbs_dfu_uart.zip

Related