PYNRFJPROG

HI,  

We have two products that work together.  One uses the nrf52832 and the other nrf5340.  Using the Programmer (3.0.9) we can take a factory fresh 5340 Erase all and program both network and application cores perfectly.  However this is slow.  I have created a python programmer that does the job much more quickly.  On the 52832 its flawless, however, working with the 5340, I get:

An error was reported by NRFJPROG DLL: -90 NOT_AVAILABLE_BECAUSE_PROTECTION. 

Here is the relative part of the code:

if device_family == "NRF53":
            program_options = ProgramOptions( verify=VerifyAction.VERIFY_NONE, erase_action=EraseAction.ERASE_ALL, qspi_erase_action=EraseAction.ERASE_ALL,  reset=ResetAction.RESET_SYSTEM )
     
            api = LowLevel.API()
            api.open()
            api.connect_to_emu_without_snr()

            print(f"The DLL version is: {api.dll_version()}")
            print(f"Erase protect: {api.is_eraseprotect_enabled()}")
            print("Recovering device")
            api.recover()
            print("Erasing Device")
            api.erase_all()
            api.close()

            api = HighLevel.API()
            api.open()
            snr = api.get_connected_probes()
            for s in snr:
                print(f"snr: {s}")
                probe = HighLevel.DebugProbe(api, s)
                print(f"Device Family: {device_family}")
                print(f"Device Version: {device_version}")
             
                probe = HighLevel.DebugProbe(api, s)
                for f in files:  #only 1 file being programmed, works with programmer
                    print("Programming Application")

                    probe.program(f,program_options)
            api.close()

This results in:


Message=An error was reported by NRFJPROG DLL: -90 NOT_AVAILABLE_BECAUSE_PROTECTION.
[Probes.821001306] [Client] Encountered error -90: Command erase_file executed for 380 milliseconds with result -90
extra: [Probes.821001306] [DebugProbe] Failed while erasing device.
extra: [HighLevel] Failed programming the device.
extra: [Probes.821001306] [nRF53] Failed while erasing device. -90: Access protection is enabled, can't erase memory.
extra: [Probes.821001306] [Worker] Access protection is enabled, can't erase memory.
Source=C:\Users\xxxxx\source\repos\serializer\serializer.py
StackTrace:
File "C:\Users\xxxxx\source\repos\serializer\serializer.py", line 186, in flashHex
probe.program(f,program_options)
File "C:\Users\xxxxx\source\repos\serializer\serializer.py", line 227, in main
sc.flashHex(cwd)
File "C:\Users\xxxxx\source\repos\serializer\serializer.py", line 264, in <module> (Current frame)
main()
pynrfjprog.APIError.APIError: An error was reported by NRFJPROG DLL: -90 NOT_AVAILABLE_BECAUSE_PROTECTION.
[Probes.821001306] [Client] Encountered error -90: Command erase_file executed for 380 milliseconds with result -90
extra: [Probes.821001306] [DebugProbe] Failed while erasing device.
extra: [HighLevel] Failed programming the device.
extra: [Probes.821001306] [nRF53] Failed while erasing device. -90: Access protection is enabled, can't erase memory.
extra: [Probes.821001306] [Worker] Access protection is enabled, can't erase memory.

I have tried:

This but it doesn't seem to help and I get Failed to disable eraseprotect.  Another weird note is that when I use the programmer to erase all, I can then use the pynrfjprog to program the board without problems.  So my basic question is, What do i need to do to get the python version working te same as the programmer because using the programmer is way to slow.

Here is the output from the programmer:

2023-10-27T02:20:31.289Z DEBUG Application data folder: C:\Users\xxxx\AppData\Roaming\nrfconnect\pc-nrfconnect-programmer
2023-10-27T02:20:31.452Z DEBUG App pc-nrfconnect-programmer v3.0.9 local
2023-10-27T02:20:31.453Z DEBUG App path: C:\Users\xxxx\.nrfconnect-apps\node_modules\pc-nrfconnect-programmer
2023-10-27T02:20:31.453Z DEBUG nRFConnect 4.1.2, required by the app is (>=4.0.0)
2023-10-27T02:20:31.453Z DEBUG nRFConnect path: C:\Users\rgant\AppData\Local\Programs\nrfconnect\resources\app.asar
2023-10-27T02:20:31.453Z DEBUG HomeDir: C:\Users\xxxx
2023-10-27T02:20:31.453Z DEBUG TmpDir: C:\Users\xxxx\AppData\Local\Temp
2023-10-27T02:20:31.889Z INFO Using nrf-device-lib-js version: 0.6.12
2023-10-27T02:20:31.889Z INFO Using nrf-device-lib version: 0.15.3
2023-10-27T02:20:31.890Z INFO Using nrfjprog DLL version: 10.19.1
2023-10-27T02:20:31.890Z INFO Using JLink version: JLink_V7.88j
2023-10-27T02:20:32.133Z INFO Installed JLink version does not match the provided version (V7.80c)
2023-10-27T02:20:32.755Z INFO Getting serialport options from persistent store 000821000627.pc-nrfconnect-programmer
2023-10-27T02:20:36.308Z DEBUG Client Id: c7f57b89-aabe-4ece-ada9-af7fdcd2bec3
2023-10-27T02:20:37.604Z DEBUG Google Analytics for category pc-nrfconnect-programmer has initialized
2023-10-27T02:20:38.011Z INFO Using @nordicsemiconductor/nrf-device-lib-js to communicate with target via JLink
2023-10-27T02:20:38.011Z INFO JLink OB firmware version J-Link V11 compiled Mar 15 2023 11:20:48
2023-10-27T02:20:38.012Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"architecture","label":"x64"}
2023-10-27T02:20:38.013Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink OB version","label":"J-Link V11 compiled Mar 15 2023 11:20:48"}
2023-10-27T02:20:38.014Z INFO Device family NRF53_FAMILY
2023-10-27T02:20:38.015Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device family","label":"NRF53_FAMILY"}
2023-10-27T02:20:38.016Z INFO Device version NRF5340_xxAA_ENGD
2023-10-27T02:20:38.016Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device version","label":"NRF5340_xxAA_ENGD"}
2023-10-27T02:20:38.017Z INFO Board version Unknown
2023-10-27T02:20:38.017Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device board version","label":"Unknown"}
2023-10-27T02:20:38.018Z INFO Loading readback protection status for Application core
2023-10-27T02:20:38.018Z INFO Loading readback protection status for Network core
2023-10-27T02:20:38.018Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open device","label":"jlink"}
2023-10-27T02:20:38.670Z INFO Readback protection status: NRFDL_PROTECTION_STATUS_ALL
2023-10-27T02:20:39.002Z INFO Readback protection status: NRFDL_PROTECTION_STATUS_ALL
2023-10-27T02:20:39.008Z INFO Parse memory regions for Application core
2023-10-27T02:20:39.009Z INFO Parse memory regions for Network core
2023-10-27T02:20:39.011Z INFO Update files regions according to Application core
2023-10-27T02:20:39.011Z INFO Parse memory regions for file
2023-10-27T02:20:39.011Z INFO Update files regions according to Network core
2023-10-27T02:20:39.011Z INFO Parse memory regions for file
2023-10-27T02:20:39.018Z INFO Device is loaded and ready for further operation
2023-10-27T02:20:44.932Z INFO Parsing HEX file:  C:\code\flashtest\mfg_test-0.2.hex
2023-10-27T02:20:44.948Z INFO File was last modified at  10/18/2023, 10:27:07 AM
2023-10-27T02:20:45.130Z INFO Update files regions according to Application core
2023-10-27T02:20:45.130Z INFO Parse memory regions for file
2023-10-27T02:20:45.131Z INFO Update files regions according to Network core
2023-10-27T02:20:45.131Z INFO Parse memory regions for file
2023-10-27T02:20:46.621Z INFO Recovering NRFDL_DEVICE_CORE_APPLICATION core
2023-10-27T02:20:48.767Z INFO Recovering NRFDL_DEVICE_CORE_APPLICATION core completed
2023-10-27T02:20:48.768Z INFO Recovering NRFDL_DEVICE_CORE_NETWORK core
2023-10-27T02:20:50.934Z INFO Recovering NRFDL_DEVICE_CORE_NETWORK core completed
2023-10-27T02:20:50.949Z INFO Device recovery completed
2023-10-27T02:20:50.951Z INFO Writing procedure starts for NRFDL_DEVICE_CORE_APPLICATION core
2023-10-27T02:20:51.118Z INFO Writing HEX to NRFDL_DEVICE_CORE_APPLICATION core
2023-10-27T02:20:51.558Z INFO  0%
2023-10-27T02:20:52.273Z INFO {"chip_erase_mode":"ERASE_ALL","qspi_erase_mode":"ERASE_NONE","reset":"RESET_NONE","verify":"VERIFY_NONE"} 100%
2023-10-27T02:20:52.274Z INFO Uploading image through JLink: 0%
2023-10-27T02:20:54.586Z INFO Uploading image through JLink: 100%
2023-10-27T02:20:54.587Z INFO  100%
2023-10-27T02:20:54.722Z INFO Writing HEX to NRFDL_DEVICE_CORE_APPLICATION core completed
2023-10-27T02:20:54.722Z INFO Writing procedure ends for NRFDL_DEVICE_CORE_APPLICATION core
2023-10-27T02:20:54.722Z INFO Writing procedure starts for NRFDL_DEVICE_CORE_NETWORK core
2023-10-27T02:20:54.805Z INFO Writing HEX to NRFDL_DEVICE_CORE_NETWORK core
2023-10-27T02:20:55.307Z INFO  0%
2023-10-27T02:20:55.920Z INFO {"chip_erase_mode":"ERASE_ALL","qspi_erase_mode":"ERASE_NONE","reset":"RESET_NONE","verify":"VERIFY_NONE"} 100%
2023-10-27T02:20:55.921Z INFO Uploading image through JLink: 0%
2023-10-27T02:20:57.329Z INFO Uploading image through JLink: 100%
2023-10-27T02:20:57.334Z INFO  100%
2023-10-27T02:20:57.482Z INFO Writing HEX to NRFDL_DEVICE_CORE_NETWORK core completed
2023-10-27T02:20:57.482Z INFO Writing procedure ends for NRFDL_DEVICE_CORE_NETWORK core
2023-10-27T02:20:58.336Z INFO Resetting device completed
2023-10-27T02:20:58.339Z INFO Using @nordicsemiconductor/nrf-device-lib-js to communicate with target via JLink
2023-10-27T02:20:58.339Z INFO JLink OB firmware version J-Link V11 compiled Mar 15 2023 11:20:48
2023-10-27T02:20:58.339Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink OB version","label":"J-Link V11 compiled Mar 15 2023 11:20:48"}
2023-10-27T02:20:58.340Z INFO Device family NRF53_FAMILY
2023-10-27T02:20:58.341Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device family","label":"NRF53_FAMILY"}
2023-10-27T02:20:58.342Z INFO Device version NRF5340_xxAA_ENGD
2023-10-27T02:20:58.342Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device version","label":"NRF5340_xxAA_ENGD"}
2023-10-27T02:20:58.343Z INFO Board version Unknown
2023-10-27T02:20:58.343Z DEBUG Sending usage data {"category":"pc-nrfconnect-programmer","action":"Open jlink device board version","label":"Unknown"}
2023-10-27T02:20:58.344Z INFO Loading readback protection status for Application core
2023-10-27T02:20:58.344Z INFO Loading readback protection status for Network core
2023-10-27T02:20:59.137Z INFO Readback protection status: NRFDL_PROTECTION_STATUS_NONE
2023-10-27T02:20:59.461Z INFO Readback protection status: NRFDL_PROTECTION_STATUS_NONE
2023-10-27T02:21:00.225Z INFO Parse memory regions for Application core
2023-10-27T02:21:00.225Z INFO Parse memory regions for Network core
2023-10-27T02:21:00.227Z INFO Update files regions according to Application core
2023-10-27T02:21:00.227Z INFO Parse memory regions for file
2023-10-27T02:21:00.227Z INFO Update files regions according to Network core
2023-10-27T02:21:00.227Z INFO Parse memory regions for file
2023-10-27T02:21:00.232Z INFO Device is loaded and ready for further operation

Parents
  • Hello,

    I would recommend using nrfjprog if you are looking for a way to program your nRF devices from the command line or a batch script, but do not necessarily need Python integration.

    Flashing chip with nrfjprog when readback protection is enabled

    $ nrfjprog --program merged_domains.hex --recover --verify  -r

    Flashing chip with nrfjprog when readback protection is disabled

    nrfjprog --program merged_domains.hex --chiperase --verify  -r

    An error was reported by NRFJPROG DLL: -90 NOT_AVAILABLE_BECAUSE_PROTECTION. 

    The nRF5340 and nrf52832 with the latest build code (see IN142 Informational Notice v1.1) have readback protection enabled by default when they leave our factory, which must be disabled before you can perform the initial programming of the chip. When you do an "ERASEALL" in the programmer app, it will perform the same operation as nrfjprog --recover does to unlock the chip. The equivalent function in pynrfjprog is implemented here: https://github.com/NordicSemiconductor/pynrfjprog/blob/67e1a1eeaf77566214ea055aed4fd130401ae5a2/pynrfjprog/LowLevel.py#L680 

    Best regards,

    Vidar

  • Hi Vidar,

    As you can see from the above code, I perform a low level recover:

    print(f"The DLL version is: {api.dll_version()}")
    print(f"Erase protect: {api.is_eraseprotect_enabled()}")
    print("Recovering device")
    api.recover()
    print("Erasing Device")
    api.erase_all()
    api.close()

    But I still cant program the device.   I need to be able to permanently disable to protection.  When I try from the command line, wit the command you provided, it works fine.  we have several steps including serializing the device that the python program takes care of for us.  Are you suggesting that i need to write the scripts in a different language because the python nrfjprog doesn't always work?  Or is the lowlevel recover working and the chip is reset to its original state because I close the low level api and open the high level api?  If that is the case, can you please tell me how to write a merged.hex using the low level api?  The documentation is terrible for the python library.

    I tried using a command shell from python it seems to work but I get these errors in the output:

    [error] [ Client] - Encountered error -90: Command read_memory_descriptors executed for 15 milliseconds with result -90
    [error] [ Worker] - Can't read memory descriptors, ap-protection is enabled.

    However the code IS loaded onto the chip, so why the errors?

    Brian

  • Hi Brian, 

    I made a test using the 'highlevel_program_hex.py' example and discovered that one must specify the CPU core when disabling readback protection (APPROTECT). Please try to disable the readback protection using the high level API as I did here:

    import sys
    from pynrfjprog import HighLevel, Parameters
    
    
    def program_hex(hex_file_path):
    
        # Initialize an API object.
        # Open the loaded DLL and connect to an emulator probe.
        with HighLevel.API() as api:
    
            probes = api.get_connected_probes()        
            snr = probes[0]
            # Initialize the probe connection. The device family is automatically detected, and the correct sub dll is loaded.
            with HighLevel.DebugProbe(api, snr) as probe:
    
                print("# Reading out device information.")
                # Read out device information to find out which hex file to program
                device_info = probe.get_device_info()
                print(device_info.device_family)
    
                # Erase all the flash of the device.
                print("# Programming %s to device with ERASE_ALL and SYSTEM_RESET." % hex_file_path)
    
                # Make a program option struct to modify programming sequence.
                # If ommitted, the default programoptions struct specifies ERASE_ALL, SYSTEM_RESET, and VERIFY_NONE.
                program_options = HighLevel.ProgramOptions(
                    erase_action=HighLevel.EraseAction.ERASE_ALL,
                    reset=HighLevel.ResetAction.RESET_SYSTEM,
                    verify=HighLevel.VerifyAction.VERIFY_READ,
                )
    
                probe.set_coprocessor(Parameters.CoProcessor.CP_NETWORK)
                if probe.get_readback_protection() != Parameters.ReadbackProtection.NONE:
                    print("Disabling APPROTECT on network core")
                    probe.recover()
                probe.set_coprocessor(Parameters.CoProcessor.CP_APPLICATION)
                if probe.get_readback_protection() != Parameters.ReadbackProtection.NONE:
                    probe.recover()
                    print("Disabling APPROTECT on application core")
                
                probe.program(hex_file_path, program_options=program_options)
    
                print("# Application running. ")
    
        print("# Example done...")
    
    def main():
        if len(sys.argv) != 2:
            print("No .hex file specified")
            sys.exit(1)
        
        hex_file = sys.argv[1]
        program_hex(hex_file) 
    
    
    if __name__ == "__main__":
        main()

    Please also ensure that your pynrfjprog package is up to date (v10.23.2 at the time of writing). This is required if the input hex file contains data for both the application and network core.

    Vidar

  • Hi Vidor, That did it!  i wasn't recovering each core separately.  Didn't realize  I had to do that.  Its all working now and everything is much faster.

Reply Children
No Data
Related