def test_programming(self): settings = Settings.current() serial_ports = BLEDriver.enum_serial_ports() # Check that from enumeration matches # kits provided from settings found_ports = list(map(lambda port: port.port, serial_ports)) for serial_port in settings.serial_ports: self.assertIn(serial_port, found_ports) for serial_port in serial_ports: if serial_port.port in settings.serial_ports: serial_number = serial_port.serial_number logger.info("%s/%s deleting existing firmware", serial_port.port, serial_number) flasher = Flasher(serial_port=serial_port.port) flasher.erase() self.assertFalse( flasher.fw_check(), "#{} must be programmed because it is erased".format( serial_number), ) flasher.fw_flash() logger.info("%s/%s programmed", serial_port.port, serial_number) self.assertTrue( flasher.fw_check(), "#{} is programmed, shall not be programmed again".format( serial_number), ) # Try to use the device with leading zeroes in serial number removed flasher = Flasher(snr=serial_port.serial_number.lstrip('0')) flasher.reset() logger.info("%s/%s programmed successfully", serial_port.port, serial_number)
def flash_connectivity(comport, jlink_snr): flasher = Flasher(serial_port=comport, snr=jlink_snr) if flasher.fw_check(): print("Board already flashed with connectivity firmware.") else: print("Flashing connectivity firmware...") flasher.fw_flash() print("Connectivity firmware flashed.") flasher.reset() time.sleep(1)
def ble(package, conn_ic_id, port, connect_delay, name, address, jlink_snr, flash_connectivity): """ Perform a Device Firmware Update on a device with a bootloader that supports BLE DFU. This requires a second nRF device, connected to this computer, with connectivity firmware loaded. The connectivity device will perform the DFU procedure onto the target device. """ ble_driver_init(conn_ic_id) if name is None and address is None: name = 'DfuTarg' click.echo( "No target selected. Default device name: {} is used.".format( name)) if port is None and jlink_snr is not None: port = get_port_by_snr(jlink_snr) elif port is None: port = enumerate_ports() if port is None: click.echo( "\nNo Segger USB CDC ports found, please connect your board.") return if flash_connectivity: flasher = Flasher(serial_port=port, snr=jlink_snr) if flasher.fw_check(): click.echo("Board already flashed with connectivity firmware.") else: click.echo("Flashing connectivity firmware...") flasher.fw_flash() click.echo("Connectivity firmware flashed.") flasher.reset() time.sleep(1) logger.info("Using connectivity board at serial port: {}".format(port)) ble_backend = DfuTransportBle(serial_port=str(port), target_device_name=str(name), target_device_addr=str(address)) ble_backend.register_events_callback(DfuEvent.PROGRESS_EVENT, update_progress) dfu = Dfu(zip_file_path=package, dfu_transport=ble_backend, connect_delay=connect_delay) if logger.getEffectiveLevel() > logging.INFO: with click.progressbar(length=dfu.dfu_get_total_size()) as bar: global global_bar global_bar = bar dfu.dfu_send_images() else: dfu.dfu_send_images() click.echo("Device programmed.")
def main(port): descs = BLEDriver.enum_serial_ports() print("enum_serial_ports: {} serial ports found".format(len(descs))) for i, d in enumerate(descs): print("\nSerial port #{}:".format(i)) print("|") print("|- Port: \"{}\"".format(d.port)) print("|- Manufacturer: \"{}\"".format(d.manufacturer)) print("|- Serial Number: \"{}\"".format(d.serial_number)) print("|- PnP ID: \"{}\"".format(d.pnp_id)) print("|- Location ID: \"{}\"".format(d.location_id)) print("|- Vendor ID: \"{}\"".format(d.vendor_id)) print("|_ Product ID: \"{}\"".format(d.product_id)) if port != None: flasher = Flasher(serial_port=port) if flasher.fw_check(): print("Port \"{}\" already flashed with connectivity firmware". format(port)) else: print("Flashing Port \"{}\"".format(port)) flasher.fw_flash() print("Firmware flashed")
data = conn.recv(1024) outbuf = [ord(x) for x in data] b.write_data(outbuf) #came out of loop conn.close() args.name = ' '.join(args.name) comport = args.com[0] jlink_snr = args.snr[0] flash_connectivity = True logging.basicConfig(format='%(message)s', level=logging.INFO) if flash_connectivity: flasher = Flasher(serial_port=comport, snr = jlink_snr) if flasher.fw_check(): logger.info("Board already flashed with connectivity firmware.") else: logger.info("Flashing connectivity firmware...") flasher.fw_flash() logger.info("Connectivity firmware flashed.") flasher.reset() time.sleep(1) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print 'Socket created'