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
  • After some research I found a solution that might help someone. The program didn't run because I didn't have any SoftDevice loaded in flash memory and the framework I used expected it. Since my code doesn't need a SoftDevice, I modified the Adafruit platform (modified version) and package (modified version) for nRF5. I added a new PCA10059 board (pca10059NDFU) with SoftDevice disabled and a new programming method (nordic_nrfutil_boot) that uses the original nrfutil which supports the original DFU bootloader.

    To use a modified platform, your platformio.ini file must contain the following:

    [env:adafruit_nrf52840_dongle]
    ; Modified Adafruit's platform (which will also downloads the package).
    platform = https://gitlab.nsoric.com/mtf/mcu/nrf52/platform-nordicnrf52-add-on.git
    
    ; Modified PCA10059 board, which allows to use original nrfutil and DFU bootloader.
    ; Board has disabled SoftDevice.
    board = pca10059NDFU
    
    framework = arduino
    
    ; Original nrfutil, which will work with original DFU bootloader.
    upload_protocol = nordic_nrfutil_boot
    
    ; Select serial port, where nrf52840 dongle is connected
    upload_port = COM6

    Note: Some features (such as debugging) may not work with a modified board.

Reply
  • After some research I found a solution that might help someone. The program didn't run because I didn't have any SoftDevice loaded in flash memory and the framework I used expected it. Since my code doesn't need a SoftDevice, I modified the Adafruit platform (modified version) and package (modified version) for nRF5. I added a new PCA10059 board (pca10059NDFU) with SoftDevice disabled and a new programming method (nordic_nrfutil_boot) that uses the original nrfutil which supports the original DFU bootloader.

    To use a modified platform, your platformio.ini file must contain the following:

    [env:adafruit_nrf52840_dongle]
    ; Modified Adafruit's platform (which will also downloads the package).
    platform = https://gitlab.nsoric.com/mtf/mcu/nrf52/platform-nordicnrf52-add-on.git
    
    ; Modified PCA10059 board, which allows to use original nrfutil and DFU bootloader.
    ; Board has disabled SoftDevice.
    board = pca10059NDFU
    
    framework = arduino
    
    ; Original nrfutil, which will work with original DFU bootloader.
    upload_protocol = nordic_nrfutil_boot
    
    ; Select serial port, where nrf52840 dongle is connected
    upload_port = COM6

    Note: Some features (such as debugging) may not work with a modified board.

Children
No Data
Related