RAK4631 (nRF52): No serial port when compiled with PlatformIO, same code fine in Arduino IDE


I’m using the RAK Wireless 4631 board. Followed their configuration for PlatformIO.

Running into an issue where the most basic of sketches ( setup{} loop{} ) when compiled and upload via Arduino IDE results the board presenting a serial port in Windows. But the same code compiled and uploaded via PlatformIO does not present a serial port. You need to put the board in update mode to get the (alternative) serial port detected.

I have a thread going at the RAK forum, but unfortunately there is no clear solution.

I tried the board on different Windows machines and the behaviour is the same: sketch compiled in Arduino IDE → Serial port shows up, compiled in PlatformIO → no serial port.

Any hints on what to try would be helpful


Okay, then let’s just find out what’s different between PlatformIO and the Arduino IDE.

Please provide the following:

  1. your exact platformio.ini
  2. a verbose PlatformIO build log and upload (CLIpio run -t clean, pio run -v 2>&1 > pio_build.log, upload the new file via e.g. pastebin.com)
  3. The RAK Arduino core version used in the Arduino IDE (Tools → Boards → Board Manager)
  4. A screenshot of your Arduino IDE → “Tools” settings menu with which it works
  5. A verbose Arduino IDE build log and upload (File → Preferences → Verbose Build and Upload ticked, then upload triggered, upload all output via e.g. pastebin.com)

Fantastic, tx so much for responding!

  1. RAK PIO ini - Pastebin.com
  2. pio_build.log - Google Drive
  3. RAK Board v 1.3.3

5) Arduino RAK Build log - Pastebin.com

Their installation procedure has a few weaknesses in my eyes, in particular it blindly patches (read: copies their variant folder for the RAK4631) the framework-arduinoadafruitnrf52 package. However when looking at https://github.com/RAKWireless/RAK-nRF52-Arduino/tree/v1.3.3, they base their Arduino core off of the Adafruit nRF52 1.3.0 core with some patches. The latest nordicnrf52 platform installs the Adafruit core in version 1.5.0. So right there you’re getting a mismatch in intended base core version. In addition to that, the patches they make in their 1.3.3 version are not only adding their own variant folder, but modifying a few core files as well, and adding new libraires (like for I2S). Their patch file does not add that at all. So you end up with a weird frankenstein monster that’s not quite their core version but also not the Adafruit one.

In this case however, the most glaring omission in the PlatformIO build log is that the Adafruit TinyUSB Library is not mentioned and linked in at all, while in the Arduino build it is. Same for the bluefruit library. Omission of the TinyUSB library might have it fall back on hardware serial, since that is the library that creates the USB serial (CDC).

So let’s just do this the easy way: I’ve created a project that is completely self-contained (no need to for a patch installer that modifies PlatformIO packages). The board definition can live inside the project folder’s board folder, and the variant folder they want to use can also be put in the project folder and pointed to using the exactly therefore programmed board_build.variants_dir configuration option.

Can you just download and open this project in VSCode and upload it, see if it creates a serial port now?

And by the way if this works fine, then all you might need to do in your original project is to just add

#include <Adafruit_TinyUSB.h>

at the top of your code.

Hi Maximilian,

Thank you so much for that detailed dig into the issue!

I can confirm that the package you put together did indeed results in the COM port being visible there.

Adding the TinyUSB include unfortunately did not brjng back the comport


Mhh. Then the only essential remaining difference is that it’s using the newer platform + package version that is Adafruit-nrF52 core 1.5.0 based.

When you use this project but instead set

platform = nordicnrf52@10.1.0

instead, does it break the USB serial port functionality too?


With a Clean + Build @ 10.1.0, the port is still there


Well that’s suprising. Is the port still there when you use your original code in RAK19007+RAK4631, USB serial output - #3 by basrijn - WisBlock - RAKwireless Forum?


When I replace your code, with my test code from the RAK forum it fails to compile:

.pio\build\rak\src\main.cpp.o: In function setup': main.cpp:(.text.setup+0x1c): undefined reference to Adafruit_USBD_CDC::begin(unsigned long)’
main.cpp:(.text.setup+0x48): undefined reference to Adafruit_USBD_CDC::operator bool()' main.cpp:(.text.setup+0x54): undefined reference to Serial’

If I add back the Adafruit TinyUSB include, it compiles and the com port is still there


Okay not quite understanding that one, because if you used @10.1.0 and your original code, it should also compile normally as in your original project without modifications, but it doesn’t-- The current installed packages are probably in a weird state right now.

In any case, it is definitely more correct to use @9.6.0 setup project as I’ve posted above for now. There just needs to be official support for the forked RAK nRF52 core into Pull requests · platformio/platform-nordicnrf52 · GitHub, but noone’s done that yet. I’m definitely seeing an attempt at that in this commit, but it doesn’t seem they followed all they way through with a forked platform and PR. I think that should be relatively easy to do though, so let me put some stones into motion…

1 Like

I’ve opened a PR, the ball is now in PlatformIO’s court.

I proclaim that using this PR is the best way to do RAK4631 development in PlatformIO, because it properly uses their RAK core in it’s completeness. You have everything 1:1 available as you do in the Arduino IDE (and not missing out on core file changes or missing libraries etc.)

1 Like


Thank you so much for putting that PR together. Will pass the information to the RAK forum!

I will do some testing with the approach you described.