def run(snr): """ Run example script. @param int snr: Specify serial number of DK to run example on. """ print('# Opening High Level API instance and initializing a probe handle.') # Initialize an API object. # Open the loaded DLL and connect to an emulator probe. with HighLevel.API() as api: # 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 device_info = probe.get_device_info() print(device_info) # RTT if probe.is_rtt_started() == False: probe.rtt_start() print("is_rtt_started", probe.is_rtt_started()) print("rtt_is_control_block_found", probe.rtt_is_control_block_found()) print("rtt_read_channel_count", probe.rtt_read_channel_count()) print( "rtt_read_channel_info - UP_DIRECTION", probe.rtt_read_channel_info( 0, Parameters.RTTChannelDirection.UP_DIRECTION)) print( "rtt_read_channel_info - DOWN_DIRECTION", probe.rtt_read_channel_info( 0, Parameters.RTTChannelDirection.DOWN_DIRECTION)) print("rtt_read", probe.rtt_read(0, 1024)) print('# Example done...')
def run(serial_device_name_uart0, serial_device_name_uart1, nrf9160_modem_firmware_zip_location): """ Run example script. @param string serial_device_name_uart0: Specify Thingy:91 UART0 serial port name. @param string serial_device_name_uart1: Specify Thingy:91 UART1 serial port name. @param string nrf9160_modem_firmware_zip_location: Specify the location of the modem firmware zip file """ # Verify that the firmware zip exists if not os.path.exists(nrf9160_modem_firmware_zip_location): raise Exception( "Invalid path to modem firmware zip file provided. Skipping nrf9160 modem device firmware upgrade example." ) print( '# nrf9160 modem firmware upgrade over serial port example started...') # Configure logging to see HighLevel API output logging.basicConfig(level=logging.INFO, format="%(message)s") # Find the hex file to flash. It should be located in the same directory as this example file. module_dir, _ = os.path.split(__file__) hex_file_path = os.path.join( os.path.abspath(module_dir), r"nrf9160_pca20035_firmware_upgrade_app_0.1.0.hex") # Create our API instance with HighLevel.API() as api: # Program the nrf9160 device with the DFU server application using MCUBoot # This assumes the device is in serial recovery mode and is ready to be programmed print("Flashing nrf9160 modem DFU application") with HighLevel.MCUBootDFUProbe( api, serial_device_name_uart0) as mcuboot_probe: mcuboot_probe.program(hex_file_path) # Upload the modem firmware to the nrf9160 device start_time = time.time() with HighLevel.ModemUARTDFUProbe( api, serial_device_name_uart1) as modem_dfu_probe: modem_dfu_probe.program(nrf9160_modem_firmware_zip_location) modem_dfu_probe.verify(nrf9160_modem_firmware_zip_location) # Print upload time print("------------------------------------------------------------") print("The operation took {0:.2f} seconds ".format(time.time() - start_time)) print('# Example done...')
def _write_firmware(nrfjprog_probe, fw_hex): """Program and verify a hex file.""" program_options = HighLevel.ProgramOptions( erase_action=HighLevel.EraseAction.ERASE_ALL, reset=HighLevel.ResetAction.RESET_SYSTEM, verify=HighLevel.VerifyAction.VERIFY_READ) nrfjprog_probe.program(fw_hex, program_options)
def run(uart, modem_firmware_zip, baudrate): if not os.path.exists(modem_firmware_zip): raise Exception("Modem firmware zip file does not exist") logging.info('# modem firmware upgrade over serial port example started.') # Find the hex file to flash. It should be located in the same directory as # this example file. with HighLevel.API() as api: start_time = time.time() with HighLevel.ModemUARTDFUProbe(api, uart, baudrate) as modem_dfu_probe: modem_dfu_probe.program(modem_firmware_zip) modem_dfu_probe.verify(modem_firmware_zip) # Print upload time logging.info("-------------------------------------------------------") logging.info("The operation took {0:.2f} seconds ".format(time.time() - start_time))
def flash_modem_pkg(modem_zip, verify): start = time.time() with HighLevel.API(True) as api: snr = api.get_connected_probes() for s in snr: log.info("Establish board connection") log.info(f"Flashing '{modem_zip}' to board {s}") with HighLevel.IPCDFUProbe( api, s, HighLevel.CoProcessor.CP_MODEM) as probe: log.info(f"Programming '{modem_zip}'") probe.program(modem_zip) log.info("Programming complete") if verify: log.info("Verifying") probe.verify(modem_zip) log.info("Verifying complete") api.close() log.info(f"Completed in {time.time() - start} seconds")
def run(snr): """ Run example script. @param int snr: Specify serial number of DK to run example on. """ print('# Hex file programming example using pynrfjprog started...') print('# Opening High Level API instance and initializing a probe handle.') # Initialize an API object. # Open the loaded DLL and connect to an emulator probe. with HighLevel.API() as api: # 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() hex_file_path = find_blinky_hex(device_info.device_family.name, device_info.device_type.name) if hex_file_path is None: raise Exception( "Could not find example binary for device " + device_info.device_type.name.lower() + ".\n" + "This example may not support your device yet.") # 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.program(hex_file_path, program_options=program_options) print('# Application running. Your board should be blinking.') print('# Example done...')
def _connect_to_jlink(args): """Connect to the debug probe.""" api = HighLevel.API() api.open() connected_serials = api.get_connected_probes() if args.serial_number: if args.serial_number in connected_serials: connected_serials = [args.serial_number] else: print("error: serial_number not found ({})".format(args.serial_number)) _close_and_exit(api, -1) if not connected_serials: print("error: no debug probes found") _close_and_exit(api, -1) if len(connected_serials) > 1: print("error: multiple debug probes found, use --serial_number") _close_and_exit(api, -1) probe = HighLevel.DebugProbe(api, connected_serials[0], HighLevel.CoProcessor.CP_APPLICATION) return (api, probe)
def run(snr): """ Run example script. @param int snr: Specify serial number of DK to run example on. """ print('# Memory read and write 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. api = HighLevel.API( ) # Using with construction so there is no need to open or close the API class. print('# Opening High Level API instance and initializing a probe handle.') # Open the loaded DLL and connect to an emulator probe. If several are connected a pop up will appear. api.open() try: probe = HighLevel.DebugProbe(api, snr) try: # Erase all the flash of the device. print('# Erasing all flash in the microcontroller.') # api.erase supports several erase actions, including sector erase, erase all, and qspi erase options. probe.erase(HighLevel.EraseAction.ERASE_ALL) # Write to addresses 0x0 and 0x10. NVMC is used automatically whenever a write to flash is requested. print('# Writing 0xDEADBEEF to memory address 0x0.') probe.write(0x0, 0xDEADBEEF) print('# Writing 0xBAADF00D to memory address 0x10.') probe.write(0x10, 0xBAADF00D) # Read from addresses 0x0 and 0x10 and print the result. print( '# Reading memory address 0x0 and 0x10, and print to console') print('Address 0x0 contains: ', hex(probe.read(0x0))) print('Address 0x10 contains: ', hex(probe.read(0x10))) finally: probe.close() finally: api.close() print('# Example done...')
def check(): api = HighLevel.API() api.open() # Find connected probes probes = api.get_connected_probes() if len(probes) != 1: print("Error, expected 1 nRF device to be connected, found: " + str(len(probes))) sys.exit(1) snr = probes[0] # To program J-Link probe at snr <snr>: probe = HighLevel.DebugProbe(api, snr) # Read MAC Address addr0 = probe.read(FICR_BASE + DEVICEADDR0) addr1 = probe.read(FICR_BASE + DEVICEADDR1) mac = ficr2mac(addr0, addr1) mac_str = mac2str(mac) print('DeviceAddr: ', mac_str) parser = argparse.ArgumentParser("Flash and print label for NRF52 device") parser.add_argument('--text', type=str, help="Text") parser.add_argument('--print', type=str, help="Print label from template file. 'xx:xx:xx:xx:xx:xx' is replaced with MAC address and 'SENSOR' is replaced with text argument" ) parser.add_argument('--fw', type=str, help='Firmware to flash') args = parser.parse_args() if args.print: labelXml = "" with open(args.print, 'r') as myfile: labelXml = myfile.read() labelXml = labelXml.replace("xx:xx:xx:xx:xx:xx", mac_str) if args.text: labelXml = labelXml.replace("SENSOR", args.text) else: labelXml = labelXml.replace("SENSOR", "") print(labelXml) url = "https://127.0.0.1:41951/DYMO/DLS/Printing/PrintLabel" labelData = { "printerName": "DYMO LabelWriter 450", "labelXml": labelXml, "labelSetXml": "" } x = requests.post(url, data = labelData, verify = False) print(x.text) # Program device if args.fw: print("Flashing nRF52 device") probe.erase(HighLevel.EraseAction.ERASE_ALL) probe.program(args.fw) print("Verifying nRF52 device") probe.verify(args.fw) print("Done.") probe.reset(HighLevel.ResetAction.RESET_PIN) api.close()