Exemplo n.º 1
0
def programe_file_thread(jlink_obj, progress_obj, file_1, file_2, file_3):
    try:
        if not jlink_obj.is_open():
            jlink_obj.open()
        jlink_1.connect_to_emu_with_snr(int(JLinkDevice.get()))

        progress_obj["maximum"] = 3
        if file_1:
            jlink_1.erase_all()
            for segment in Hex.Hex(file_1):
                jlink_obj.write(segment.address, segment.data, True)
        progress_obj["value"] = 1
        if file_2:
            for segment in Hex.Hex(file_2):
                jlink_obj.write(segment.address, segment.data, True)
        progress_obj["value"] = 2
        if file_3:
            for segment in Hex.Hex(file_3):
                jlink_obj.write(segment.address, segment.data, True)
        progress_obj["value"] = 3
        # Reset device, run
        jlink_1.sys_reset()
        jlink_1.go()

        # Close API
        jlink_1.close()
    except API.APIError as exc:
        messagebox.showerror('Programe Status', str(exc))
    else:
        messagebox.showinfo('Programe Status', 'Programe Successed.')
Exemplo n.º 2
0
def flash(hex_file_path):
    api = API.API('NRF51')
    api.open()
    serial_numbers = api.enum_emu_snr()

    for snr in serial_numbers:
        api.connect_to_emu_with_snr(snr)
        assert api.is_connected_to_emu()

        # api.connect_to_device()?
        api.erase_all()

        program = Hex.Hex(hex_file_path)
        print('# Flashing on {}'.format(snr))
        for segment in program:
            api.write(segment.address, segment.data, True)

        api.sys_reset()
        print('# Device reset... ')

        api.go()
        print('# Application running...  ')

        api.disconnect_from_emu()
        print('')

    api.close()
Exemplo n.º 3
0
    def flash_application(self, hex_file_path):
        """
        callback routine used to decode the data read from the device.

        @param int hex_file_path: Path to the hex file you want to flash

        @return None
        """

        try:
            if os.path.exists(hex_file_path):
                pass
            else:
                return "Failed to locate hex file at %s" % hex_file_path

            application = Hex.Hex(
                hex_file_path)  # Parsing hex file into segments
            for segment in application:
                self.nrfjprog.write(segment.address, segment.data, True)

            return True
        except Exception as e:
            print(str(e))
            print("Failed to write device")
            return str(e)
Exemplo n.º 4
0
def run(snr=None):
    """
    Run example script.

    @param (optional) int snr: Specify serial number of DK to run example on.
    """
    print('# Hex file programming example using pynrfjprog started...')
    
    # Detect the device family of your device. Initialize an API object with UNKNOWN family and read the device's family. This step is performed so this example can be run in all devices without customer input.
    print('# Opening API with device family UNKNOWN, reading the device family.')
    with API.API(API.DeviceFamily.UNKNOWN) as api:            # Using with construction so there is no need to open or close the API class.
        if snr is not None:
            api.connect_to_emu_with_snr(snr)
        else:
            api.connect_to_emu_without_snr()
        device_family = api.read_device_family()
    
    # Initialize an API object with the target family. This will load nrfjprog.dll with the proper target family.
    api = API.API(device_family)
    
    # Open the loaded DLL and connect to an emulator probe. If several are connected a pop up will appear.
    api.open()
    if snr is not None:
        api.connect_to_emu_with_snr(snr)
    else:
        api.connect_to_emu_without_snr()

    device_version = api.read_device_version()

    hex_file_path = find_blinky_hex(device_family, device_version)

    if hex_file_path is None:
        api.close()
        raise Exception("Could not find example binary for device " + device_version.lower() + ".\n" +
                        "This example may not support your device yet.")

    # Erase all the flash of the device.
    print('# Erasing all flash in the microcontroller.')
    api.erase_all()
    
    # Parse the hex file with the help of the HEX module
    print('# Parsing hex file into segments.')
    test_program = Hex.Hex(hex_file_path)
    
    # Program the parsed hex into the device's memory.
    print('# Writing %s to device.' % hex_file_path)
    for segment in test_program:
        api.write(segment.address, segment.data, True)
       
    # Reset the device and run.
    api.sys_reset()           
    api.go()
    print('# Application running. Your board should be blinking.')

    # Close the loaded DLL to free resources.
    api.close()                             

    print('# Example done...')
Exemplo n.º 5
0
    def program(self, modem_digest, path=None):

        # Parse the hex file with the help of the HEX module
        if path is not None:
            test_program = Hex.Hex(path[0])
        else:
            try:
                test_program = Hex.Hex(modem_digest[0:7].upper()+".ipc_dfu.signed.ihex")
            except:
                print("ERROR: cant find: "+modem_digest[0:7]+".ipc_dfu.signed.ihex")
                print("ERROR: Missing correct ipc_dfu for current verison.")
                return NrfDfuErr.MISSING_IPC_FILE

        # Program the parsed hex into the device's memory.
        for segment in test_program:
            self.api.write(segment.address, segment.data, False)

        return NrfDfuErr.SUCCESS
Exemplo n.º 6
0
    def flash_application(self, hex_file_path):
        try:
            if os.path.exists(hex_file_path):
                pass
            else:
                return "Failed to locate hex file at %s" % (hex_file_path)

            application = Hex.Hex(hex_file_path)  # Parsing hex file into segments
            for segment in application:
                self.nrfjprog.write(segment.address, segment.data, True)

            return True
        except Exception as e:
            print((str(e)))
            print ("Failed to write device")
            return str(e)
Exemplo n.º 7
0
      api.read_connected_emu_snr().__str__())
test = api.is_connected_to_emu()
if test is True:
    print("# Connection is established")
else:
    print("not connected")
    exit()

print("# Erasing Flash")
api.recover()
module_dir = directory
# module_file = chosen

# module_dir, module_file = os.path.split(__file__)

directory, chosen = os.path.split(__file__)
hex_file_path = os.path.join(os.path.abspath(module_dir), fw_file[fw])

print("# Parsing hex file into segments")
fw3_2 = Hex.Hex(hex_file_path)

print('# Writing %s to device.' % hex_file_path)
for segment in fw3_2:
    api.write(segment.address, segment.data, True)

api.sys_reset()
api.pin_reset()
api.go()
api.close()
print("# All done...")
def hex_load():
    print('Entering hex_load()')
    api = MultiAPI.MultiAPI('NRF51')

    global device_array
    global handle_array
    global master_segger_id
    global softdevice_file_location
    global master_hex_file_location
    global slave_hex_file_location

    a = 0
    #handle number
    name = 1

    for device_serial in device_array:

        if (device_serial != master_segger_id):

            print(device_serial)

            if (device_serial == None):
                break

            api.open()

            api.connect_to_emu_with_snr(device_serial)
            print('Connected to', device_serial, ' device.')

            api.erase_all()

            # Program device with all hex files supplied by user.
            hexFiles = [softdevice_file_location, slave_hex_file_location]

            for hex_file_path in hexFiles:

                if (hex_file_path == None):
                    break
                try:
                    program = Hex.Hex(
                        hex_file_path
                    )  # Parse .hex file into segments. Checks whether user passed a valid file path or not.
                except Exception as e:  # If hex_file_path not a valid file, print an error and raise an exception.
                    api.close()
                    print(
                        ' # One of the hex files provided was invalid... Please check that the path is correct. Closing api and exiting. '
                    )
                    raise e

                print('# Writing %s to device  ' % hex_file_path)
                for segment in program:  # Program hex file to the device.
                    api.write(segment.address, segment.data, True)

            #write handle for each slave
            api.write_u32(0x3F000, name, True)
            handle_array.append(name)

            print('handle is written')

            # Reset device, run
            api.sys_reset()  # Reset device
            api.go()  # Run application
            print('# Application running on', device_serial)
            print(api.read_u32(0x3F000))
            # Close API
            api.close()  # Close the dll
            a = 1
            name = name + 1
            print('# Hex file downloaded done on', device_serial)

        if (device_serial == master_segger_id):
            api.open()
            api.connect_to_emu_with_snr(device_serial)
            print('Connected to', device_serial, ' device.')

            api.erase_all()
            hexFiles = [softdevice_file_location, master_hex_file_location]

            for hex_file_path in hexFiles:

                if (hex_file_path == None):
                    break
                try:
                    program = Hex.Hex(
                        hex_file_path
                    )  # Parse .hex file into segments. Checks whether user passed a valid file path or not.
                except Exception as e:  # If hex_file_path not a valid file, print an error and raise an exception.
                    api.close()
                    print(
                        ' # One of the hex files provided was invalid... Please check that the path is correct. Closing api and exiting. '
                    )
                    raise e

                print('# Writing %s to device  ' % hex_file_path)
                for segment in program:  # Program hex file to the device.
                    api.write(segment.address, segment.data, True)
            # Reset device, run
            api.sys_reset()  # Reset device
            api.go()  # Run application
            api.close()  # Close the dll
            print('# Hex file downloaded done on master', device_serial)
Exemplo n.º 9
0
def programe_file_thread(jlink_obj, progress_obj, file_1, file_2, file_3):
    button_disable()
    try:
        State.set("State: Busy")
        if not jlink_obj.is_open():
            jlink_obj.open()
        jlink_obj.connect_to_emu_with_snr(int(JLinkDevice.get()))

        progress_obj["maximum"] = 2
        step = 0
        if file_1:
            progress_obj["maximum"] += len([segment for segment in Hex.Hex(file_1)])
        if file_2:
            progress_obj["maximum"] += len([segment for segment in Hex.Hex(file_2)])
        if file_3:
            progress_obj["maximum"] += len([segment for segment in Hex.Hex(file_3)])

        if file_1:
            State.set("State: write SoftDevice...")
            for segment in Hex.Hex(file_1):
                jlink_obj.write(segment.address, segment.data, True)
                step += 1
                progress_obj["value"] = step

        if file_2:
            State.set("State: write App...")
            for segment in Hex.Hex(file_2):
                jlink_obj.write(segment.address, segment.data, True)
                step += 1
                progress_obj["value"] = step

        if file_3:
            State.set("State: write Bootload...")
            for segment in Hex.Hex(file_3):
                jlink_obj.write(segment.address, segment.data, True)
                step += 1
                progress_obj["value"] = step

        State.set("State: config protection...")
        if 1 == device_family.get():
            if 1 == read_back_protection.get():
                jlink_obj.readback_protect('ALL')
        else:
            if 1 == read_back_protection.get():
                jlink_obj.write_u32(0x10001208, 0xFFFFFF00, True)
        
        # Reset device, run
        jlink_obj.sys_reset()
        jlink_obj.go()
        # Close API
        jlink_obj.close()

        State.set("State: Done.")
        progress_obj["value"] = progress_obj["maximum"]
    except API.APIError as exc:
        jlink_obj.close()
        progress_obj["value"] = 0
        State.set("State: Programe Failed.")
        messagebox.showerror('Programe Status', str(exc))
    else:
        State.set('State: Programe Successed.')
    button_enable()
Exemplo n.º 10
0
if __name__ == "__main__":
    hexfile = "ppk_110.hex"
    success = False
    retries = 5
    # Open connection to debugger and rtt
    nrfjprog = API.API('NRF52')
    nrfjprog.open()
    nrfjprog.connect_to_emu_without_snr()
    while (success is False or retries == 0):
        try:
            nrfjprog.recover()
            print "PPK erased"
            success = True
        except:
            print "failed, retrying"
            retries -= 1
            pass
    try:
        application = Hex.Hex(hexfile)
        for segment in application:
            nrfjprog.write(segment.address, segment.data, True)
        print "PPK reprogrammed"
        nrfjprog.sys_reset()
        nrfjprog.go()
        nrfjprog.rtt_start()
        print "PPK ready to go"
    except Exception as e:
        print str(e)
        print "Unable to flash " + hexfile + ", make sure this file is found in working directory."
    raw_input("Press any key to finish...")
Exemplo n.º 11
0
    def verify_update(self, hex_file_path, fw_digest_path):
        if (not self._quiet):
            print ("Starting verification")
        address = []
        length = []

        test_program = Hex.Hex(hex_file_path)

        for segment in test_program:
            if segment.address < 0x1000000:
                address.append(segment.address)
                length.append(len(segment.data))

        self.api.write_u32(0x2000000C, 0x00000007, True)
        self.api.write_u32(0x20000010, len(address), False)

        for n in range(0, len(address)):
            self.api.write_u32(0x20000014+(n*8), address[n], False)
            self.api.write_u32(0x20000018+(n*8), length[n], False)

        self.api.write_u32(0x4002A004, 0x00000001, False)

        start_time = time.time()
        event_received = False
        while (event_received == False):
            if ((time.time() - start_time) > 10):
                print ("ERROR: Time out, no event received after 10 sec.")
                return NrfDfuErr.TIME_OUT
            return_value, event_received = self.get_event_status()
            if return_value < 0:
                return return_value

        self.acknowlage_events()

        return_value, modem_response = self.read_be(0x2000000C)

        #print ("Modem responded with %s" % modem_response)

        if (modem_response == "5a000001"):
            print("\n\n ERROR: UNKNOWN COMMAND")
            return NrfDfuErr.DFU_ERROR
        elif (modem_response == "5a000002"):
            print("\n\n ERROR: COMMAND ERROR")
            error_result = self.api.read_u32(0x20000010)
            print("ERROR: Program failed at %s" % hex(error_result))
            return NrfDfuErr.DFU_ERROR

        return_value, digest = self.read_digest()
        datafile = open(fw_digest_path)
        for line in datafile:
            if ("%s"%digest).upper() in line:
                if (not self._quiet):
                    print ("Verification success")
                verified = True
                break
            else:
                verified = False

        if not verified:
            if (not self._quiet):
                print("Verification failed")
            return NrfDfuErr.DFU_ERROR
        else:
            return NrfDfuErr.SUCCESS
Exemplo n.º 12
0
    def update_firmware(self, hex_file_path):
        firmware_start = time.time()
        if (not self._quiet):
            print("Updating modem firmware")

        buffer_size=0x3FC00 - 0x18
        test_program = Hex.Hex(hex_file_path)
        program_start = time.time()

        for segment in test_program:
            data = []
            address = segment.address
            length = len(segment.data)
            max_length = len(segment.data)
            start = 0
            if (not self._quiet):
                print("Programming pages from address %s" % hex(address))
            if (length > buffer_size - 1):
                end = buffer_size
                length = end - start
            else:
                end = length

            while True:
                if (address % 8192 != 0):
                    if (not self._quiet):
                        print("address missalignement")
                    length += (address % 8192)
                    address = address - (address % 8192)
                    if (not self._quiet):
                        print ("Address aligned to {}".format(address))
                    data = [0xFF]*(address % 8192)

                data += segment.data[start:end]

                if (length % 8192 != 0):
                    length += (length % 8192)
                    data += [0xFF] * (length % 8192)

                self.api.write(0x20000018, data, False)
                self.api.write_u32(0x20000010, address, False)
                self.api.write_u32(0x20000014, length, False)
                self.api.write_u32(0x4002A100, 1, False)

                #initiate write
                self.api.write_u32(0x2000000C, 0x00000003, True)
                self.api.write_u32(0x4002A004, 0x00000001, False)

                start_time = time.time()
                event_received = False
                while (event_received == False):
                    if ((time.time() - start_time) > 10):
                        print ("ERROR: Time out, no event received after 10 sec.")
                        return NrfDfuErr.TIME_OUT
                    return_value, event_received = self.get_event_status()
                    if return_value < 0:
                        return return_value

                self.acknowlage_events()

                return_value, modem_response = self.read_be(0x2000000C)

                if (modem_response == "5a000001"):
                    print("\n\n ERROR: UNKNOWN COMMAND")
                    return NrfDfuErr.DFU_ERROR
                elif (modem_response == "5a000002"):
                    print("\n\n ERROR: COMMAND ERROR")
                    error_result = self.api.read_u32(0x20000010)
                    print("Program failed at {}".format(hex(error_result)))
                    return NrfDfuErr.DFU_ERROR

                if (length < buffer_size - 1):
                    break
                else:
                    start = start + length
                    address =  address +length
                    if end + length >= max_length:
                        end = max_length
                    else:
                        end = end + length

        program_end = time.time()
        if (not self._quiet):
            print ("Programing firmware time: %f" % (program_end - program_start))
        fimrware_end = time.time()
        if (not self._quiet):
            print ("Firmware update time including overhead: %f" % (fimrware_end - firmware_start))
            print ("Firmware updated.")
        return NrfDfuErr.SUCCESS
Exemplo n.º 13
0
    smu.write('SENS:FUNC "VOLT"')
    smu.output_disable()
    smu.set_source_current()
    smu.set_current_drain_microamp(0)
    smu.output_enable()

rtt = API.API('NRF52')
rtt.open()
rtt.connect_to_emu_without_snr()

if (write_firmware):
    hex_file_path = '.\\hex\\ppk_nrfconnect.hex'
    print("Erasing")
    rtt.erase_all()
    print("Erased")
    application = Hex.Hex(hex_file_path)  # Parsing hex file into segments
    print("Flashing")
    for segment in application:
        print("...")
        rtt.write(segment.address, segment.data, True)
    print("Flashed!")

ppk = ppkapi(rtt, logprint=False)
ppk.connect()
ppk.vdd_set(3000)
ppk.clear_user_resistors()
ppk.average_measurement_stop()

ppk.average_measurement_start()

board_id = ppk.get_connected_board_id()