Skip to main content

How to Use NX40 with PlatformIO

NX40 with PlatformIO: Build, Upload, and Monitor

Use PlatformIO IDE in Visual Studio Code to organize an Arduino-framework project for the KORLINX DEV-NX40 development board. Install the KORLINX board package, create an NX40 project, and upload a Blink application. Then use the optional USB Serial example to verify communication.

info

Package baseline This guide uses KORLINX-PlatformIO release 1.0.0, board ID nx40, and the Arduino framework. That release selects KORLINX Arduino core 1.0.2 and SoftDevice S140 6.1.1.

The repository reports tested USB upload. The supplied NX40-Bringup screenshots also show a successful USB Serial build, programming, and output. They do not show a physical Blink LED test; the documentation checks here do not constitute a separate hardware test.

Integrated-antenna and external-antenna versions of the NX40 Dev Kit

Use the NX40 configuration for your board revision and fitted module.

What you will build​

Prepare a PlatformIO project containing an Arduino application that blinks the NX40 red user LED every 500 ms. An optional second application checks native USB Serial output.

Before you begin​

Required hardware​

ItemRequirement
Development boardDEV-NX40 with the NX40-compatible bootloader required by the selected USB upload integration
USB cableData-capable USB Type-C cable
Host computerWindows, macOS, or Linux computer supported by the selected PlatformIO tools
Optional debug probeRequired for bootloader installation/recovery, or an explicitly configured SWD workflow

A bare NX40 module needs a carrier board providing power, programming access, and the required circuitry. Review the DEV-NX40 hardware guide before connecting external devices.

Required software​

PlatformIO Core is included with the VS Code extension; a separate Core installation is unnecessary for this IDE workflow. Follow PlatformIO's installation documentation for host-specific requirements.

Step 1: Install PlatformIO IDE​

  1. Install Visual Studio Code.
  2. Open Extensions in the Activity Bar.
  3. Search for the official PlatformIO IDE extension and install it.
  4. Wait for initialization to finish; reload VS Code if requested.
  5. Open PlatformIO Home.
  6. Open a PlatformIO terminal and check the included Core:
pio --version

Follow the official installation guide if initialization fails.

Official PlatformIO IDE extension installed in VS Code

The Disable and Uninstall controls indicate that PlatformIO IDE is already installed.

Step 2: Install the KORLINX PlatformIO package​

Open the PlatformIO terminal in VS Code and install the tagged platform:

pio pkg install -g -p https://github.com/KORLINX/KORLINX-PlatformIO.git#1.0.0

Wait for installation to complete. This installs the KORLINX development platform globally, including the NX40 board definition. Framework and tool dependencies are resolved as needed for the selected project.

The repository's examples use platform = korlinx after this global installation. The project configuration below instead pins the repository tag so the platform version is explicit.

SettingRelease 1.0.0 value
Platform packagekorlinx
Board IDnx40
Display nameKORLINX NX40 nRF52840
Frameworkarduino
Arduino coreKORLINX nRF52 core 1.0.2
Default upload protocolnrfutil (USB serial DFU)

These settings come from the release's platform manifest and NX40 board manifest. The Arduino FQBN korlinx:nrf52:nx40 is not the PlatformIO board ID.

Step 3: Prepare an NX40 project​

  1. Open PlatformIO Home > New Project.
  2. Name the project nx40_blink.
  3. Select KORLINX NX40 nRF52840 and the Arduino framework.
  4. Select a project location and finish creation.
  5. Replace the generated configuration with the pinned configuration in Step 4.

If the newly installed board does not appear, reload VS Code. You can also create a project folder manually with platformio.ini and src/main.cpp, then open that folder in VS Code. The configuration in Step 4 resolves the platform without selecting a different manufacturer's board in the wizard.

To use the repository's examples instead, clone the matching release and open its Blink project:

git clone --branch 1.0.0 --depth 1 https://github.com/KORLINX/KORLINX-PlatformIO.git

Open KORLINX-PlatformIO/examples/arduino-blink in VS Code. Its platform = korlinx configuration uses the package installed in Step 2.

Project itemPurpose
platformio.iniPlatform, board, framework, build, upload, and monitor settings
src/main.cppApplication source
include/Project headers
lib/Project-local libraries
boards/Optional project-local overrides; not needed for the supplied NX40 board
.pio/Generated build files and project dependencies

New Project action in PlatformIO Home

Open PlatformIO Home and select New Project.

NX40 Arduino project settings in the PlatformIO wizard

Select KORLINX NX40 nRF52840 and Arduino. The screenshot uses the project name NX40; nx40_blink is the name used in this guide.

Step 4: Configure platformio.ini​

Use this configuration for the NX40 Arduino project:

[platformio]
default_envs = nx40

[env:nx40]
platform = https://github.com/KORLINX/KORLINX-PlatformIO.git#1.0.0
board = nx40
framework = arduino
monitor_speed = 115200
monitor_dtr = 1

The platform supplies the framework package, NX40 variant, linker settings, and default USB uploader. No custom board JSON or platform_packages override is required for this baseline.

Keep the release tag pinned for repeatable builds. Updating the platform or framework should be an explicit project change followed by build and hardware verification.

The monitor_dtr = 1 setting asserts DTR when opening the project serial monitor, matching the USB Serial example below. See monitor_dtr.

Save the file and allow PlatformIO to resolve its dependencies. Confirm that the build configuration uses board nx40 before uploading.

PlatformIO configuration using platform korlinx and board nx40

The screenshot uses the globally installed korlinx platform. The configuration above pins release 1.0.0 and adds explicit monitor settings.

Open src/main.cpp and replace its contents with:

#include <Arduino.h>

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
digitalWrite(LED_BUILTIN, LED_STATE_ON);
delay(500);

digitalWrite(LED_BUILTIN, 1 - LED_STATE_ON);
delay(500);
}

PlatformIO compiles this as a C++ source file, so include Arduino.h explicitly. The code uses the NX40 BSP's LED alias and active-level definition. The KORLINX NX40 variant definitions map LED_BUILTIN through PIN_LED1 to pin 11 and define LED_STATE_ON as 0. Confirm the same variant is included in the selected PlatformIO framework package.

Step 6: Build the application​

  1. Select the nx40 environment.
  2. Run PlatformIO: Build, or use the PlatformIO terminal:
pio run -e nx40
  1. Wait for the build to complete successfully.
  2. Check that the log identifies KORLINX NX40 nRF52840 and the KORLINX Arduino framework.

Compilation confirms that the selected software configuration builds. LED behavior, USB enumeration, and bootloader compatibility require a hardware test.

Successful PlatformIO build of the NX40 USB Serial application

The supplied NX40-Bringup screenshot shows a successful USB Serial example build. Use the same Build task for the Blink application.

Step 7: Connect and upload​

The NX40 board manifest selects upload_protocol = nrfutil, enables a 1200-bps touch, and waits for the bootloader port. The repository documents automatic reset and USB serial DFU upload with the KORLINX bootloader.

  1. Connect DEV-NX40's native nRF52840 USB interface with a data-capable cable.
  2. List available serial devices:
pio device list
  1. Identify the NX40 native USB port. The FTDI bridge is a separate hardware UART interface.
  2. Close serial monitors that may hold the upload port open.
  3. In Project Tasks > nx40 > General, select Upload, or run:
pio run -e nx40 -t upload

-e nx40 selects [env:nx40] in platformio.ini; -t upload runs the upload target. PlatformIO builds the firmware as needed before uploading.

If automatic port selection is unsuitable, specify the actual port:

pio run -e nx40 -t upload --upload-port YOUR_NX40_PORT

Replace YOUR_NX40_PORT with the port reported by your computer. For normal automatic upload, use the application USB port. The uploader requests bootloader entry and waits for the upload port to reappear.

The KORLINX bootloader documentation documents double-pressing Reset within 500 ms, or holding SW2 while pressing Reset, to enter the bootloader. These are fallback bootloader-entry methods; a normal upload through this platform performs the reset automatically.

If the bootloader is missing, follow bootloader installation or recovery before USB upload. That procedure can erase existing firmware and stored data.

PlatformIO Upload task successfully programming NX40 over USB DFU

Select Upload to program NX40. The terminal shows the DFU transfer, Device programmed, and SUCCESS.

note

Alternative upload methods The repository also lists jlink, nrfjprog, and cmsis-dap upload paths, plus the bootloader target. It explicitly marks these paths as untested on NX40. This guide uses the documented USB workflow.

Step 8: Confirm the LED result​

After successful upload and reset, the expected application behavior is:

  • The red user LED turns on for approximately 500 ms.
  • It turns off for approximately 500 ms.
  • The cycle repeats continuously.

Check the user LED controlled by the application. Power or charging indicators alone do not verify Blink. If upload succeeds but the LED does not blink, review the NX40 variant, polarity, application flash layout, and board revision.

Optional: Verify USB Serial​

The KORLINX Arduino core requires Adafruit_TinyUSB.h for sketches that use native USB Serial. This header is included in the example below.

Replace src/main.cpp with:

#include <Arduino.h>
#include <Adafruit_TinyUSB.h>

void setup() {
Serial.begin(115200);
const uint32_t started = millis();
while (!Serial && millis() - started < 3000) {
delay(10);
}
}

void loop() {
if (Serial) {
Serial.println("KORLINX NX40 Arduino is running");
}
delay(1000);
}

NX40 USB Serial example in src main.cpp

USB Serial example in src/main.cpp. The listing above includes Arduino.h explicitly for a standalone C++ source file.

Build and upload again. After USB re-enumeration, select the application port and open PlatformIO: Serial Monitor with the nx40 environment and monitor_dtr = 1, or run:

pio device monitor --port YOUR_NX40_PORT --baud 115200 --dtr 1

The DTR option supports the sketch's Serial connection check. For the IDE workflow, set monitor_port to the application port if automatic selection chooses the FTDI bridge; this can differ from upload_port after bootloader re-enumeration. Expected output is approximately one line per second:

KORLINX NX40 Arduino is running

Serial uses native USB CDC in the documented NX40 Arduino workflow. Serial1 uses the hardware UART. Select the native USB application port for this example; its output will not appear on the FTDI UART port.

NX40 Upload and Monitor showing Device programmed and repeated USB Serial messages

The supplied capture shows successful programming and repeated USB Serial output using Upload and Monitor.

The capture shows the monitor at 9600 while the sketch requests 115200. This example uses native USB CDC rather than a physical UART; keep the explicit 115200 monitor setting in this guide. For hardware UART, the terminal baud rate must match the firmware. The port /dev/ttyACM0 shown is specific to that test computer.

NX40 code examples​

The examples directory provides the following projects with an nx40 environment using platform = korlinx, board = nx40, and framework = arduino.

ExampleWhat it demonstrates
arduino-blinkBlinks the built-in user LED
arduino-ledsCycles through the Dev Kit LEDs
arduino-fadeFades an LED with PWM
arduino-buttonReads the user button and controls an LED
arduino-analogReads the NX40 analog input aliases
arduino-serial-echoEchoes data received through the serial interface
arduino-imuReads acceleration and angular rate from the onboard IMU
arduino-shtc3Reads temperature and relative humidity from the onboard SHTC3
arduino-ble-uartProvides a Bluetooth LE UART-style service
arduino-usb-serialDemonstrates NX40 native USB serial communication

Clone the repository, then build and upload the required project with its nx40 environment:

git clone https://github.com/KORLINX/KORLINX-PlatformIO.git
cd KORLINX-PlatformIO
pio run -d examples/arduino-blink -e nx40
pio run -d examples/arduino-blink -e nx40 -t upload

Replace arduino-blink with another project name from the table.

Troubleshooting​

SymptomWhat to check
NX40 is absent from the project wizardInstall the KORLINX platform in Step 2 and reload VS Code, or create the project manually with the pinned configuration
Unknown board or package errorUse board ID nx40 and the tagged KORLINX platform URL; check Git and package-download errors
LED_STATE_ON is undefinedConfirm that the NX40 Arduino variant is selected
TinyUSB header is missingConfirm that the integration includes the BSP's required libraries and submodules
Linker or SoftDevice-related errorsCheck framework, compiler, linker script, and reserved memory compatibility
No upload portCheck the data cable, native USB routing, bootloader, drivers, and serial permissions
Upload fails after entering the bootloaderCheck the new port and the uploader's reset/port-discovery behavior
Uploader is missingInstall the dependency required by the approved integration; Arduino IDE tools may not be available to PlatformIO
Upload succeeds but no BlinkCheck the LED mapping, polarity, board revision, and image layout
Serial Monitor is blankSelect the application USB port, assert DTR, reopen after enumeration, and confirm USB CDC support

References​