Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Upload hex-File with J-Flash and J-Link with/without Bootloader, application not starting

Hello,

I am having trouble understanding the flashing process of an nrf52840. I have programmed a simple flashing example with the nRF5 SDK. I compiled the project using make and GNU gcc. If I transfer the generated hex-file with the nrf Connect Programmer and the bootloader, the example works. If I transfer the hex file with the Segger J-Flash software, it does not work. Somewhere the nrf Connect Programmer writes a few bytes extra (probably in some vector table). By the way, I can flash the bootloader with Segger J-Flash without any problems and it works. If I use Segger embedded Studio, I can even compile and flash the Blink example without a bootloader via the J-Link V8. The MBR (mbr_nrf52_2.4.1_mbr.hex) and the eleven-file of the project are then transferred. However, the elf-file cannot be flashed via the Segger software J-Flash, an error message is displayed. The corresponding hex file can be flashed, but the flashing example does not work. I also tried to flash the hex files via the command line with nrfjprog, but I got the error message "ERROR: JLinkARM DLL reported an error".

I would like to be able to compile a project with make and GNU-gcc and simply transfer the resulting hex-file to the nrf52840 without a bootloader via the programming device.

Thank you and regards
Markus

  • Hi Markus,

    Using nRF Connect programmer to program via a debugger it will not write anything other than what is in the hex file. And you should not have any problem programming the hex file with other tools either. It should work out of the box. Can you specify exactly which projects you build and which MBR/SoftDevice etc you use with those, and any other hex files you also program, as well as the method you use to program step by step? Perhaps that will reveal somethings I cannot think of at the moment. Can you also upload the hex files here so that I can inspect them and test on my side?

    I also tried to flash the hex files via the command line with nrfjprog, but I got the error message "ERROR: JLinkARM DLL reported an error".

    Can you generate a log by using the --log option and upload it here?

  • Hello Einar,

    I think I solved half of the problem. Since the nRF Connect Programmer using the bootloader to program the device it is not written the hex-File only. When I read out the flash there are definitely a few bytes at the end of the memory different. And the bootloader set also a flag that there is a valid app flashed in the memory. When I do it with J-Flash and J-Link this flag will not be set and the bootloader will never start the application.

    When I erase the whole memory and flash only the mbr (without bootloader) and the blink.hex the program is working fine, the mbr jumps directly to the address 0x1000 where the application lies. But I have really to erase the whole chip before since UICR.NRFFW[0] needs to be not set and the address 0xFFC needs to be 0xFFFFFFFF.

    To set the flag for a valid app manually I couldn't figure it out since nrfjprog is still not working. See the attached log for the erase command: nrfjprog --family nRF52 --eraseall --log

    FYI: I am still new to the nordic hard and software. I use before mostly Atmel avr-Mikrocontroller and the ZigBee-Stack Bitcloud. So I still try to understand the hard and software structure from the nRF52840 and I am trying to get ZigBee and Thread running. But the example I used here was just the peripheral example blink from the SDK which I adjust a little. No Softdevice, no Bluetooth, or anything else yet.

    [2021-Jun-23 17:06:29] [ info] --------------------------------------------------------------------------------
    [2021-Jun-23 17:06:29] [ info] nrfjprog --family nRF52 --eraseall --log 
    [2021-Jun-23 17:06:29] [ info] nrfjprog version 10.12.2 
    [2021-Jun-23 17:06:29] [ info] --------------------------------------------------------------------------------
    [2021-Jun-23 17:06:29] [debug] [ nRF0x0] - open_dll
    [2021-Jun-23 17:06:29] [ info] [ nRF0x0] - Load library at C:\Program Files\Nordic Semiconductor\nrf-command-line-tools\bin\JLINKARM_NRF52_NRFJPROG.dll.
    [2021-Jun-23 17:06:29] [ info] [ nRF0x0] - Library loaded, loading member functions.
    [2021-Jun-23 17:06:29] [ info] [ nRF0x0] - Member functions succesfully loaded.
    [2021-Jun-23 17:06:29] [ info] [Backend] - Logger callback at 0x7ff708cf56f0 registered in Segger backend logger.
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] Logger callback at 0x7ff708cf56f0 registered in JLink logger.
    [2021-Jun-23 17:06:29] [debug] [nRF520x0] - open
    [2021-Jun-23 17:06:29] [debug] [Backend] - open_dll
    [2021-Jun-23 17:06:29] [ info] [Backend] - No J-Link DLL path was provided. Attempting to auto detect.
    [2021-Jun-23 17:06:29] [ info] [Backend] - Load library at C:\Program Files (x86)\SEGGER\JLink\JLink_x64.dll.
    [2021-Jun-23 17:06:29] [ info] [Backend] - Library loaded, loading member functions.
    [2021-Jun-23 17:06:29] [ info] [Backend] - Member functions succesfully loaded.
    [2021-Jun-23 17:06:29] [debug] [Backend] - dll_version
    [2021-Jun-23 17:06:29] [ info] [Backend] - Segger dll version 7.22.b loaded.
    [2021-Jun-23 17:06:29] [debug] [ nRF0x0] - enum_emu_snr
    [2021-Jun-23 17:06:29] [debug] [nRF520x0] - enum_emu_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - enum_emu_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_enum_emu_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_get_num_emus
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [ nRF0x0] - connect_to_emu_with_snr
    [2021-Jun-23 17:06:29] [debug] [nRF520x0] - connect_to_emu_with_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - connect_to_emu_with_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_enum_emu_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_get_num_emus
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_connect_to_emu_with_snr
    [2021-Jun-23 17:06:29] [debug] [Backend] - ---just_connect_to_emu_without_snr
    [2021-Jun-23 17:06:29] [ info] [Backend] - Segger logging enabled.
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] Firmware: J-Link ARM V8 compiled Nov 28 2014 13:44:46
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] Hardware: V8.00
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] S/N: 4294967295
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] OEM: SEGGER
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] Feature(s): RDI,FlashDL,FlashBP,JFlash,GDB
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] TELNET listener socket opened on port 19021
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] WEBSRV Starting webserver
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] WEBSRV Failed to put socket into listener state (port 19080)
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] WEBSRV Webserver running on local port 19081
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 21.139ms returns "O.K."  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_Lock()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_GetHWStatus(...)  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.483ms returns 0  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_ExecCommand("SetRestartOnClose = 0", ...).   
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.003ms returns 0x01  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_ExecCommand("DisableFlashDL", ...).   
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.007ms returns 0x00  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_ExecCommand("ExcludeFlashCacheRange 0x0-0xFFFFFFFF", ...).   
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.005ms returns 0x00  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_SetHookUnsecureDialog  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_SetHookUnsecureDialog(...)
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.017ms returns 0  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_TIF_Select(JLINKARM_TIF_SWD)  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 1.310ms returns 0x00  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_SetSpeed(2000)  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.249ms  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_GetSN()  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.008ms returns -1  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_HasError()  
    [2021-Jun-23 17:06:29] [ info] [Backend] - JLinkARM.dll reported "-1", an unknown error.
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] - 0.024ms  
    [2021-Jun-23 17:06:29] [ info] [  JLink] - [Info    ] [JLink     ] JLINK_Close()  
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [ nRF0x0] - close_dll
    [2021-Jun-23 17:06:29] [debug] [nRF520x0] - close
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - close
    [2021-Jun-23 17:06:29] [debug] [Backend] - disconnect_from_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - is_connected_to_emu
    [2021-Jun-23 17:06:29] [debug] [Backend] - Segger Backend closed.
    [2021-Jun-23 17:06:29] [debug] [nRF520x0] - nRF family DLL closed
    

  • Hi,

    MarkusK said:
    I think I solved half of the problem. Since the nRF Connect Programmer using the bootloader to program the device it is not written the hex-File only. When I read out the flash there are definitely a few bytes at the end of the memory different. And the bootloader set also a flag that there is a valid app flashed in the memory. When I do it with J-Flash and J-Link this flag will not be set and the bootloader will never start the application.

    Yes, if you use the USB bootloader to program this will be the case (typically for the nRF52840 dongle which ships with a SUB bootloader). But note that if you use nRF Connect programmer to flash via a debugger (like the onboard debugger on a DK), it will not write anything other than the hex file you provide. So if you program the app using a debugger and you have a bootloader, you also need to generate a valid bootloader settings page and program that as well (see Generating and displaying bootloader settings).

    Which device are you working on? I would generally recommend to start without a bootloader as its presence causes some hassle when developing.

    MarkusK said:
    When I erase the whole memory and flash only the mbr (without bootloader) and the blink.hex the program is working fine, the mbr jumps directly to the address 0x1000 where the application lies. But I have really to erase the whole chip before since UICR.NRFFW[0] needs to be not set and the address 0xFFC needs to be 0xFFFFFFFF.

    Yes. If you have a recent MBR it first checks 0x00000FFC. If that is all ff's it checks UICR.NRFFW[0]. If neither is set  then the MBR will continue executing from 0x1000 (where either the application or SoftDevice resides). If one of them is set, that is assumed to be the bootloader start address and the MBR will jump to it.

    MarkusK said:
    To set the flag for a valid app manually I couldn't figure it out since nrfjprog is still not working. See the attached log for the erase command: nrfjprog --family nRF52 --eraseall --log

    I see there is an error but do not make much sense of it. Which HW are you using to test? Are you using the onboard debugger on the DK, or an external debugger? If so, which debugger are you using?

  • Hi,

    since I am doing home office from Bali, I was only able to get two nRF52840 USB Dongle from Makerdiary first. As an external Programmer/Debugger I got the Segger J-Link V8. I am teaching students on the topic wireless sensor network and they have to do projects in this area. So I am looking for a solution which fulfills the requirements for education, this means reliable, easy to use and not too expensive. For ZigBee I designed before already our own developer boards. Now I am looking if we can extend our experience using Thread-networks and the Nordic solution looks promisings.

    And for education purposes, I also like not using the bootloader first, but then we need an easy way to program the nRF52840. By the way, the J-Link V8 programmer is not shown in the nRF Connect Programmer App. Only the device itself, when it enters the bootloader mode.

    Thx for your help.

  • Hi,

    I see. You could do a full chip erase to debug the dongle as normal (you also would not meet the issues with voltage I described in this tutorial as you are using a debugger that supports a vide voltage range). If not, you need to keep using the nRF Connect Programmer and program via USB DFU or update the bootloader settings page with the correct CRC of your app whenever you program a new one. If not, the bootloader will see that the CRC does not match the current application and will enter DFU mode instead of starting the app.

    (Generally I would recommend a DK for development as that has everything you need and to not give you these additional hurdles, but as you have a proper debugger that should be fine as well.)

Related