Running code on nrf52840-DK fails after flashing without bootloader

Hey everyone,

I am a bit stuck and after countless (partly aimless) attempts, I think I'm in need of (non-AI) help. This is the first time that I am trying to flash via a debugger and it's a bit overwhelming...

Ultimately, I wanna flash an external SoC, specifically the FSC-BT634 module with the nRF52840. As the module doesn't expose USB, I have to flash my code without using the bootloader. In order to make sure everything works, I wanna try the same using the onboard SoC of the nRF52840-DK. To this end, I installed the Adafruit nRF52 boards and select the Nordic nRF52840 DK as my board. I tried flashing via Arduino IDE, but I simply cannot get it to work (*), so I need to flash it manually. Long story short, after fixing some other bugs, I managed to export the compiled binary and here's what I do:

nrfjprog --eraseall
nrfjprog --eraseall --program compiled_hex.hex --verify --reset -f nrf52

After that, I restart the board, but nothing happens. I tried setting other Pins High or Low, but nothing happens when I measure voltage at those Pins.

After some back and fourth with ChatGPT, I assumed that perhaps the .hex file I get from Arduino assumes that the Softdevice is flashed first. So I also tried

nrfjprog --eraseall
nrfjprog --eraseall --program s140_nrf52_6.1.1_softdevice.hex --verify --reset -f nrf52
nrfjprog --eraseall --program compiled_hex.hex --verify --reset -f nrf52

Again, flashing works, but nothing happens afterwards and it seems the program is simply not running.

Does anyone have an idea what I have to do in order to get this to work?

Thanks a lot for any help!

(*) First, I got errors related to adafruit-nrfutils. After I have replaced the file with one I downloaded from the web, this worked, but I now I get JLink-related errors when chosing "Upload with Programmer" ("ERROR: JLinkARM DLL load failed. Try again. If it keeps failing, please").

You are just 'shotgunning'. You need to use correct terminology, and you need to have at least a basic understanding of what you want to do. Given your random messing with pins, toss those boards in the bin unless you can upload a test sketch to prove they are ok.

I am sorry, I wrote the message in a bit of a rush yesterday and upon reading it a second time, I realized I forgot to add an important detail: I am simply trying to run the basic blink example.

The sketch runs fine if I follow the standard approach: first flashing the bootloader, then compiling and uploading the sketch through the Arduino IDE. However, my goal is to upload the sketch via SWD without flashing a bootloader first.

Uploading from the Arduino IDE fails—initially due to an adafruit-nrfutil error, and later due to a J-Link-related issue. So I switched to using the command line: I compile the sketch in the Arduino IDE, export the .hex file, and then flash it using nrfjprog. That part works technically, but after flashing, none of the onboard LEDs blink.

I wasn’t just "randomly messing with pins"—I merely tested the four onboard LEDs as defined in my dev kit's pin mappings. Since none of them responded, I assume the code isn't running at all. And I am wondering why the sketch wouldn't run when flashed via SWD, even though the same sketch works when a bootloader is present?

It is true that, as a beginner, I do lack the "correct terminology". I assume it also took you a while to get acquainted with it.

Indeed it did take a while to learn new terms, and I still struggle even after 66 years.
My standard approach is to just do an upload.
Since I have never 'flashed' a bootloader and have no idea what SWD is I will sit and watch your progress so I might continue to learn.
Good luck.