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

NRFUTIL does not disconnect after BLE DFU error

HI,

I have found some problem with nrfutil (version 5.2.0 installed from pypi). 

Problem description:

When I am updating dfu with success (correct keys, packages etc) everything goes fine but in my CI test I am verifying situation that package signed with wrong key is trying to be updated over dfu ble. In this case dfu procedure should fail and it fails with proper code:
DFU CALL:  nrfutil dfu ble -ic NRF52 -p /dev/ttyACM0 -a 70B3D5C53310 -pkg application.zip

Traceback (most recent call last):
  File "/home/patlas/.local/bin/nrfutil", line 11, in <module>
    sys.exit(cli())
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/patlas/.local/lib/python2.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/__main__.py", line 812, in ble
    dfu.dfu_send_images()
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu.py", line 122, in dfu_send_images
    self._dfu_send_image(self.manifest.application)
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu.py", line 90, in _dfu_send_image
    self.dfu_transport.send_init_packet(data)
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_ble.py", line 495, in send_init_packet
    if try_to_recover():
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_ble.py", line 489, in try_to_recover
    self.__execute()
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_ble.py", line 583, in __execute
    self.__get_response(DfuTransportBle.OP_CODE['Execute'])
  File "/home/patlas/.local/lib/python2.7/site-packages/nordicsemi/dfu/dfu_transport_ble.py", line 660, in __get_response
    raise NordicSemiException('Response Code {}'.format(get_dict_key(DfuTransport.RES_CODE, resp[2])))
pc_ble_driver_py.exceptions.NordicSemiException: Response Code InvalidObject

but unfortunately my devkit (which perform nrfutil dfu process) does not disconnect from updated peripheral. The only thing that I can do to perform disconnection is disconnect usb power supply from devkit but this solution in unacceptable in my case.
How to deal with it? Is it a bug in nrfutil?

Parents
  • Hello,

    I was not able to reproduce what you describe:

    As you can see I try to perform DFU with a packet with wrong key, but I am able to retry without powering off any of the DKs. 

     

    The only thing that I can do to perform disconnection is disconnect usb power supply from devkit but this solution in unacceptable in my case.

     Do you mean the DK that is connected to the COM port COMX that you use in the command:

    nrfutil dfu ble ... -p COMX ...

    ?

    Best regards,

    Edvin

  • Please reproduce it the same way as I do. As you see in my log I am doing it on linux (my case is Debian Buster). Maybe there is some issue in python serial implementation?

    Do you mean the DK that is connected to the COM port COMX that you use in the command: nrfutil dfu ble ... -p COMX ... ?

    Yes, exactly that DK.

    Additionally: I have considered your example, and I can retry perform DFU process once again after fail (wrong package) as you mention. But try to add some led indicator to your code which shows you that "slave" is connected, than you will see that after dfu fail, updated device stays connected with DK (dfu master) which means that after fail nrfutil does not send disconnection request to slave.


    If you wish I can provide You Dockerfile which shows that issue but I thin that after adding some led indicator (or look inside debugger) you will see that after fail (nrfutil process fail and exit) devices stays connected.

Reply
  • Please reproduce it the same way as I do. As you see in my log I am doing it on linux (my case is Debian Buster). Maybe there is some issue in python serial implementation?

    Do you mean the DK that is connected to the COM port COMX that you use in the command: nrfutil dfu ble ... -p COMX ... ?

    Yes, exactly that DK.

    Additionally: I have considered your example, and I can retry perform DFU process once again after fail (wrong package) as you mention. But try to add some led indicator to your code which shows you that "slave" is connected, than you will see that after dfu fail, updated device stays connected with DK (dfu master) which means that after fail nrfutil does not send disconnection request to slave.


    If you wish I can provide You Dockerfile which shows that issue but I thin that after adding some led indicator (or look inside debugger) you will see that after fail (nrfutil process fail and exit) devices stays connected.

Children
  • I think I understand what you mean. nrfutil is not disconnecting after a failed attempt. If you want this, you must implement that. In most cases, when an update fails, maybe due to a disconnect. When the devices disconnect, the bootloader has a timer that times out eventually. When this happens, the device resets, and will run the application that was previously programmed. 

    If you wish to disconnect from nrfutil after a failed attempt. This occurs in nrfutil\nordicsemi\dfu\dfu_transport_ble.py on line 661. Maybe you can use this event with status "InvalidObject" to disconnect? 

    Another "quick fix" if you want to disconnect is to use the command: "nrfjprog --reset". If you have several DKs connected, you can use nrfjprog --reset --snr <serial_number>.

    Best regards,

    Edvin

  • I found out solution with sending reset to DK but from my point of view, problem I have noticed is bug in nrfutil application. If application exit without crash (exception is caught and information about invalid object is displayed) but with proper error code it should perform disconnection. What and how is implemented on ble device (dfu receiver) side is custom user device application approach and it should not be impacted by external tool implementation like you suggested.
    Each nrfutil application exit (manually, on crach, on error, etc) should perform ble disconnect process.

Related