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

BLE DFU on nrfutil fails with NRF_ERROR_RESOURCES

Now that nrfutil has been ported to Python 3, I've been trying to get a DFU controller set up on a Raspberry Pi 3A running Raspbian Lite. I've built and installed the pc-ble-driver v4.1.1 as well as the Python bindings v0.13.0. I have been able to successfully use the examples that came with pc-ble-driver-py, such as the heart rate monitor, with no issues, so I know the drivers and bindings are installed correctly. An nRF52832 devkit is connected via USB (which on the Pi corresponds to the port /dev/ttyACM0) to the Pi and is running the 1M connectivity firmware. The drivers, python bindings, and connectivity firmware are all compiled for softdevice v5.1.0.

I also built and installed v6.0.0a1 of nrfutil, and set up a DFU target using another nRF52832 devkit running what is essentially a copy of the SDK15.3, softdevice s132 v6 secure bootloader. The only changes I made to that bootloader code were to add some print statements for debugging purposes, and set the MTU to 247. I checked using the nRF Connect Android app, and the DFU target device is indeed advertising correctly and is DFU-able from the app. However, when I attempt to DFU the target from the Pi instead I get this error message:

> nrfutil dfu ble -pkg /home/pi/Pylon/embedivet_firmware_package.zip -p /dev/ttyACM0 -ic NRF52 -n "DfuTarg" -mtu 247

Traceback (most recent call last):
  File "/usr/local/bin/nrfutil", line 11, in <module>
    load_entry_point('nrfutil==6.0.0a1', 'console_scripts', 'nrfutil')()
  File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/__main__.py", line 1145, in ble
    dfu.dfu_send_images()
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu.py", line 127, in dfu_send_images
    self._dfu_send_image(self.manifest.application)
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu.py", line 100, in _dfu_send_image
    self.dfu_transport.send_firmware(data)
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu_transport_ble.py", line 555, in send_firmware
    try_to_recover()
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu_transport_ble.py", line 543, in try_to_recover
    offset = response['offset'])
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu_transport_ble.py", line 632, in __stream_data
    self.dfu_adapter.write_data_point(list(to_transmit))
  File "/home/pi/.local/lib/python3.7/site-packages/nrfutil-6.0.0a1-py3.7.egg/nordicsemi/dfu/dfu_transport_ble.py", line 340, in write_data_point
    self.adapter.write_cmd(self.conn_handle, DFUAdapter.DP_UUID, data)
  File "/home/pi/.local/lib/python3.7/site-packages/pc_ble_driver_py/ble_adapter.py", line 494, in write_cmd
    raise e
  File "/home/pi/.local/lib/python3.7/site-packages/pc_ble_driver_py/ble_adapter.py", line 482, in write_cmd
    response = self.driver.ble_gattc_write(conn_handle, write_params)
  File "/home/pi/.local/lib/python3.7/site-packages/pc_ble_driver_py/ble_driver.py", line 107, in wrapper
    error_code=err_code,
pc_ble_driver_py.exceptions.NordicSemiException: Failed to ble_gattc_write. Error code: NRF_ERROR_RESOURCES

Looking through other posts here on DevZone, this error is supposed to be solved by either increasing the MTU size (which is already at its maximum of 247), or by waiting until the packet queue is free. While I could certainly implement the latter in my own code, I'm hesitant about modifying someone else's code unless necessary. Thus, I first wanted to ask if there are any other possible reasons why ble_gattc_write might throw this error or any other possible fixes before I started tinkering.

Regards,
Lexi

Parents Reply Children
  • Hello Simon,

    Thank you for your response. Yes, that was pretty much the solution that I'd had in mind. It turned out the pc_ble_driver_py bindings already handled this error in a similar way, but this code was never being called because for some reason it was only checking for the string "Error code: 19" instead of "NRF_ERROR_RESOURCES" which was what was being thrown. By changing this line to check for the latter string instead, I was able to get nrfutil to work completely. I plan to submit a pull request to the pc_ble_driver_py repository with this fix.

    Regards,
    Lexi

Related