Custom nRF52832 board pinout

Hey man, thanks for the extensive explanation! I think I got i right:
I copied the board file I based my design on (nrf52_dk.json) into the “boards” folder of my PIO project. In it, I added a specific variant of the board, and specified “variants_dir” and as “variants” which is the folder I also created in the PIO project. In “variants” I created my custom board name folder and copied .cpp and .h files from the original variant. To wrap it up, the folder structure looks somewhat like this:

  - custom_board.json  // here is the "variant" = "my_variant", and "variant_dir" = "variants"

 - my_variant
     - pins_arduino.h
     - variant.h
     - variant.cpp

If I may add, it is also necessary to include variants folder in the build process by adding
build_flags = -I variants/my_variant into the platformio.ini

So, the compilation itself runs just fine, everything seems to be compiled nicely, but the build process ends in error. For some reason linker script fails, and it doesn’t display any error. Any idea what might be behind that?

Well, this is the bit I had hopped you would not have to go through.

You will probably need to run the “pio” build command from a command line (from powershell if you’re using PlatformIO from within Visual Studio Code), adding -v at the end to get a verbose output.

There should be some error message in there somewhere.

If it’s not self explanatory you’ll have to look around in the PlatformIO documentation for that platform to see if there are instructions there for adding custom board variants - you see the build process in PlatformIO is implemented inside each platform directory so it will not be the same for the one I made my own project for (samd) as it if for yours.

If you can’t fix the build from what’s in the verbose build output alone or the documentation for your platform, then you’ll have to look at the python build code for that platform, which should be under the “builder” subdirectory of that platform’s directory, I believe inside

In this I can’t really help you as I have no experience with those chips and that platform.

1 Like

Hey, thanks for still sticking around, trying to help!
I tried building in the command line shell. Unfortunately, and funny enough, error messages and no explanations still popping up.

What is funny, is that when I check my installled boards (pio boards --installed) I get to see my custom board in all of the platforms: in nordicnrf52, espressif8266, atmelavr and native. All these platforms for some reason list my custom board in there.

EDIT: Hey, I think I got it! Well, it seems that platformio prefers to have its variants in the original folder, that is C:\Users<user>.platformio\packages/… Only when I moved my “my_variant” folder there, did it finish the build without errors! Any thoughts why is that so?
BTW, the platformio docs about system directories mentions nothing about “variants_dir” that you used in your board.json file. How did you make it to search in your project directory?

Support of the board_build.variants_dir is builder-script dependent.

The builder scripts for NordicNRF52 + Arduino do not allow changing the variant directory. It is constantly pointed to the actual framework package’s variants directory.

This is in contrast to Atmel SAM + Arduino where build.variants_dir is used

And hence you observe that difference.

An issue about this has been opened in Support build.variants_dir · Issue #11 · platformio/builder-framework-arduino-nrf5 · GitHub.

Hey, thanks for clarification, and opening the issue!

Out of the curiosity, what is going to happen now? Is someone going to fix the issue?
Is it going to be eventaully updated in new PIO version, or something?

Genuinely asking, since I’ve no clue how big software projects like Platformio flow…

Well generally when issues are opened it should get fixed – the small change the issue is about should be trivial.

When GitHub - platformio/builder-framework-arduino-nrf5: Arduino (Nordic nRF5) build script for PlatformIO Build System is fixed, GitHub - platformio/platform-nordicnrf52: Nordic nRF52: development platform for PlatformIO will be updated to point at the new version of the first repo (see arduino @ ...). As soon as that is done users can already use the upstream version to get the feature.

Then some time later a new platform-nordicnrf52 release will be made (new stable version") which users can update to as normal through the PlatformIO Home → Platforms → Updates GUI or the CLI with pio platform update nordicnrf52.

1 Like

cool! thanks for the explanation.
Have a great day!

In fact I’ve opened PR Expand builder scripts to use build.variants_dir by maxgerhardt · Pull Request #12 · platformio/builder-framework-arduino-nrf5 · GitHub in an attempt to solve the problem.

Can you do the following:

  1. Edit your platformio.ini in regards to the platform = .. value to
platform =
  1. Add the instruction
board_build.variants_dir = custom_variants

to your platformio.ini.

  1. In your local project directory, create the folder custom_variants. In this folder, move your created board variant folder (my_variant) that is currently in the PlatformIO Arduino core package. Move your old my_variant folder from the core package to somewhere else (so that it definitely fails if it does not use your local variant)
  2. Attempt compilation.

EDIT: Had to correct a Python error, use CLIpio platform update nordicnrf52 to update again.

The PR has already been merged so

platform =
; other options...
board_build.variants_dir = custom_variants

can already be used.

1 Like

Hey man, thanks for the effort. I tried what you said, and I am happy to confirm it worked like a charm. I have the variants defined only in my project directory, not in core_dir anymore. My platformio.ini is modified as you advised, and build finished with no errors. So, good job, my friend!

Question: I have “variants_dir” defined in my json manifest and in my platformio.ini. What to make of it? Is it redundant to have defined in both places?

EDIT: I have also tried with platform = nordicnrf52 instead of this long github link, and it also worked just fine. Ofc, I did that pio platform update command beforehand.

Hm this is probably working by-accident because GitHub - platformio/platform-nordicnrf52: Nordic nRF52: development platform for PlatformIO has not made a new stable release yet. Likely it’s using the git version obtained earlier. For now, platform = is the correct, portable way, until you see a new release after 9.0.0 at here.

The variants_dir is only valid / respected in the platformio.ini, not in the board’s JSON manifest. In the JSON manifest, the variant field is important.

Great to hear it works.

Good to see that it all ended well :fu:

Hello again,

unfortunately, I have to open the case one more time. Actually, I moved my framework from sandeepmistry’s to Adafruit’s following our discussion here, and this advices didn’t work anymore.

The build scripts do not recognize my custom board that is set according to the instructions here. (json manifest in the /boards, variants h/.cpp in the variants/my_variants directory).
The compilation only works with the native Adafruit board like adafruit_feather_nrf52832, and I changed my json and variant files according to it. Not even putting those into the PIO core directory make it work.

All of the errors I get in the build process are related to the Adafruit TinyUSB library, like this one:

C:\users\krivi\.platformio\packages\framework-arduinoadafruitnrf52\libraries\Adafruit_TinyUSB_Arduino\src\arduino/Adafruit_USBD_CDC.h:90:26: error: conflicting declaration 'Adafruit_USBD_CDC Serial'

Got any advice on how to solve this?

This should be the way to go, does it not run / upload if you treat your board as a adafruit_feather_nrf52832?

yes it, does, but we’re discussing custom boards here, and when I put time in the platformio.ini, it doesnt work anymore.

Please show the complete board JSON file, platformio.ini and code with which you’re testing.

It looks the same as the adafruit feather nrf52832 one, but no need to look at it, only the “variant” and “name” have been changed into “my_board”.

I am onto something. Look, has this interesting piece of code:

if isdir(usb_path):
if env.subst("$BOARD") != "adafruit_feather_nrf52832" :

so it adds something with TINYUSB if the board is NOT adafruit feather nrf52832. Now, if I include my board into this logic expression in the if statement:

if env.subst("$BOARD") != "adafruit_feather_nrf52832" and env.subst("$BOARD") != "my_board"

it treats it the same way as adafruit feather one and the issue gets doesn’t appear anymore. Could this be a good way to go?

Looks like I have to resurrect this thread…

I have tried, to the best of my abilities (which doesn’t necessarily say much… :slight_smile: ), to follow the suggestions in this thread, but I’m stuck with a different problem.

I’m using a custom board with a Rigado BMD-300 module, based on nRF52832, and I have looked at several different nRF52832-based boards’ JSON-files to cook up a suitable JSON-file for my board, but when I try to build, I get the error message: "Error: Could not load broken JSON ". I have tried to put the JSON-file and the accommodating and pins_arduino.h in the appropriate folders both in my project directory and in the C:\Users<etc,etc>\framework-arduinonordicnrf5 folder, without any luck.

My platformio.ini

platform		= nordicnrf52
board			= MyBoardNRF5
framework		= arduino
board_build.mcu = nrf52832
monitor_speed	= 115200
monitor_port	= COM10
upload_protocol	= blackmagic

build_flags = 
	-I variants/MyBoardNRF5
lib_deps = 
	adafruit/Adafruit BME280 Library@^2.2.2

My MyBoardNRF5.json:

  "build": {
    "arduino": {
        "ldscript": "nrf52_xxaa.ld"
    "core": "nRF5",
    "cpu": "cortex-m4",
    "f_cpu": "64000000L",
    "mcu": "nrf52832",
    "variant": "MyBoardNRF5",
    "variants_dir" : "variants"
  "debug": {
    "jlink_device": "nRF52832_xxAA",
    "openocd_chipname": "nrf52832",
    "openocd_target": "nrf52832",
    "svd_path": "nrf52.svd",
  "frameworks": [
  "name": "MyBoardNRF5",
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 524288,
	"require_upload_port": true,
	"speed": 115200,
    "protocol": "jlink",
    "protocols": [
  "url": "",
  "vendor": "Generic"

Anyone able to spot where I’ve goofed up?
PlatformIO is 6.1.6a4, running in VS Code 1.74.2

Edit: I don’t know if “nrf52_xxaa.ld” and “nrf52.svd” needs to be put somewhere or if they are loaded from somewhere automatically? If it is not done automatically, where can I find them and where should they be put?

The JSON file is syntactically broken, you put a comma after an attribute value but no new attribute followed (svd_path).

Using with “FIx JSON” unticked will tell you the same.

Hi, maxgerhardt.

Thanks! It’s the small details that trip you up… :laughing:
Didn’t know about the JSON checker site. Seems handy. Thanks again.