adafruit / Adafruit_nRF52_nrfutil

Modified version of Nordic's nrfutil 0.5.x for use with the Adafruit Feather nRF52
BSD 3-Clause "New" or "Revised" License
87 stars 29 forks source link

Upload issues on Linux #13

Closed vakker closed 4 years ago

vakker commented 4 years ago

I'm trying to flash an Adafruit feather nRF52840 on Linux. I followed the steps from here, but I keep running into issues. I tried both the Arduino IDE and Platformio CLI and they seem to have the same error that leads back to adafruit-nrfutil.

I tried to reproduce the same issue on Windows, but I could not so it seems to be a Linux only one (I haven't tried MacOS).

What happens:

I can upload the sketch once and then when I try to upload a new one, I get an error (same for Arduino IDE and PlatformIO):

Upgrading target on /dev/ttyACM0 with DFU package /tmp/arduino_build_772392/blinky.ino.zip. Flow control is disabled, Single bank, Touch disabled
Timed out waiting for acknowledgement from device.

Failed to upgrade target. Error is: No data received on serial port. Not able to proceed.
Traceback (most recent call last):
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/__main__.py", line 294, in serial
    dfu.dfu_send_images()
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/dfu/dfu.py", line 235, in dfu_send_images
    self._dfu_send_image(HexType.APPLICATION, self.manifest.application)
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/dfu/dfu.py", line 206, in _dfu_send_image
    self.dfu_transport.send_firmware(firmware)
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/dfu/dfu_transport_serial.py", line 213, in send_firmware
    self.send_packet(pkt)
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/dfu/dfu_transport_serial.py", line 243, in send_packet
    ack = self.get_ack_nr()
  File "/home/user/workspace/tools/Adafruit_nRF52_nrfutil/nordicsemi/dfu/dfu_transport_serial.py", line 282, in get_ack_nr
    raise NordicSemiException("No data received on serial port. Not able to proceed.")
nordicsemi.exceptions.NordicSemiException: No data received on serial port. Not able to proceed.

Possible causes:
- Selected Bootloader version does not match the one on Bluefruit device.
    Please upgrade the Bootloader or select correct version in Tools->Bootloader.
- Baud rate must be 115200, Flow control must be off.
- Target is not in DFU mode. Ground DFU pin and RESET and release both to enter DFU mode.

Or I get this (for Arduino IDE):

Global variables use 5980 bytes (2%) of dynamic memory, leaving 242852 bytes for local variables. Maximum is 248832 bytes.
processing.app.debug.RunnerException
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
    at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
    at processing.app.SketchController.upload(SketchController.java:732)
    at processing.app.SketchController.exportApplet(SketchController.java:703)
    at processing.app.Editor$UploadHandler.run(Editor.java:2075)
    at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port '/dev/ttyACM0'.
    at processing.app.Serial.touchForCDCReset(Serial.java:107)
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
    ... 5 more
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM0; Method name - openPort(); Exception type - Port busy.
    at jssc.SerialPort.openPort(SerialPort.java:164)
    at processing.app.Serial.touchForCDCReset(Serial.java:101)
    ... 6 more

and this for Platformio:

Failed to upgrade target. Error is: Serial port could not be opened on /dev/ttyACM0. Reason: [Errno 16] could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'
Traceback (most recent call last):
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/serial/serialposix.py", line 265, in open
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK)
OSError: [Errno 16] Device or resource busy: '/dev/ttyACM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 113, in open
    self.serial_port = Serial(port=self.com_port, baudrate=self.baud_rate, rtscts=self.flow_control, timeout=self.timeout)
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/serial/serialutil.py", line 240, in __init__
    self.open()
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/serial/serialposix.py", line 268, in open
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg))
serial.serialutil.SerialException: [Errno 16] could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/nordicsemi/__main__.py", line 294, in serial
    dfu.dfu_send_images()
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/nordicsemi/dfu/dfu.py", line 235, in dfu_send_images
    self._dfu_send_image(HexType.APPLICATION, self.manifest.application)
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/nordicsemi/dfu/dfu.py", line 157, in _dfu_send_image
    self.dfu_transport.open()
  File "/home/user/miniconda3/envs/nrf/lib/python3.7/site-packages/nordicsemi/dfu/dfu_transport_serial.py", line 115, in open
    raise NordicSemiException("Serial port could not be opened on {0}. Reason: {1}".format(self.com_port, e))
nordicsemi.exceptions.NordicSemiException: Serial port could not be opened on /dev/ttyACM0. Reason: [Errno 16] could not open port /dev/ttyACM0: [Errno 16] Device or resource busy: '/dev/ttyACM0'

Possible causes:
- Selected Bootloader version does not match the one on Bluefruit device.
    Please upgrade the Bootloader or select correct version in Tools->Bootloader.
- Baud rate must be 115200, Flow control must be off.
- Target is not in DFU mode. Ground DFU pin and RESET and release both to enter DFU mode.

I tried older versions of adafruit-nrftool, but it didn't help.

vakker commented 4 years ago

I found one issue with Linux that is mentioned here. The solution is to run sudo apt purge modemmanager, as the guide says: If you're on Linux, and are seeing multi-second delays connecting to the serial console, or are seeing "AT" and other gibberish when you connect, then the modemmanager service might be interfering. Just remove it; it doesn't have much use unless you're still using dial-up modems.

Regarding the No data received on serial port. Not able to proceed. error, I assume have to put the board in DFU mode (by double pressing the reset button) every time. The guides do not say that the button needs to be pressed before uploading. However, using --touch 1200 does make it work. I.e. the full command: adafruit-nrfutil --verbose dfu serial -p /dev/ttyACM0 -b 115200 --singlebank -pkg <pkg.zip> --touch 1200

Maybe this will help someone in the future.