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.

Parents
  • Hi,

     

    1. How can I get ninja flash to work?

    On the thingy:91, there's no dedicated reset line, so try to erase the chip first:

    nrfjprog -e && ninja flash

     Could you see if this works?

     

    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?

    I do not have much experience with qtcreator, but here's how I start up a debug session.

    Try starting the server with:

    JLinkGDBServer -if SWD -device nrf9160

     Then enter debug mode, with the following:

    arm-none-eabi-gdb /path/to/.elf
    target remote localhost:2331
    load
    mon reset
    c
    

     

    Kind regards,

    Håkon

     

  • The GDB stuff works like a charm!

    But the flashing fails, "nrfjprog -e && ninja flash" perhaps not surprisingly produces the same output and failure as before when I just did "ninja flash".

  • Aha, the nrfjprog -e runs succesfully, it's the subsequent "ninja flash" that fails to flash the merged.hex

  • I am attaching the last couple of lines of log.log generated by "nrfjprog --log --program /home/arvid/ncs/nrf/applications/asset_tracker/build-20035ns/zephyr/merged.hex -f NRF91 --snr 50123109 --sectorerase"

    The whole log.log file was too big to attach

    2019-Sep-06 16:34:59  nRF_write
    2019-Sep-06 16:34:59  . nRF91_write
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_emu
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_emu:	JLink INFO	JLINK_IsOpen()
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_emu:	JLink INFO	  returns 0x01
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_emu:	JLink INFO	 (0000ms, 3381ms total)  
    2019-Sep-06 16:34:59  . . nRF91_readback_status
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register
    2019-Sep-06 16:34:59  . . . . nRF91_is_debug_region_powered
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0000ms, 3381ms total)  
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x01)
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 -- Value=0xF0000040
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0001ms, 3382ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x04000000)
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 (0000ms, 3382ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(AP reg 0x03)
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 -- Value=0x00000003
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 (0001ms, 3383ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register
    2019-Sep-06 16:34:59  . . . . nRF91_is_debug_region_powered
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0000ms, 3383ms total)  
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x01)
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 -- Value=0xF0000040
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0000ms, 3384ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x04000010)
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 (0000ms, 3384ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(AP reg 0x02)
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 -- Value=0x00000001
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . nRF91_read_access_port_register:	JLink INFO	 (0001ms, 3385ms total)  
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_device
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_device:	JLink INFO	JLINK_IsConnected()
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_device:	JLink INFO	  returns TRUE
    2019-Sep-06 16:34:59  . . nRF91_is_connected_to_device:	JLink INFO	 (0000ms, 3385ms total)  
    2019-Sep-06 16:34:59  . . nRF91_halt
    2019-Sep-06 16:34:59  . . nRF91_halt:	JLink INFO	JLINK_Halt()
    2019-Sep-06 16:34:59  . . nRF91_halt:	JLink INFO	  returns 0x00
    2019-Sep-06 16:34:59  . . nRF91_halt:	JLink INFO	 (0000ms, 3385ms total)  
    2019-Sep-06 16:34:59  . . nRF91_nvmc_config_control
    2019-Sep-06 16:34:59  . . . nRF91_is_secure_debug_available
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register
    2019-Sep-06 16:34:59  . . . . . nRF91_is_debug_region_powered
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0000ms, 3385ms total)  
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(DP reg 0x01)
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	 -- Value=0xF0000040
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . . . nRF91_read_debug_port_register:	JLink INFO	 (0001ms, 3386ms total)  
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_WriteAPDPReg(DP reg 0x02, 0x00000000)
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	 (0000ms, 3386ms total)  
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	JLINK_CORESIGHT_ReadAPDPReg(AP reg 0x00)
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	 -- Value=0x03800052
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . . nRF91_read_access_port_register:	JLink INFO	 (0001ms, 3387ms total)  
    2019-Sep-06 16:34:59  . . nRF91_nvmc_config_control:	JLink INFO	JLINK_WriteU32(0x50039504, 0x00000001)
    2019-Sep-06 16:34:59  . . nRF91_nvmc_config_control:	JLink INFO	 -- CPU_WriteMem(4 bytes @ 0x50039504)
    2019-Sep-06 16:34:59  . . nRF91_nvmc_config_control:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . nRF91_nvmc_config_control:	JLink INFO	 (0000ms, 3387ms total)  
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	JLINK_ExecCommand("InvalidateCache", ...). 
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	  returns 0x00
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	 (0000ms, 3387ms total)  
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	JLINK_ReadMemU32(0x50039400, 0x0001 Items, ...)
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	 -- CPU_ReadMem(4 bytes @ 0x50039400)
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	 - Data: 01 00 00 00
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	  returns 1
    2019-Sep-06 16:34:59  . . nRF91_nvmc_wait_for_ready:	JLink INFO	 (0000ms, 3387ms total)  
    2019-Sep-06 16:34:59  . nRF91_write:	JLink INFO	JLINK_WriteMem(0x0000C000, 0x3FC0C Bytes, ...)
    2019-Sep-06 16:34:59  . nRF91_write:	JLink INFO	 - Data: D0 D2 02 20 41 54 01 00 97 A8 03 00 C5 52 01 00 ...
    2019-Sep-06 16:34:59  . nRF91_write:	JLink INFO	 -- CPU_WriteMem(261132 bytes @ 0x0000C000)
    2019-Sep-06 16:34:59  . nRF91_write:	JLink INFO	  returns 0xFFFFFFFF
    2019-Sep-06 16:34:59  . nRF91_write:	JLink INFO	 (0006ms, 3393ms total)  
    2019-Sep-06 16:34:59  . nRF91_write:	JLinkARM.dll WriteMem returned error -1.
    
    2019-Sep-06 16:34:59  nRF_close_dll
    2019-Sep-06 16:34:59  . nRF91_close_dll
    2019-Sep-06 16:34:59  . . nRF91_disconnect_from_emu
    2019-Sep-06 16:34:59  . . . nRF91_is_connected_to_emu
    2019-Sep-06 16:34:59  . . . nRF91_is_connected_to_emu:	JLink INFO	JLINK_IsOpen()
    2019-Sep-06 16:34:59  . . . nRF91_is_connected_to_emu:	JLink INFO	  returns 0x01
    2019-Sep-06 16:34:59  . . . nRF91_is_connected_to_emu:	JLink INFO	 (0000ms, 3393ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu
    2019-Sep-06 16:34:59  . . . . nRF91_is_connected_to_device
    2019-Sep-06 16:34:59  . . . . nRF91_is_connected_to_device:	JLink INFO	JLINK_IsConnected()
    2019-Sep-06 16:34:59  . . . . nRF91_is_connected_to_device:	JLink INFO	  returns TRUE
    2019-Sep-06 16:34:59  . . . . nRF91_is_connected_to_device:	JLink INFO	 (0000ms, 3393ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	Disable trace before closing connection.
    
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	JLink INFO	JLINK_WriteU32(0xE000EDFC, 0x00000000)
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	JLink INFO	 -- CPU_WriteMem(4 bytes @ 0xE000EDFC)
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	JLink INFO	  returns 0
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	JLink INFO	 (0000ms, 3393ms total)  
    2019-Sep-06 16:34:59  . . . nRF91_disconnect_from_emu:	JLink INFO	JLINK_Close()
    2019-Sep-06 16:34:59  . nRF91_close_dll:	Freeing Library.
    
    2019-Sep-06 16:34:59  nRF_close_dll:	Freeing Library.
    

  • 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

Reply Children
No Data
Related