Serial port suddenly vanished on adafruit nrf52840 right after uploading code

I’ve been developing on the adafruit feather nrf52840 express for several months now. I have 3 different boards. One of them suddenly stopped showing up as a serial port after I finished uploading my code. That board had been working perfectly fine all day long (tests, firmware upload, etc…)
The code built and uploaded fine (via USB as I had been doing several dozen times), after which I did a pio device monitor, which showed me:


$ pio device monitor 
Error: Traceback (most recent call last):
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/platformio/__main__.py", line 102, in main
    cli()  # pylint: disable=no-value-for-parameter
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/platformio/cli.py", line 71, in invoke
    return super().invoke(ctx)
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/platformio/device/monitor/command.py", line 127, in device_monitor_cmd
    options["port"] = SerialPortFinder(
  File "/home/ludozb/.platformio/penv/lib/python3.10/site-packages/platformio/device/finder.py", line 156, in find
    return best_port or port
UnboundLocalError: local variable 'port' referenced before assignment
============================================================
An unexpected error occurred. Further steps:
* Verify that you have the latest version of PlatformIO using
  `pip install -U platformio` command

* Try to find answer in FAQ Troubleshooting section
  https://docs.platformio.org/page/faq/index.html

* Report this problem to the developers
  https://github.com/platformio/platformio-core/issues
============================================================

Does platformIO always throw this message when it can’t find a serial port?

From then on, the board will only appear as a serial port if I double press the reset button to enter into bootloader. In bootloader I can program the board (upload some firmware), but after power cycle the board, it will not appear anymore on my computer’s serial port.

I have tried:

  • to burn the latest bootloader using a blackmagic probe: bootloader does get burnt fine, but board remains in the same state of not showing its serial port unless in bootloader mode
  • to use the ARduino IDE: same phenomena: no serial port appears, but if I am in the bootloader I can upload any sketch (blink, …).
  • to upload a slightly modified blink (including some serial data to show on/off at the same pace as the blinking LED) using the blackmagic probe, no change: the code uploads, the LED blinks but then no serial port after power cycle.
  • to use a different usb cable (I knew the one I was using was fine since I had uploaded code successfully few minutes before the board stops showing as serial port)
  • install CircuitPython on my board (reference), test the IMU connected to my board with some sample code, see it serial works: it does. Then uninstall CircuitPython to revert to uploading with ARduino or PlatformIO: back to the same, no more serial port

pio --version: PlatformIO Core, version 6.1.4

I have read this related information: Add notes for USB Serial · Issue #119 · platformio/platform-nordicnrf52 · GitHub (I’m the one to have made the comment that there’s no need for lib_archive = no in that issue), but have had no issue whatsoever since the time of my comment.

It is the second time I have this issue (same board reference feather nrf52840, different board), reported here on adafruit forum (solution proposed tried, didn’t work).

Why would the board behave this way? It may not be a platformIO related issue after all, but the long error message above looked a bit suspicious.

Should be fixed in Speeded up device port finder · platformio/platformio-core@490af8a · GitHub, try CLIpio upgrade --dev and retry.

1 Like

Max, when I read your message I was unable to test your idea. But I thought: how come upgrading platformIO would solve the board’s port invisibility on 2 different unrelated computers, one of them having no development tool installed beside a port monitor and the ability to list visible serial ports.

Well…

It worked. I did the upgrade. Obviously right after the upgrade the board was still invisible (it was running a blink sketch). I put the board in bootloader mode, reupload my blink, do a pio device list, and … the board was now listed! pio device monitor also shows the expected output in the terminal.

As much as I’m really grateful for your solution and relieved that the problem is solved, I would like to understand what happened!

Opened questions (to myself and anyone else):

  • Why did the board stopped being visible on any computer’s serial port and as reported above: did platformio caused the issue (the way it uploaded code or what it actually uploaded on the board), or is it specific to the nrf52840, or to the adafruit carrier board for that processor?
  • How come a one line change in platformio core aimed at speeding up the device port finder could make the board be visible again as a serial port?