This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Flashing Thingy:91 nrf9160 using nrfConnect Programmer works, but ninja flash and west flash fails. Also how do I get gdb to flash when connecting to JLink gdbserver

Since nrfConnect Programmer, ninja flash/west flash ALL use nrfjprog behind the scenes, I wish I could find out _exactly_ which nrfjprog commands the nrfConnect Programmer is using!

I am trying to flash the nrf/applications/asset_tracker built for nrf9160_pca20035ns. cmake and ninja build works perfectly, but ninja flash fails. Using the nrfConnect Programmer to flash merged.hex works perfectly. I am on master branch on Ubuntu Linux 18.04.

1. How can I get ninja flash to work?

2. How can I get gdb-arm-none-eabi to flash as part of the init when I connect to the JLink gdbserver? So I get the latest version flashed on there when I connect to jlink gdbserver?

This is my gdb init, "load" appears not to be working (stolen from  https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/nrf52-debugging-with-qtcreator-on-windows ) :

set remote hardware-breakpoint-limit 6
set remote hardware-watchpoint-limit 4

monitor semihosting enable

load

monitor reset 0

Step 1 would be more convenient than using the gui programmer. Step 2 would be more convenient than step 1.

Here is the output of ninja flash:

arvid@arvid-HP-EliteBook-850-G3:~/ncs/nrf/applications/asset_tracker/build-20035ns$ ninja flash
[0/1] Flashing nrf9160_pca20035ns
-- west flash: using runner nrfjprog
-- runners.nrfjprog: Flashing file: /home/arvid/ncs/nrf/applications/asset_tracker/build-20035ns/zephyr/merged.hex
Parsing hex file.
Erasing page at address 0x0.
Erasing page at address 0x1000.
Erasing page at address 0x2000.
Erasing page at address 0x3000.
Erasing page at address 0x4000.
Erasing page at address 0x5000.
Erasing page at address 0x6000.
Erasing page at address 0x7000.
Erasing page at address 0xC000.
Erasing page at address 0xD000.
Erasing page at address 0xE000.
Erasing page at address 0xF000.
Erasing page at address 0x10000.
Erasing page at address 0x11000.
Erasing page at address 0x12000.
Erasing page at address 0x13000.
Erasing page at address 0x14000.
Erasing page at address 0x15000.
Erasing page at address 0x16000.
Erasing page at address 0x17000.
Erasing page at address 0x18000.
Erasing page at address 0x19000.
Erasing page at address 0x1A000.
Erasing page at address 0x1B000.
Erasing page at address 0x1C000.
Erasing page at address 0x1D000.
Erasing page at address 0x1E000.
Erasing page at address 0x1F000.
Erasing page at address 0x20000.
Erasing page at address 0x21000.
Erasing page at address 0x22000.
Erasing page at address 0x23000.
Erasing page at address 0x24000.
Erasing page at address 0x25000.
Erasing page at address 0x26000.
Erasing page at address 0x27000.
Erasing page at address 0x28000.
Erasing page at address 0x29000.
Erasing page at address 0x2A000.
Erasing page at address 0x2B000.
Erasing page at address 0x2C000.
Erasing page at address 0x2D000.
Erasing page at address 0x2E000.
Erasing page at address 0x2F000.
Erasing page at address 0x30000.
Erasing page at address 0x31000.
Erasing page at address 0x32000.
Erasing page at address 0x33000.
Erasing page at address 0x34000.
Erasing page at address 0x35000.
Erasing page at address 0x36000.
Erasing page at address 0x37000.
Erasing page at address 0x38000.
Erasing page at address 0x39000.
Erasing page at address 0x3A000.
Erasing page at address 0x3B000.
Erasing page at address 0x3C000.
Erasing page at address 0x3D000.
Erasing page at address 0x3E000.
Erasing page at address 0x3F000.
Erasing page at address 0x40000.
Erasing page at address 0x41000.
Erasing page at address 0x42000.
Erasing page at address 0x43000.
Applying system reset.
Checking that the area to write is not protected.
Programming device.
ERROR: JLinkARM DLL reported an error. Try again. If error condition
ERROR: persists, run the same command again with argument --log, contact Nordic
ERROR: Semiconductor and provide the generated log.log file to them.
ERROR: command exited with status 33: nrfjprog --program /home/arvid/ncs/nrf/applications/asset_tracker/build-20035ns/zephyr/merged.hex -f NRF91 --snr 50123109 --sectorerase
FAILED: zephyr/cmake/flash/CMakeFiles/flash
cd /home/arvid/ncs/nrf/applications/asset_tracker/build-20035ns && /usr/bin/cmake -E env /home/arvid/.local/bin/west flash --skip-rebuild
ninja: build stopped: subcommand failed.

  • On closer inspection, "load" from gdb does not work - I changed the code, rebuilt, and the "load" command in my gdb init was not effective. The old binary was being debugged using the new elf file, which was evident because new printouts I had added were not being printed, and stepping through the code produced unexpected results (i.e. gdb "n" not going to next line, but completely different source code). I had to go to the nRF Connect - Programmer and flash the new merged.hex. Restarted gdb server, reattached gdb, Then the new binary was being debugged using the new elf file, because "n" was again working as expected, and the new printouts I added show up.

  • Hi,

     

    I was able to reproduce the behavior you are seeing, especially when programming larger binaries.

    Could you try this:

    1. Call "nrfjprog -e" to erase the nRF9160 chip.

    2. Power cycle the thingy:91

    3. Program it either in gdb/IDE or using "nrfjprog --program <hex> --verify -f nrf91"

     

    And see if you are able to successfully program? This worked on my end.

    I am very sorry for this issue, and I can assure you that we are working on fixing this inconvenience.

     

    Kind regards,

    Håkon

  • Thank you Håkon, I was talking to a colleague at lunch and he told me the exact same steps: you need to erase and power cycle it before flashing =D

Related