Using nrfutil to program an off-the-shelf XIAO nRF52840 module

System Details:

  • Chip: nRF52840, XIAO Module
  • nRF5 SDK: Version 16.0.0
  • mdk version: 8.46.0
  • nrfjprog version: 10.15.4 external
  • nrfutil version: 6.1.3
  • JLinkARM.dll version: 7.64d

Hello,

I have tested an nRF SDK example application (usbd_generic_hids) on my nRF52840 DK board, and I now would like to try and flash this application onto my off-the-shelf XIAO nRF52840 modules. I have used nrfutil in the past in order to perform DFU, but it has always been for OTA DFU via BLE. I want to know how I can program just the application itself. I believe this usbd_generic_hids example does not require a SoftDevice to be present, and I am not sure if it needs a bootloader (I dont think so).

I havent programmed an off-the-shelf module like this before, so I have a few questions:

  1. I know that the XIAO module comes with a USB bootloader built-in, and I was recommended to leave that bootloader intact for easier programming. However, as I said before, I am familiar with OTA DFU and secure dfu bootloaders on the nRF52840, so I should be able to program this device wirelessly and not have to worry about overwriting the default XIAO bootloader with a nRF-based bootloader. I would personally prefer to use our normal dfu secure bootloader, with softdevice, because this is more consistent with the other versions of this device that I have been developing. Is this possible? Is there anything I should be aware of in this process?
  2. I have tried using nrfutil to generate a package of the application code by itself. It compiles and creates the .zip package just fine, but it fails to actually perform the DFU (error message included below). Is it even possible to do what I am trying? I feel like I need the dfu bootloader on-board in order to perform this usb-based dfu process.
  3. Any general advice on what resources will help me learn how to do this?

Thank you in advance :)

Parents
  • According to https://wiki.seeedstudio.com/XIAO_BLE/ the manufacturer advises flashing this device through the Arduino GUI.  Are you sure their default bootloader implements a serial protocol compatible with nrfutil?

    However, as I said before, I am familiar with OTA DFU and secure dfu bootloaders on the nRF52840, so I should be able to program this device wirelessly and not have to worry about overwriting the default XIAO bootloader with a nRF-based bootloader

    FWIW: I started off using nrfutil to program my nRF52840 Dongles through the Open Bootloader that it ships with.  This was sufficient for early prototyping and evaluation.  But when it came time to support OTA updates I wanted our own public key embedded into the bootloader so that it would only accept properly signed release images.  I also wanted to enforce a static partition map that won't change in future builds.  So I reflashed the dongles with a homebuilt mcuboot image through the SWD pins (just SWIO, SWCLK, GND).

  • Thanks for the quick response  

    Are you sure their default bootloader implements a serial protocol compatible with nrfutil?

    Good question. No I am not sure.

    I was recommended this specific module and the recommender also mentioned that I could use nrfutil to program it. I have taken their word on good faith, but I am not 100% sure that it is accurate. This is sort of why I came to this forum after running into issues.

    I am familiar with the Arduino IDE, but have never used it to flash a separate application. I see in the docs that you linked that it is possible to get simple Arduino example code running on the board, but I wonder: Is it possible to flash my compiled nRF SDK application .hex/.bin file directly to the XIAO board via the Arduino IDE? Are there any resources out there where I could read more about this kind of thing? Is the first comment on this thread relevant?
    or will I have to create an Arduino IDE-created version of my nRF52840 application from scratch? I hope there is an easier option than this...

    So I reflashed the dongles with a homebuilt mcuboot image through the SWD pins (just SWIO, SWCLK, GND).

    I was also thinking this could be a realistic option, but wanted to see if there might be a software solution. Good to know its not too unreasonable to take this route if all else fails.

    Thanks again for the help,

    Corten

  • I was recommended this specific module and the recommender also mentioned that I could use nrfutil to program it.

    If I'm looking at the correct repo, then it seems like the Arduino support package does use adafruit-nrfutil under the hood: https://github.com/zhanggw7/Seeed_52840_Core/blob/main/platform.txt

    tools.nrfutil.upload.pattern="{cmd}" {upload.verbose} dfu serial -pkg "{build.path}/{build.project_name}.zip" -p {serial.port} -b 115200 --singlebank

    Running in verbose mode (per  Is there a way to configure nrfutil to show all the bytes transmitted and received?  ) might help determine whether the bootloader is completely unresponsive / speaking the wrong protocol, or if a few commands are working and then it's getting wedged at one specific place.

    So I reflashed the dongles with a homebuilt mcuboot image through the SWD pins (just SWIO, SWCLK, GND).

    I should probably add: in order to tell NCS that I was using a dongle without the default bootloader, I created a new board definition in my project tree.  So now I build with `west -b raw_dongle` rather than `west -b nrf52840dongle_nrf52840`

    Maybe this works differently with the old nRF SDK; I have never used it.

  • github.com/.../quote]

    Nice find on the repo. Clearly they are using the nrfutil under the hood. So I updated my nrfutil dfu command with the verbose flags, and here is the output:

    Note that the delay between the output of Line 21 and the output of Line 22 is over 30 seconds long. I thought it was just going to crash as usual. But you can see that we are getting a few slip messages to appear before the crash.

    For a weird sanity check, I called the nrfutil dfu command with serial instead of usb-serial, hoping that things might magically work out. As expected, it still didnt work. Just sharing the output in case there is anything valuable there:

    There are maybe 2 or 3 posts in Google that are showing up with this same error message with nRF52840 nrfutil dfu attempts...but none of them really have a solution. Someone mentioned disabling the MSD, but this XIAO module doesnt appear as a flash storage icon when plugged in, so I dont think that is relevant. Im not sure how to proceed further...do those slip messages mean anything to you?

  • UPDATE:

    I realize that I have downloaded the standard nrfutil tool, not the adafruit-nrfutil tool. So I uninstalled the former and installed the latter, and also tweaked a couple of the inputs, and was able to get these new, more informative error messages:

    Out of the listed possible causes, it appears that we can rule out bullet point 2 as we are setting the baud rate specifically, and we see in the output that Flow Control is disabled. So it could be the bootloader issue....or possibly the DFU state, since I have not done anything to step it into DFU state so far. However, I have had difficulty finding out how to manually place the device into DFU mode....its unclear as to what the DFU pin is. I grounded the RST pin, and that is actually what got the second of the 2 error messages I just shared to display.

    Also, I realized that this XIAO module does appear as a flash storage icon when plugged in, which means I could possibly try the previous solution I came across which involved disabling the MSD. Is there a known way to disable this aside from JLINK (which is what is recommended in the docs)? Because if I hook up the JLINK connections, I may as well just program the device that way...

  • Hello,

    I was not able to find any documentation that confirmed what bootloader this module shipped with either, but the fact that it enumerates as a mass storage device indicates that it is not executing our bootloader, at least . Maybe it supports drag&drop programming instead?

    Another alternative to DFU over USB is to use one of the Debug outputs from your nRF52840DK to program the module. Just remember that the module must have the same VDD voltage as the DK because the OB Jlink doesn't have a built-in level shifter like you will find in a standalone J-link programmer.

Reply
  • Hello,

    I was not able to find any documentation that confirmed what bootloader this module shipped with either, but the fact that it enumerates as a mass storage device indicates that it is not executing our bootloader, at least . Maybe it supports drag&drop programming instead?

    Another alternative to DFU over USB is to use one of the Debug outputs from your nRF52840DK to program the module. Just remember that the module must have the same VDD voltage as the DK because the OB Jlink doesn't have a built-in level shifter like you will find in a standalone J-link programmer.

Children
No Data