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.
    + nrfutil pkg generate --hw-version 52 --sd-req 0xCA --application-version 1 --application ../nrf-sdk/examples/peripheral/usbd_hid_generic/pca10056/blank/armgcc/_build/nrf52840_xxaa.hex usbd_hid.zip                         
                                                                                                                                                                                                                                   
    |===============================================================|                                                                                                                                                              
    |##      ##    ###    ########  ##    ## #### ##    ##  ######  |                                                                                                                                                              
    |##  ##  ##   ## ##   ##     ## ###   ##  ##  ###   ## ##    ## |                                                                                                                                                              
    |##  ##  ##  ##   ##  ##     ## ####  ##  ##  ####  ## ##       |                                                                                                                                                              
    |##  ##  ## ##     ## ########  ## ## ##  ##  ## ## ## ##   ####|                                                                                                                                                              
    |##  ##  ## ######### ##   ##   ##  ####  ##  ##  #### ##    ## |                                                                                                                                                              
    |##  ##  ## ##     ## ##    ##  ##   ###  ##  ##   ### ##    ## |                                                                                                                                                              
    | ###  ###  ##     ## ##     ## ##    ## #### ##    ##  ######  |                                                                                                                                                              
    |===============================================================|                                                                                                                                                              
    |You are not providing a signature key, which means the DFU     |                                                                                                                                                              
    |files will not be signed, and are vulnerable to tampering.     |                                               
    |This is only compatible with a signature-less bootloader and is|                                               
    |not suitable for production environments.                      |                                               
    |===============================================================|                                               
                                                                                                                    
    Zip created at usbd_hid.zip                                                                                     
    + nrfutil dfu usb-serial -pkg usbd_hid.zip -p /dev/cu.usbmodem14301 -b 115200                                   
      [------------------------------------]    0%                                                                  
    Traceback (most recent call last):                                                                              
      File "/usr/local/bin/nrfutil", line 8, in <module>                                                            
        sys.exit(cli())                                                                                             
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1128, in __call__                           
        return self.main(*args, **kwargs)                                                                           
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main                               
        rv = self.invoke(ctx)                                                                                       
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke                             
        return _process_result(sub_ctx.command.invoke(sub_ctx))                                                     
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke                             
        return _process_result(sub_ctx.command.invoke(sub_ctx))                                                     
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke                             
        return ctx.invoke(self.callback, **ctx.params)                                                              
      File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke                              
        return __callback(*args, **kwargs)                                                                          
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/__main__.py", line 1022, in usb_serial
        do_serial(package, port, connect_delay, flow_control, packet_receipt_notification, baud_rate, serial_number, False,
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/__main__.py", line 978, in do_serial                                                                                                                                 
        dfu.dfu_send_images()                               
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/dfu/dfu.py", line 127, in dfu_send_images
        self._dfu_send_image(self.manifest.application)     
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/dfu/dfu.py", line 88, in _dfu_send_image                                                                                                                             
        self.dfu_transport.open()                           
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 217, in open                                                                                                                      
        self.__get_mtu()                                                                                            
      File "/usr/local/lib/python3.9/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 366, in __get_mtu                                                                                                                 
        self.mtu = struct.unpack('<H', bytearray(response))[0]                       
    TypeError: cannot convert 'NoneType' object to bytearray  
  3. Any general advice on what resources will help me learn how to do this?

Thank you in advance :)

  • Hello,

    I'm glad to hear that you were able to program the module through the debug interface.

    cor10 said:
    Why is this the case? For example, when I plug in the nRF52840 DK, it also appears as a flash storage icon. So why does this fact help us distinguish that it is not a Nordic bootloader?

    The main USB on the DK is connected to the standalone J-link interface chip and not to the nRF52840's USB (the nRF usb is the one on the side). The J-link will enumerate as a composite device with 1-2 VCOM ports and a mass storage device.

    cor10 said:
    I am having trouble replying to the most recent comment left by Mytzjay, but I was able to learn a bit more about the device. I found some information on board my XIAO module that mentions the bootloader, as well as some other high level details. Take a look:

    UF2 is a different bootloader which you can read more about here: https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython/uf2-bootloader-details

  • It looks like I hosed the softdevice on my XIAO using one/some of the NRF5 SDK examples. The UF2 mass storage bootloader interface takes the executables, but they simply don't work.(It could be that I zapped the bootloader in the process as well). Any ideas how to use the UF2 bootloader to replace the softdevice and/or the UF2 bootloader itself. I'd like to avoid messing with j-link for the moment.

  • I managed to fix it. The UF2 bootloader is apparently protected so it likely survived my testing completely unscathed. However, the bootloader can be updated and likely replaced through the mass storage and likely the BOSSA emulated serial interface using some "secret" wrapper code: learn.adafruit.com/.../uf2-bootloader-details

    To restore the softdevice, I simply ran the uf2conv.py -c -f 0xADA52840 -o s140_nrf52_7.3.0_softdevice.uf2 s140_nrf52_7.3.0_softdevice.hex on the softdevice file and uploaded it via the UF2 mass storage interface. In the process I learned that the softdevice is loaded at 0x0 and the executable is expected at 0x27000.

    Running code that does not require the softdevice can be accomplished by compiling and linking it with a 0x27000 start address (yes, you loose some code storage, but gain convenience and flexibility). You need to massage the .emProject file and perhaps the local .ld file (or delete the local .ld file so the default is used). It worked for me. I believe the bootloader and not the softdevice expects the executable to be at 0x27000.

    Some UF2 bootloader sources state that you need 7.x softdevice and that 6.x is incompatible, but I suspect it may be that 6.x executables are compiled to start at 0x26000, which can likely be changed to 0x27000 just like the 0x0 start executables. However, I haven't tested with 6.x.

Related