Programming nRF52840 dongle (PCA10059) with PlatformIO and Arduino framework

Hi,

 

I am trying to program nRF52840 dongle (PCA10059) with PlatformIO and Arduino framework, but the program (see below) won’t start. I think it falls in the hard fault before setup() function is called.

#include <Arduino.h>

void setup() {
  pinMode(13, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(6, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(25, HIGH);
  digitalWrite(6, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  digitalWrite(25, LOW);
  digitalWrite(6, LOW);
  delay(1000);
}

This is what my configuration .ini file looks like:

platform = [email protected]
board = pca10059
framework = arduino
platform_packages = framework-arduinoadafruitnrf52@https://github.com/jpconstantineau/Community_nRF52_Arduino.git#0.1.21

extra_scripts = dfu_upload.py
upload_protocol = custom

; Select serial port, where nrf52840 dongle is connected
upload_port = COM3

Program is flashed using DFU bootloader (MCU has already nordic’s bootloader) and nrfutil. It is handled by custom upload script (which I found here and modified it):

import os
from os.path import basename
Import("env")

platform = env.PioPlatform()
upload_port = env.GetProjectOption("upload_port")

def dfu_upload(source, target, env):
    firmware_path = str(source[0])
    firmware_name = basename(firmware_path)

    genpkg = "".join(["nrfutil -v -v -v pkg generate --hw-version 52 --sd-req=0x00 --application ", firmware_path, " --application-version 1 firmware.zip"])
    dfupkg = "".join(["nrfutil -v -v -v dfu serial -pkg firmware.zip -p ", upload_port, " -b 115200"])
    print( genpkg )
    os.system( genpkg )
    os.system( dfupkg )

    print("Uploading done.")

# Custom upload command and program name
env.Replace(PROGNAME="firmware", UPLOADCMD=dfu_upload)

And this is what uploading looks like:

After uploading I have checked using nRFconnect tool, if program was flashed correctly. See that the program size is 39564 bytes and in the picture below, in nRF Connect Programmer tool you can see that there is loaded application with 39564 bytes, which means that program was flashed correctly, but the LED won’t blink.

So, I have tried to create new project, to check if it works under different framework, so I have chosen Zephyr with the given configuration:

platform = nordicnrf52
board = nrf52840_dk
framework = zephyr
board_build.zephyr.variant = nrf52840dongle_nrf52840
extra_scripts = dfu_upload.py
upload_protocol = custom

I used the same upload script as before, uploaded example blink sketch and it works. LED is blinking. Now you can ask, why are you bothering with Arduino framework, when nRF52840 can be easily programmed under Zephyr framework? The answer it, that I have to use Arduino framework, because I want to migrate an existing project from Arduino board. So the final question is, has anybody same problem as me and can it be fixed?

PS: I think, that problem may be in the linker script, startup assembly code or with default Nordic's bootloader.

Thank you all for the answers.

Parents Reply Children
No Data
Related