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

Can not enter application after readback protect?

Hi ,

I wirte a python script to download FW to nRF52832 custom board, the FW is the merged file with softdevice(s132_nrf52_7.0.1_softdevice.hex), bootload, bootload settings, and application,  then setting readback protect. 

After setting readback protect, our board just advertising DfuTarg,it seems enter bootload, didn't enter application.

the python script is as follows,

api = LowLevel.API("NRF52")
sleep(1)
try:
api.open()
api.connect_to_emu_with_snr(jlink_serial, swd_speed)

# Program the parsed hex into the device's memory.
test_program = Hex.Hex(hex_file_path)
print("Writing %s to device..." % hex_file_path)

for segment in test_program:
api.write(segment.address, segment.data, True)

api.sys_reset()
api.go()
api.readback_protect(2) # or api.write_u32(0x10001208, 0x00,True)

api.pin_reset()
api.close()

If I comment out api.readback_protect(2),our board can enter application and works ok .
In addtion, I download the same FW with nRF connect Programmer, our board can enter application and works ok.
I download another FW, which is merge file with eddystone example,bootload,softdevice, and bootload settings,
it has the same problem,always enter the bootload, attached please find this FW.
1602.ed_sd_bl_set_app.hex
Please help analyze the reason, thank you very much.








  • Hi Vidar,

    According to your suggestion, I checked the version of mergehex , it is  version: 10.4.1.

    And I modified the programming script,  as shown in the example highlevel_programe_hex.py,  it gives the same result.

    Before if I don't set readback_protect, the application can run. if set readback_protect, still advertsing DfuTarg.

    Following is the script,

    def program_target(dut):
        global jlink_serial, swd_speed, hex_file_path
        print ("Flash DUT with production firmware")
    
        api = HighLevel.API("NRF52")  #add by Susan
    
        sleep(1)
    
        dut.hexfilemd5=md5(hex_file_path)
        try:
            api.open()
          #  api.connect_to_emu_with_snr(jlink_serial, swd_speed)  # comment out by Susan
            probe = HighLevel.DebugProbe(api, jlink_serial)   #add by Susan
    
            dut.hexfilename = hex_file_path
            print("Writing %s to device..." % 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.
            #following add by Susan
            
            program_options = HighLevel.ProgramOptions(
                erase_action=HighLevel.EraseAction.ERASE_ALL,
                reset=HighLevel.ResetAction.RESET_SYSTEM,
                verify=HighLevel.VerifyAction.VERIFY_READ
            )
            
            probe.program(hex_file_path, program_options=program_options)
    
            sleep(1)  # if don't add sleep time, will advertising DfuTarg.
            probe.readback_protect()
         #   probe.reset()  # if add reset, will except APIError.
            probe.close()
    
            dut.flash_success = True
            dut.programtime = str(datetime.datetime.now())
            return dut
    
        except HighLevel.APIError:
            print ("Programming adapter not found!---1")
            dut.failure_desc="No programming adapter or programming failed!"
    
            probe.close()  #add by susan
            dut.flash_success = False
            return dut
    

     I try to  add sleep time delay 0.01 seconds before probe.readback_protect,  the application can run, why?

    sleep(0.01)     # if don't add sleep time, will advertising DfuTarg.
    probe.readback_protect()
    # probe.reset()   # if add reset, will except APIError.
    probe.close()

    After probe.readback_protect(),  do I need to add probe.reset() ?  

    Try previous programming script,  which use the LowLevel API,  just add sleep time before api.readback_protect(2), test 10 times, the applicaiton can run. 

    def program_target(dut):
        global jlink_serial, swd_speed, hex_file_path
        print ("Flash DUT with production firmware")
        
        api = LowLevel.API("NRF52")  
        sleep(1)
    
        dut.hexfilemd5=md5(hex_file_path)
        try:
            api.open()
            api.connect_to_emu_with_snr(jlink_serial, swd_speed)  # comment out by Susan
    
            # Program the parsed hex into the device's memory.
            test_program = Hex.Hex(hex_file_path)
            dut.hexfilename = hex_file_path
            print("Writing %s to device..." % hex_file_path)
    
            for segment in test_program:
                api.write(segment.address, segment.data, True)
                content = api.read(segment.address, len(segment.data))
                if not segment.data == content:
                    print ("Program data mismatch starting at address: {}, segment length: {}".format(str(segment.address, 'x'), str(len(segment.data))))
                    raise LowLevel.APIError
                    break
    
            print (str(datetime.datetime.now()) + ": Resetting target...")
            api.sys_reset()   
            api.go()
            
            sleep(0.01)  # if don't add sleep time, will advertising DfuTarg.
            
            api.readback_protect(2)   # or api.write_u32(0x10001208, 0x00,True)
            print ("Pinreset...")
            api.pin_reset()
            api.close().
    
            dut.flash_success = True
            dut.programtime = str(datetime.datetime.now())
            return dut
            
        except LowLevel.APIError:
            print ("Programming adapter not found!---1")
            dut.failure_desc="No programming adapter or programming failed!"
            api.close()   
            dut.flash_success = False
            return dut
    

    What is differrent between HighLevel API and LowLevel API ?  Which one should I use first?

    Is it necessary to increase sleep time before readback protection? 

    Please help me to check above two programming script , any problem, please help to corret, thank you very much.

    Best regards,

    Susan 

  • Hi Vidar,

    Any update or  suggestions ? thank you very much.

    Susan

  • Hi Susan,

    It sounded like the problem was more intermittent earlier, even when you didn't enable readback protection.  Have you seen any failures now after you added the delay? Also, are you using the same J-link debugger when you use nrfjprog/nRFconnect?

    Best regards,

    Vidar

  • Hi Vidar,

    I haven't see any failures  after you added the delay.  Of course I am using the same J-link debugger I use nrfjprog/nRFconnect. 

    when I use flash script, the SWD speed is 10000kHz.

    What is the default SWD speed when I use nrfjprig/nRFconnect?

    Does SWD speed affect the integrity check and cause this problem? Thank you very much.

    Best regards,

    Susan

  • Hi Susan,

    Ok, thanks for confirming that you were using the same J-link.

    I may be related to the clock speed as you say. The default speed is usually between the 2000 - 4000 kHz, so considerably slower than what your script is using. Could you try lowering the clock speed and see it helps?

    The verification step (checks integrity check of loaded image) you enabled with the high level API should detect any programming errors. Did you check the log to see if pynrfjprog reported any errors?

    Best regards,

    Vidar

Related