Flashing firmware on nRF52840 DK with platformio IDE

Hi,
I’m currently using Adafruit BSP Arduino core to test on a nRF52840 DK board with platformio IDE. I follow these steps to flash a program onto the board -

1: Using the J-Link USB port on the board

  1. Erase the memory using the “Programmer” app in the “nRF connect for Desktop” suite.
  2. Burn the Adafruit BSP bootloader onto the board using platformio IDE(or arduino IDE, both work)
  3. Upload the code using platformio IDE.

2: Switch to the nRF USB serial port on the board

  1. Run the serial monitor to look at the debug logs

This procedure works. However, I find that every time after flashing a new program, my device can’t detect the serial port anymore to see the debug logs and I suspect the new program doesn’t run either from the looks of LEDs not flashing. Currently, I have to restart the whole procedure from erasing the memory again to make it work again.

I don’t think it should be this difficult. Is there a more convenient way to prototype on a nRF52840 DK board? Maybe just doing everything from platformio IDE? Thanks loads.

UPDATE:
I believe what I’m looking for is a way to upload the firmware via DFU upload method in platformIO IDE.

I’ve tried uploading the code in arduino IDE using the DFU upload method chosen under “Programmer” tab. It uploads successfully without having to burn bootloader again.

Just some more findings: I think the memory is corrupted the second time I flash a program using platformIO IDE. I can see it from the “Programmer” app in “nRF connect for Desktop” suite, that the MBR and Bootloader have disappeared after second flash.

Can you share your platformio.ini? Is it configured for nrf DK board or adafruit
?

I think that the nrf DK board configuration assumes no bootloader and program that starts at address 0.

[env:nrf52840_dk_adafruit]
platform = nordicnrf52
board = nrf52840_dk_adafruit
framework = arduino
monitor_speed = 115200
lib_deps = 
    adafruit/Adafruit MAX31865 library@^1.3.0
    adafruit/Adafruit BusIO@^1.11.2

Im using nrf52840_dk_adafruit.

I think there is platformio support for your specific Nordic DK board. That is not adafruit related. Do you use instead the adafruit configuration for a reason?

I use Adafruit config for the Bluefruit BLE library. The BLE library called “BLEperipheral” found here that is used inside the sample that PlatfromIO provides in the documentation doesn’t work properly. Are we able to use Bluefruit library without Adafruit core?

I am not sure how similar are the Adafruit and Nordic boards, from firmware perspective. One has USB to serial and the other has some Segger debugger adapter.

I am on a similar path, starting a project on nrf52 and decided to with the configuration below, because it’s also provides the Nordic SDK API (hal and nrfx) and support bare boards with no USB/Serial. I am using Segger Edu Mini for upload and debugging. YMMV.

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = zephyr

@zapta changing board to “nrf52_dk” doesn’t work for me since I want to use the Bluefruit BLE library that only works for adafruit core. Do you know any BLE library that will work on nordic52_dk with arduino framework?