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

Nrfutil USB DFU trigger seems not to work on Linux systems

Hi

I am developing an application for the nrf52840dongle. I want to be able to connect the dongle to a Raspberry Pi 3B+ which has a zip file containing the new firmware to be flashed. The zipfile is not generated on the Pi itself.

On my Windows pc everything works fine using the v6.1.0 executable, the DFU bootloader gets triggered, the device reboots, enters bootloader and flashes the new application.

nrfutil -v -v -v -v dfu usb-serial -pkg file.zip -p COM20

2021-05-28 09:39:20,536 Using board at serial port: COM20
2021-05-28 09:39:20,552 Sending Application image.
2021-05-28 09:39:24,093 Serial: DFU bootloader was triggered
2021-05-28 09:39:24,093 Serial: Waiting 500 ms for device to enter bootloader 1/10 time
2021-05-28 09:39:24,603 Serial: Set Packet Receipt Notification 0
2021-05-28 09:39:24,603 SLIP: --> [2, 0, 0]
2021-05-28 09:39:24,604 SLIP: <-- [96, 2, 1]
2021-05-28 09:39:24,604 SLIP: --> [7]
2021-05-28 09:39:24,605 SLIP: <-- [96, 7, 1, 3, 8]
2021-05-28 09:39:24,605 Sending init packet...
2021-05-28 09:39:24,606 Serial: Selecting Object: type:1
2021-05-28 09:39:24,607 SLIP: --> [6, 1]

...

When I try the same on a Linux pc or Raspberry Pi, I do get the following:

nrfutil -v -v -v -v dfu usb-serial -pkg file.zip -p /dev/ttyACM0
2021-05-28 10:13:37,333 Using board at serial port: /dev/ttyACM0
2021-05-28 10:13:37,345 Sending Application image.
2021-05-28 10:13:37,936 LIBUSB_ERROR_ACCESS: Unable to connect to trigger interface.
2021-05-28 10:13:37,936 Serial: Waiting 500 ms for device to enter bootloader 1/10 time
2021-05-28 10:13:38,444 Serial: Waiting 500 ms for device to enter bootloader 2/10 time
2021-05-28 10:13:38,952 Serial: Waiting 500 ms for device to enter bootloader 3/10 time
2021-05-28 10:13:39,460 Serial: Waiting 500 ms for device to enter bootloader 4/10 time
2021-05-28 10:13:39,968 Serial: Waiting 500 ms for device to enter bootloader 5/10 time
2021-05-28 10:13:40,476 Serial: Waiting 500 ms for device to enter bootloader 6/10 time
2021-05-28 10:13:40,985 Serial: Waiting 500 ms for device to enter bootloader 7/10 time
2021-05-28 10:13:41,493 Serial: Waiting 500 ms for device to enter bootloader 8/10 time
2021-05-28 10:13:42,001 Serial: Waiting 500 ms for device to enter bootloader 9/10 time
2021-05-28 10:13:42,509 Serial: Waiting 500 ms for device to enter bootloader 10/10 time
2021-05-28 10:13:43,018 Serial: Device is either not in bootloader mode, or using an unsupported bootloader.
2021-05-28 10:13:43,020 Serial: Set Packet Receipt Notification 0
2021-05-28 10:13:43,021 SLIP: --> [2, 0, 0]
2021-05-28 10:13:44,032 SLIP: --> [7]
Traceback (most recent call last):
  File "/home/pi/.local/bin/nrfutil", line 10, in <module>
    sys.exit(cli())
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/__main__.py", line 1001, in usb_serial
    timeout)
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/__main__.py", line 958, in do_serial
    dfu.dfu_send_images()
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu.py", line 129, in dfu_send_images
    self._dfu_send_image(self.manifest.application)
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu.py", line 90, in _dfu_send_image
    self.dfu_transport.open()
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 217, in open
    self.__get_mtu()
  File "/home/pi/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 366, in __get_mtu
    self.mtu = struct.unpack('<H', bytearray(response))[0]
TypeError: 'NoneType' object is not iterable

Is someone experiencing the same issue or is there any solution for this?

When I manually put the nrf52 in bootloader mode, the application gets uploaded without any problem.

Kind regards

  • Adding sudo to the command did the trick.

    sudo nrfutil -v -v -v -v dfu serial -pkg ot-rcp.zip -p /dev/ttyACM0

    works fine

  • Thanks for updating the thread. You may also consider giving your user write access to ttyACM0 so you don't have to run the script as root.

    https://devzone.nordicsemi.com/f/nordic-q-a/52546/nrf-connect-linux

  • Does this work really on Raspberry Pi ? I mean its ARM. I see nowhere that this is supported.

    For me this:

    sudo nrfutil -v -v -v -v dfu serial -pkg app_dfu_package.zip -p /dev/ttyAMA0 -b 115200 -prn 1 -fc 0


    is not working on Raspberry Pi (using nrfutil version 5.2.0). On Windows (nrfutil version 6.1.7) no problem.
    Bootloader has disabled HWFC and Baudrate is set to 115200.  

  • Getting serial DFU to work on the Pi should be possible without much effort as it doesn’t rely on precompiled C libraries like DFU over BLE. What version of Python is installed on this Pi? You might need to use an older version than the one distributed with the OS, but it should be Python 3, not Python 2. Python 3 is compatible with version 6.1.7.

  • I got it working. =) 

    here my instructions:

    # Install nrfutil on RPi4
    
    ```console
    mkdir nrfutil
    cd nrfutil
    curl -LO https://github.com/NordicSemiconductor/pc-nrfutil/archive/v6.1.7.zip
    unzip v6.1.7.zip
    cd pc-nrfutil-6.1.7
    ```
    
    replace "pc_ble_driver_py >= 0.16.4" to "pc_ble_driver_py" in requirements.txt
    ```console
    sed -i 's/pc_ble_driver_py >= [^ ]*/pc_ble_driver_py/' requirements.txt
    ```
    
    check max python version in setup.py with the python on the system
    python_requires='>=3.7, <3.11',
    
    ```console
    python3 -m pip install -r requirements.txt
    ```
    
    if `python3 -m pip install -r requirements.txt` not working? check [[https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-mana](https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-mana)]
    
    may try:
    ```console
    python3 -m venv .venv
    source .venv/bin/activate
    python3 -m pip install -r requirements.txt
    ```
    
    ```console
    pip install .
    ```
    
    
    perform dfu via serial (the start may takes some time up to 30 seconds or more):
    
    ```console
    nrfutil dfu serial -pkg app_dfu_package.zip -p /dev/ttyAMA0 -b 115200 -prn 1 -fc 0
    ```
    or
    ```console
    nrfutil dfu serial -pkg app_dfu_package.zip -p /dev/ttyS0 -b 115200 -prn 1 -fc 0
    ```
    `/dev/ttyAMA0` for (Bullseye) and `/dev/ttyS0` for (Bookworm)?
    
    perform dfu serial with debug
    ```console
    nrfutil -v -v -v -v dfu serial -pkg app_dfu_package.zip -p /dev/ttyAMA0 -b 115200 -prn 1 -fc 0
    ```


Related