NRF52 zephyr - building for wrong board?

Hi,

I’m a bit stuck on an issue I’m having with building a project for a custom board.

I’m trying to get set up a project using Zephyr-RTOS to program an nrf52 based board I’ve designed. I started by copying the “blinky” example for the nrf52-dk and starting by renaming everything to the name of my project. I’ve also created a new board definition in C:\Users\me.platformio\packages\framework-zephyr\boards\arm. The project will simply be named “nixie_watch”.

I’m able to build the project successfully. The problem is that somewhere in the setup, it keeps using the devicetree (.dts) file from the nrf52-dk instead of the custom devicetree file I’m writing for the new board.

My platformio.ini project configuration has the nixie_watch board specified as per the following:

[env:nixie_watch]
platform = nordicnrf52
board = nixie_watch
framework = zephyr
debug_tool = jlink
upload_protocol = jlink

However, when I run menuconfig, I see the following output from the build system:

CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nixie_watch.html
PLATFORM: Nordic nRF52 (4.4.1) > Nordic nRF52-DK
HARDWARE: NRF52832 64MHz, 64KB RAM, 512KB Flash
DEBUG: Current (jlink) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES: … (long list)

[0/1] Re-running CMake…
– Application: C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/zephyr
– Zephyr version: 2.3.0 (C:/Users/me/.platformio/packages/framework-zephyr)
– Board: nrf52dk_nrf52832
– Found dtc: C:/Users/me/.platformio/packages/tool-dtc/dtc.exe (found suitable version “1.4.7”, minimum required is “1.4.6”)
Python path: C:/Users/me/.platformio/penv/Scripts/python.exe
– Found toolchain: gnuarmemb (C:/Users/me/.platformio/packages/toolchain-gccarmnoneeabi)
– Found BOARD.dts: C:/Users/me/.platformio/packages/framework-zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts

It is still building using the nrf52-dk platform and using the nrf52dk devicetree file.

Where should I be looking for a setting or configuration option to instead have it build and reference the board-specific files for my project “nixie_watch”?

I am not a professional software developer by any means. Nor do I have a formal education in any of this. If I made a noob mistake I apologize in advance!

So what’s the contents of your nixie_watch.json file?

There are 3 json files within the project root directory, under C:\Users\me\Documents\PlatformIO\Projects\nixie_watch.vscode

within the .vscode folder, the 3 json files are:
c_cpp_properties.json
extensions.json
launch.json

They contain the following:

c_cpp_properties.json: 
{
    "configurations": [
        {
            "name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
        },
        {
            "name": "Win32",
            "includePath": [
                "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/include",
                "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/src",
                "C:/Users/me/.platformio/packages/framework-zephyr/include",
                "C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated",
                "C:/Users/me/.platformio/packages/framework-zephyr/soc/arm/nordic_nrf/nrf52",
                "C:/Users/me/.platformio/packages/framework-zephyr-segger/rtt",
                "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx",
                "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx/drivers/include",
                "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx/mdk",
                "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic",
                "C:/Users/me/.platformio/packages/framework-zephyr-cmsis/CMSIS/Core/Include",
                "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated",
                "C:/Users/me/.platformio/packages/tool-unity",
                ""
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "path": [
                    "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/include",
                    "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/src",
                    "C:/Users/me/.platformio/packages/framework-zephyr/include",
                    "C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated",
                    "C:/Users/me/.platformio/packages/framework-zephyr/soc/arm/nordic_nrf/nrf52",
                    "C:/Users/me/.platformio/packages/framework-zephyr-segger/rtt",
                    "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx",
                    "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx/drivers/include",
                    "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic/nrfx/mdk",
                    "C:/Users/me/.platformio/packages/framework-zephyr-hal-nordic",
                    "C:/Users/me/.platformio/packages/framework-zephyr-cmsis/CMSIS/Core/Include",
                    "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated",
                    "C:/Users/me/.platformio/packages/tool-unity",
                    ""
                ]
            },
            "defines": [
                "PLATFORMIO=50001",
                "ARDUINO_NRF52_DK",
                "BUILD_VERSION=zephyr-v20300",
                "KERNEL",
                "NRF52832_XXAA",
                "_FORTIFY_SOURCE=2",
                "__PROGRAM_START",
                "__ZEPHYR__=1",
                ""
            ],
            "intelliSenseMode": "clang-x64",
            "cStandard": "c99",
            "forcedInclude": [
                "C:/Users/me/.platformio/packages/framework-zephyr/include/toolchain/zephyr_stdint.h",
                "C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated/autoconf.h",
                ""
            ],
            "compilerPath": "C:/Users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin/arm-none-eabi-gcc.exe",
            "compilerArgs": [
                "-mabi=aapcs",
                "-mcpu=cortex-m4",
                "-mthumb",
                "-isystem",
                "C:/Users/me/.platformio/packages/framework-zephyr/lib/libc/minimal/include",
                "-isystem",
                "c:/users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/include",
                "-isystem",
                "c:/users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/8.2.1/include-fixed",
                ""
            ]
        }
    ],
    "version": 4
}

extensions.json:

{

    // See http://go.microsoft.com/fwlink/?LinkId=827846

    // for the documentation about the extensions.json format

    "recommendations": [

        "platformio.platformio-ide"

    ]

}

launch.json:

// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY

// PIO Unified Debugger
//

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug",
            "executable": "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/firmware.elf",
            "toolchainBinDir": "C:/Users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin",
            "svdPath": "C:/Users/me/.platformio/platforms/nordicnrf52/misc/svd/nrf52.svd",
            "preLaunchTask": {
                "type": "PlatformIO",
                "task": "Pre-Debug"
            },
            "internalConsoleOptions": "openOnSessionStart"
        },
        {
            "type": "platformio-debug",
            "request": "launch",
            "name": "PIO Debug (skip Pre-Debug)",
            "executable": "c:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/firmware.elf",
            "toolchainBinDir": "C:/Users/me/.platformio/packages/toolchain-gccarmnoneeabi/bin",
            "svdPath": "C:/Users/me/.platformio/platforms/nordicnrf52/misc/svd/nrf52.svd",
            "internalConsoleOptions": "openOnSessionStart"
        }
    ]
}

As far as I can tell, there are no board specific lines that I need to change. I know I am missing something in the project overall that tells the build system to use one board and not the other, I’m just not sure where that is.

o_O Okay one step back to here. You’re declaring the PlatformIO board to be nixie_watch. So there has to be a nixie_watch.json board description for PlatformIO. It’s not in platform-nordicnrf52/boards at develop · platformio/platform-nordicnrf52 · GitHub. So it’s got to be in the boards/ folder of your project. But you don’t have any? (Documentation)

You may want to copy platform-nordicnrf52/boards/nrf52_dk.json at develop · platformio/platform-nordicnrf52 · GitHub as boards/nixie_watch.json and change the zephyr variant value as well as the name and other metadata.

1 Like

Ah okay thanks for pointing me in the right direction. I recall that I had indeed copied nrf52_dk.json and renamed it nixie_watch.json in platforms\nordicnrf52\boards

Here are the contents of nixie_watch.json as they are now (same as when I was building the project as first described):

    {
  "build": {
    "arduino":{
      "ldscript": "nrf52_xxaa.ld"
    },
    "core": "nRF5",
    "cpu": "cortex-m4",
    "extra_flags": "-DARDUINO_NRF52_DK",
    "f_cpu": "64000000L",
    "mcu": "nrf52832",
    "variant": "nRF52DK",
    "zephyr": {
       "variant": "nrf52_pca10040"
    }
  },
  "connectivity": [
    "bluetooth"
  ],
  "debug": {
    "default_tools": [
      "jlink"
    ],
    "jlink_device": "nRF52832_xxAA",
    "onboard_tools": [
      "cmsis-dap",
      "jlink"
    ],
    "svd_path": "nrf52.svd"
  },
  "frameworks": [
    "arduino",
    "mbed",
    "zephyr"
  ],
  "name": "Nordic nRF52-DK",
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 524288,
    "protocol": "jlink",
    "protocols": [
      "jlink",
      "nrfjprog",
      "stlink",
      "blackmagic",
      "cmsis-dap",
      "mbed"
    ]
  },
  "url": "https://developer.mbed.org/platforms/Nordic-nRF52-DK/",
  "vendor": "Nordic"
}

Now i see there are a few lines with “variant” which indicate both "“variant”: “nRF52DK” and “variant”: “nrf52_pca10040”, and “name”: “Nordic nRF52-DK”. Are these the lines I should focus on changing?

The first variant is the Arduino variant (irrelevant for your project), the second one is the Zephyr board variant name. That should be changed. As well as name if you want a nice display name. The MCU value of nrf52832 is still correct I assume?

1 Like

Thank you Max; I will give it a try tonight. That looks like it might do the trick.

Its been such a busy day I only had 5 minutes to go on my computer just now!

Finally got to sit down and work on this. Sorry; I didn’t answer your question in my last post. Yes, the mcu I’m using is the NRF52832-QFAA-R.

I changed the variant under zephyr to “nixie_watch”, which should correspond to the board specific files I have under “packages\framework-zephyr\boards\arm\nixie_watch”

The output from the build system has changed, but I still see that it is hung up on thinking that the project board is the nrf52dk, and it is still using the devicetree file for that board.

nixie_watch.json:

{
  "build": {
    "arduino":{
      "ldscript": "nrf52_xxaa.ld"
    },
    "core": "nRF5",
    "cpu": "cortex-m4",
    "extra_flags": "-DARDUINO_NRF52_DK",
    "f_cpu": "64000000L",
    "mcu": "nrf52832",
    "variant": "nRF52DK",
    "zephyr": {
       "variant": "nixie_watch"
    }
  },
  "connectivity": [
    "bluetooth"
  ],
  "debug": {
    "default_tools": [
      "jlink"
    ],
    "jlink_device": "nRF52832_xxAA",
    "onboard_tools": [
      "cmsis-dap",
      "jlink"
    ],
    "svd_path": "nrf52.svd"
  },
  "frameworks": [
    "arduino",
    "mbed",
    "zephyr"
  ],
  "name": "Neonkev Nixie Watch",
  "upload": {
    "maximum_ram_size": 65536,
    "maximum_size": 524288,
    "protocol": "jlink",
    "protocols": [
      "jlink",
      "nrfjprog",
      "stlink",
      "blackmagic",
      "cmsis-dap",
      "mbed"
    ]
  },
  "url": "/",
  "vendor": "Nordic"
}

build system output when running menuconfig:

    platformio.exe run --target menuconfig --environment nixie_watch <

Processing nixie_watch (platform: nordicnrf52; board: nixie_watch; framework: zephyr)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/nordicnrf52/nixie_watch.html
PLATFORM: Nordic nRF52 (4.4.1) > Neonkev Nixie Watch
HARDWARE: NRF52832 64MHz, 64KB RAM, 512KB Flash
DEBUG: Current (jlink) On-board (cmsis-dap, jlink) External (blackmagic, stlink)
PACKAGES:
 - framework-zephyr 2.20300.200823 (2.3.0)
 - framework-zephyr-canopennode 0.0.0-alpha+sha.5c6b0566d5
 - framework-zephyr-civetweb 0.0.0-alpha+sha.99129c5efc
 - framework-zephyr-cmsis 0.0.0-alpha+sha.542b2296e6
 - framework-zephyr-fatfs 0.0.0-alpha+sha.9ee6b9b951
 - framework-zephyr-hal-nordic 0.0.0-alpha+sha.742d8fb839
 - framework-zephyr-libmetal 0.0.0-alpha+sha.3c3c9ec83b
 - framework-zephyr-littlefs 0.0.0-alpha+sha.0aefdda69d
 - framework-zephyr-loramac-node 0.0.0-alpha+sha.29e516ec58
 - framework-zephyr-lvgl 0.0.0-alpha+sha.74fc2e753a
 - framework-zephyr-mbedtls 0.0.0-alpha+sha.4bf099f125
 - framework-zephyr-mcuboot 0.0.0-alpha+sha.e88113bbeb
 - framework-zephyr-mcumgr 0.0.0-alpha+sha.5885efb7ca
 - framework-zephyr-mipi-sys-t 0.0.0-alpha+sha.957d46bc3c
 - framework-zephyr-open-amp 0.0.0-alpha+sha.724f7e2a45
 - framework-zephyr-openthread 0.0.0-alpha+sha.a83d18cf18
 - framework-zephyr-segger 0.0.0-alpha+sha.6fcf61606d
 - framework-zephyr-tinycbor 0.0.0-alpha+sha.40daca97b4
 - framework-zephyr-tinycrypt 0.0.0-alpha+sha.3e9a49d267
 - framework-zephyr-trusted-firmware-m 0.0.0-alpha+sha.7de2daa196
 - tool-cmake 3.16.4
 - tool-dtc 1.4.7
 - tool-ninja 1.9.0
 - tool-sreccat 1.164.0 (1.64)
 - toolchain-gccarmnoneeabi 1.80201.190214 (8.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Running menuconfig...
[0/1] Re-running CMake...
-- Application: C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/zephyr
-- Zephyr version: 2.3.0 (C:/Users/me/.platformio/packages/framework-zephyr)
-- Board: nrf52dk_nrf52832
-- Found dtc: C:/Users/me/.platformio/packages/tool-dtc/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
Python path: C:/Users/me/.platformio/penv/Scripts/python.exe
-- Found toolchain: gnuarmemb (C:/Users/me/.platformio/packages/toolchain-gccarmnoneeabi)
-- Found BOARD.dts: C:/Users/me/.platformio/packages/framework-zephyr/boards/arm/nrf52dk_nrf52832/nrf52dk_nrf52832.dts
-- Generated zephyr.dts: C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/zephyr.dts
-- Generated devicetree_unfixed.h: C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated/devicetree_unfixed.h
Parsing C:/Users/me/.platformio/packages/framework-zephyr/Kconfig
Loaded configuration 'C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/.config'
No change to configuration in 'C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/.config'
No change to Kconfig header in 'C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch/zephyr/include/generated/autoconf.h'
-- Cache files will be written to: C:/Users/me/.platformio/packages/framework-zephyr/.cache
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/me/Documents/PlatformIO/Projects/nixie_watch/.pio/build/nixie_watch

So under the line “PLATFORM” it has changed to the “Neonkev Nixie Watch” that I changed in “nixie_watch.json”, but it still uses the nrf52dk_nrf52832 board. I confirmed this by adding a device defnition to nixie_watch.dts (the devicetree file) and then trying to use it in my main.c, which throws the error “#error directive: “Unsupported board: led0 devicetree alias is not defined””, meaning that my new device definition (led4) does not exist in the referenced devicetree file (nrf52dk devicetree only has devices for led0 thru led3).

Very odd. What else should I try to change? Is there a line I can add in nixie_watch.json to force it to use nixie_watch as the board?

This is still wrong. The PlatformIO build script (C:\Users\<user>\.platformio\packages\framework-zephyr\scripts\platformio\platformio-build.py) does

def get_zephyr_target(board_config):
    return board_config.get("build.zephyr.variant", env.subst("$BOARD").lower())

[..]
def run_cmake():
    print("Reading CMake configuration...")

    cmake_cmd = [
        os.path.join(platform.get_package_dir("tool-cmake") or "", "bin", "cmake"),
        "-S",
        os.path.join(PROJECT_DIR, "zephyr"),
        "-B",
        BUILD_DIR,
        "-G",
        "Ninja",
        "-DBOARD=%s" % get_zephyr_target(board),
        "-DPYTHON_EXECUTABLE:FILEPATH=%s" % env.subst("$PYTHONEXE"),
        "-DPYTHON_PREFER:FILEPATH=%s" % env.subst("$PYTHONEXE"),
        "-DPIO_PACKAGES_DIR:PATH=%s" % env.subst("$PROJECT_PACKAGES_DIR"),
    ]

So you should be getting nixie_watch as get_zephyr_target() output. It’s as if it still has the

zephyr variant name which is remapped to

I’ll have a look myself.

I’ve double checked and if I use that board JSON file it does give me the correct Zephyr variant name in the verbose output. Maybe you didn’t save the file? Anyways, I also had to add "cmake_extra_args": "-DOPENOCD_NRF5_SUBFAMILY=nrf52" in the JSON file to fix a Zephyr error where it couldn’t figure out the nRF family name from the variant name. Usually they’re named after e.g. nrf52_nixie_watch to auto-figure that out.

I’ve uploaded my project and instructions to GitHub - maxgerhardt/pio-zephyr-nixie-watch: Example of how to add a new Zephyr board to PlatformIO.

I’d suggest you remove the nixie_watch.json in your platform/nordicnrf52 folder (otherwise duplication from board/ folder of project) and try this project.

1 Like

Yeah and also incidentally, a tutorial was posted using the same nRF chip and Zephyr: Enabling PlatformIO and Zephyr on custom hardware :slight_smile:

I was able to finally get the project to build for the right board by following your example.

The solution looks like it involves these 2 key steps:

-adding a “boards” folder under the project root directory (C:\Users\me\Documents\PlatformIO\Projects\nixie_watch) containing the “nixie_watch.json” modified as we discussed.

-adding a “boards” folder under C:\Users\me\Documents\PlatformIO\Projects\nixie_watch\zephyr. The project then utilized the “nixie_watch.dts” devicetree under C:\Users\me\Documents\PlatformIO\Projects\nixie_watch\zephyr\boards\arm\nixie_watch as opposed to the .dts file I had originally placed in the C:\Users\me.platformio\packages\framework-zephyr

That tutorial you posted looks great. At least I can begin the long grind that will be the first rev of working firmware!