def find_greatfet(args): """ Finds a GreatFET matching the relevant arguments.""" # If we're prorgamming via DFU mode, look for a device that sports the DFU stub. # Note that we only support a single DFU-mode device for now. if args.dfu: return GreatFET(serial_number=DFU_STUB_SERIAL) # If we have an index argument, grab _all_ greatFETs and select by index. elif args.index: # Find _all_ GreatFETs... devices = GreatFET(find_all=True) # ... and then select the one with the provided index. if len(devices) <= args.index: raise DeviceNotFoundError return devices[args.index] # If we have a serial number, look only for a single device. Theoretically, # we should never have more than one GreatFET with the same serial number. # Technically, this is violable, but libusb doesn't properly handle searching # by serial number if there are multiple devices with the same one, so we # enforce this. else: return GreatFET(serial_number=args.serial)
class source(gr.basic_block): """ docstring for block source """ def __init__(self, serial=None): gr.basic_block.__init__(self, name="source", in_sig=None, out_sig=[numpy.byte]) self.history = [] try: # self.device = GreatFET(serial_number=serial) self.device = GreatFET() except greatfet.errors.DeviceNotFoundError: raise self.device.vendor_request_out(vendor_requests.SDIR_START) def general_work(self, input_items, output_items): if len(self.history) < len(output_items[0]): self.history.extend(self.device.device.read(0x81, 0x4000, 1000)) out_len = min(len(output_items[0]), len(self.history)) output_items[0][:out_len] = numpy.array(self.history[:out_len], dtype=numpy.byte) self.history = self.history[out_len:] return out_len
def main(): from greatfet.utils import GreatFETArgumentParser # Set up a simple argument parser. parser = GreatFETArgumentParser( description="Utility for experimenting with GreatFET's DAC") parser.add_argument('-S', '--set', nargs=1, type=int, help="DAC value to set on ADC0_0 (0-1023)") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.set: set(device, args.set[0])
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser(description="Utility for I2C communication via GreatFET") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") parser.add_argument('-z', '--scan', action='store_true', help="Scan all possible i2c addresses") parser.add_argument('-a', '--address', nargs=1, type=str, help="Address to transmit data to over the I2C Bus") parser.add_argument('-t', '--transmit', metavar='data', default=[], help="Data to transmit over the I2C Bus") parser.add_argument('-r', '--receive_length', default=1, help="Number of bytes expecting to receive from the I2C Bus") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.scan: scan(device, log_function) if args.address: transmit(device, args.address[0], args.transmit, int(args.receive_length), log_function)
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="JTAG debug utility for MSP430") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) print( device.comms._vendor_request_in(vendor_requests.MSP430_JTAG, length=1))
def __init__(self, serial=None): gr.basic_block.__init__(self, name="source", in_sig=None, out_sig=[numpy.byte]) self.history = [] try: # self.device = GreatFET(serial_number=serial) self.device = GreatFET() except greatfet.errors.DeviceNotFoundError: raise self.device.vendor_request_out(vendor_requests.SDIR_START)
def main(): logfile = 'log.bin' # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Logic analyzer implementation for GreatFET") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) device.apis.logic_analyzer.start() time.sleep(1) f = open(args.filename, 'wb') try: while True: d = device.comms.device.read(0x81, 16384, 1000) f.write(d) except KeyboardInterrupt: pass device.apis.logic_analyzer.stop()
def main(): from greatfet.utils import GreatFETArgumentParser # Set up a simple argument parser. parser = GreatFETArgumentParser( description="Utility for I2C communication via GreatFET") parser.add_argument( '-a', '--address', nargs=1, type=ast.literal_eval, help="7-bit address for communication over the I2C Bus") parser.add_argument( '-r', '--read', default=0, help="Number of bytes expecting to receive from the I2C Bus") parser.add_argument('-w', '--write', nargs='*', type=ast.literal_eval, default=[], help="Bytes to send over the I2C Bus") parser.add_argument('-z', '--scan', action='store_true', help="Scan all possible i2c addresses") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.scan: scan(device, log_function) if args.write: write(device, args.address[0], args.write, log_function) if args.read: read(device, args.address[0], int(args.read), log_function)
def main(): logfile = 'log.bin' parser = argparse.ArgumentParser( description="Utility for experimenting with GreatFET's ADC") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") parser.add_argument('-a', dest='adc', action='store_true', help="Use internal ADC") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.adc: device.vendor_request_out(vendor_requests.ADC_INIT) #else: # device.vendor_request_out(vendor_requests.SDIR_RX_START) while True: data = device.vendor_request_in(vendor_requests.ADC_READ, length=2) print('%d' % (data[1] << 8 | data[0])) time.sleep(1) if not args.adc: device.vendor_request_out(vendor_requests.SDIR_RX_STOP)
def __init__(self): tk.Tk.__init__(self) self.black_button_image = tk.PhotoImage(file='icons/black_button.png') self.green_button_image = tk.PhotoImage(file='icons/green_button.png') self.green_zero_button_image = tk.PhotoImage( file='icons/green_zero_button.png') self.green_one_button_image = tk.PhotoImage( file='icons/green_one_button.png') self.red_button_image = tk.PhotoImage(file='icons/red_button.png') self.red_zero_button_image = tk.PhotoImage( file='icons/red_zero_button.png') self.red_one_button_image = tk.PhotoImage( file='icons/red_one_button.png') # initialize the window w = 1250 h = 930 self.wm_title("GreatFET Test Panel") self.geometry("%dx%d+%d+%d" % (w, h, 0, 0)) # set size and position of window self.resizable(width=False, height=False) menubar = PanelMenu(self) self.config(menu=menubar) self.canvas = PanelCanvas(self) self.status = StatusBar(self) self.gf = GreatFET() hardware._init_board(self)
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Utility for gathering information about connected GreatFETs") parser.add_argument('-A', '--api', dest='print_apis', action='store_true', help="Print information about each device's supported APIs.") parser.add_argument('-a', '--all', dest='print_all', action='store_true', help="Print all available information about the device.") parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help="Prints only the serial numbers of detected GreatFETs") args = parser.parse_args() # Try to find all existing devices devices = GreatFET(find_all=True) if not devices: print('No GreatFET devices found!', file=sys.stderr) sys.exit(errno.ENODEV) # Print the board's information... for device in devices: # If we're in quiet mode, print only the serial number and abort. if args.quiet: print(device.serial_number()) continue # Otherwise, print the core information. print_core_info(device) # If desired, print all APIs. if args.print_apis or args.print_all: print_apis(device) print(" ")
def __init__(self, pin, *, frequency=750, duty_cycle=0, variable_frequency=False): """This class makes use of the GreatFET One's Pattern Generator to create a Simulated Pulse width modulation. The way that the Pattern Generator works is that takes a pattern in the form of bytes and will repeat the output. The trick to simulate PWM is to generate the correct byte pattern for the correct channel. Args: pin (Pin): CircuitPython Pin object to output to duty_cycle (int) : The fraction of each pulse which is high. 16-bit frequency (int) : target frequency in Hertz (32-bit) Returns: PWMOut: PWMOut object. Raises: PWMError: if an I/O or OS error occurs. TypeError: if `channel` or `pin` types are invalid. ValueError: if PWM channel does not exist. """ self._gf = GreatFET() if variable_frequency: raise NotImplemented( "Variable Frequency is not currently supported.") self._pattern = None self._channel = None self._enable = False self._open(pin, duty_cycle, frequency)
def __init__( self, portid, baudrate=9600, bits=8, parity=None, stop=1, timeout=1000, read_buf_len=None, flow=None, ): self._gf = GreatFET() self._uart = _UART( self._gf, baud=baudrate, data_bits=bits, stop_bits=stop, parity=parity, uart_number=portid, ) if flow is not None: # default None raise NotImplementedError( "Parameter '{}' unsupported on GreatFET One".format("flow") )
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Periodically print temperature from DS18B20 sensor") parser.add_argument('-S', dest='s20', action='store_true', help='DS18S20') parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) while True: data = device.vendor_request_in(vendor_requests.DS18B20_READ, length=2, timeout=2000) # temperature data is 16 bit signed temp = struct.unpack('<h', data)[0] if args.s20: temp /= 2.0 else: temp /= 16.0 print(time.strftime("%H:%M:%S"), temp, '{:.01f}'.format(temp * 9 / 5 + 32)) time.sleep(1)
def main(): from greatfet.utils import GreatFETArgumentParser # Set up a simple argument parser. parser = GreatFETArgumentParser( description="Utility for LED configuration on GreatFET") parser.add_argument('-t', '--toggle', nargs='*', type=ast.literal_eval, default=[], help="LED numbers to toggle (0-3)") parser.add_argument('--on', nargs='*', type=ast.literal_eval, default=[], help="LED numbers to turn on (0-3)") parser.add_argument('--off', nargs='*', type=ast.literal_eval, default=[], help="LED numbers to turn off (0-3)") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.toggle: toggle(device, args.toggle, log_function) if args.on: on(device, args.on, log_function) if args.off: off(device, args.off, log_function)
def main(): logfile = 'log.bin' # logfile = '/tmp/fifo' # Set up a simple argument parser. parser = argparse.ArgumentParser(description="Utility for experimenting with GreatFET's ADC") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") parser.add_argument('-a', dest='adc', action='store_true', help="Use internal ADC") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.adc: device.vendor_request_out(vendor_requests.ADC_INIT) else: device.vendor_request_out(vendor_requests.SDIR_RX_START) time.sleep(1) print(device.device) with open(args.filename, 'wb') as f: try: while True: d = device.device.read(0x81, 0x4000, 1000) # print(d) f.write(d) except KeyboardInterrupt: pass if not args.adc: device.vendor_request_out(vendor_requests.SDIR_RX_STOP)
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser(description="Utility for flashing the GreatFET's onboard SPI flash") parser.add_argument('-i', '--info', dest='info', action='store_true', help="Read Jedec information from target") parser.add_argument('-d', '--dump', dest='dump', metavar='<filename>', type=str, help="Dump flash into file") parser.add_argument('-a', '--address', metavar='<n>', default=0, type=int, help="Flash dump starting address") parser.add_argument('-l', '--length', metavar='<n>', type=int,default=None, help="number of bytes to read (default: flash size)") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() # If we don't have an option, print our usage. if not args.info and not args.dump: parser.print_help() sys.exit() # Determine whether we're going to log to the stdout, or not at all. log_function = log_verbose if args.verbose else log_silent # Create our GreatFET connection. try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) device.vendor_request_out(vendor_requests.SPI_INIT) if args.info: spi_info(device, log_function=log_verbose) if args.dump: dump_flash(device, filename=args.dump, address=args.address, length=args.length, log_function=log_verbose)
def __init__(self, port=None, state=None, switch=None): gr.sync_block.__init__(self, name="GreatFET GPIO Sink", in_sig=[np.float32, np.float32, np.float32], out_sig=[]) gf = GreatFET() self.gf = gf self.port = port self.state = state self.switch = switch
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Utility for flashing the GreatFET's onboard SPI flash") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) while True: data = device.vendor_request_in(vendor_requests.DS18B20_READ, length=2) # print(data) temp = (data[1] << 8 | data[0]) / 16.0 print(time.strftime("%H:%M:%S"), temp) time.sleep(1)
def main(): try: device = GreatFET() except DeviceNotFoundError: print('No GreatFET devices found!', file=sys.stderr) sys.exit(errno.ENODEV) # Print the board's information... print("Found a {}!".format(device.board_name())) print(" Board ID: {}".format(device.board_id())) print(" Firmware version: {}".format(device.firmware_version())) print(" Part ID: {}".format(device.part_id())) print(" Serial number: {}".format(device.serial_number()))
def main(): parser = argparse.ArgumentParser( description="Utility for reading GreatFET debug information") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) #Read and print the logs logs = device.read_debug_ring() log_function("Ring buffer contained {} bytes of data:\n".format(len(logs))) print(logs)
def work(self, input_items, output_items): gf = GreatFET() in0 = input_items[0] in1 = input_items[1] gpio = str(int(in0[0] + 4)) pin_string = 'J1_P' + gpio pin = gf.gpio.get_pin(pin_string) pin.set_direction(gf.gpio.DIRECTION_OUT) if (in1[0] == float(1)): pin.write(True) if (in1[0] != float(1)): pin.write(False) # <+signal processing here+> return len(input_items[0])
def main(): # Try to find all existing devices devices = GreatFET(find_all=True) if not devices: print('No GreatFET devices found!', file=sys.stderr) sys.exit(errno.ENODEV) # Print the board's information... for device in devices: print("Found a {}!".format(device.board_name())) print(" Board ID: {}".format(device.board_id())) print(" Firmware version: {}".format(device.firmware_version())) print(" Part ID: {}".format(device.part_id())) print(" Serial number: {}".format(device.serial_number())) print(" ")
def main(): parser = argparse.ArgumentParser(description="Drive ADF7242 via SPI") parser.add_argument('-r', '--read-register', dest='read_reg', metavar='<addr>', default=None, type=auto_int, help="Read register") parser.add_argument('-w', '--write-register', dest='write_reg', default=None, nargs=2, metavar=('<addr>', '<value>'), type=auto_int, help="Write register") parser.add_argument('-c', '--command', dest='command', default=None, type=auto_int, metavar='<command>', help="SPI command") parser.add_argument('-S', '--status', action='store_true', help='Get status byte') parser.add_argument('-t', '--temperature', action='store_true', help='Read temperature') parser.add_argument('--reset', action='store_true', help='Reset ADF7242') parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() # Determine whether we're going to log to the stdout, or not at all. log_function = log_verbose if args.verbose else log_silent # Create our GreatFET connection. try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) device.vendor_request_out(vendor_requests.SPI_INIT) if args.reset: adf7242_command(device, 0xC7) if args.read_reg: print('Register value: {:02x}'.format(adf7242_read_reg(device, args.read_reg))) if args.write_reg: adf7242_write_reg(device, args.write_reg[0], args.write_reg[1]) if args.command: adf7242_command(device, args.command) if args.status: print('Status: {:02x}'.format(adf7242_status(device))) if args.temperature: temp = adf7242_temperature(device) temp_f = temp * 9 / 5 + 32 print('Temperature: {:0.1f} °F / {:.01f} °C'.format(temp_f, temp))
def find_tester(self): devices = [] timeout = time.time() + 30 while len(devices) < 1: try: devices = GreatFET(find_all=True) except: self.log(traceback.format_exc()) self.print("Unexpected error: %s" % sys.exc_info()[0]) pass if time.time() >= timeout: self.print( 'FAIL 10: Tester not found. Connect Tester to Narcissus and connect only Tester to this host with USB. Ensure no EUT is present when connecting Tester to host via USB.' ) sys.exit(errno.ENODEV) time.sleep(1) if len(devices) > 1: self.fail( 'FAIL 20: More than one GreatFET found. Connect only Tester to this host with USB.' ) # Print the Tester's information... self.tester = devices[0] self.print("Found Tester {}.".format(self.tester.board_name())) self.print(" Board ID: {}".format(self.tester.board_id())) self.print(" Firmware version: {}".format( self.tester.firmware_version())) self.print(" Part ID: {}".format(self.tester.part_id())) self.print(" Serial number: {}".format(self.tester.serial_number())) self.print(" ") self.setup_tester_pins() self.tester_pins[self.other_pins["U4_E"]].write(1) self.tester_pins[self.other_pins["U4_E"]].set_direction( self.tester.gpio.DIRECTION_OUT) self.tester_pins[self.other_pins["U4_S0"]].set_direction( self.tester.gpio.DIRECTION_OUT) self.tester_pins[self.other_pins["U4_S1"]].set_direction( self.tester.gpio.DIRECTION_OUT) self.tester_pins[self.other_pins["U4_S2"]].set_direction( self.tester.gpio.DIRECTION_OUT)
def __init__(self): self._gf = GreatFET() self._frequency = None self.buffer_size = 255 self._presets = { 204000: (100, 9), 408000: (100, 4), 680000: (100, 2), 1020000: (100, 1), 2040000: (50, 1), 4250000: (24, 1), 8500000: (12, 1), 12750000: (8, 1), 17000000: (6, 1), 20400000: (2, 4), 25500000: (4, 1), 34000000: (2, 2), 51000000: (2, 1), 102000000: (2, 0), }
def main(): logfile = 'log.bin' # Set up a simple argument parser. parser = argparse.ArgumentParser(description="Utility for flashing the GreatFET's onboard SPI flash") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="Write data to file", default=logfile) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_START) time.sleep(1) f = open(args.filename, 'wb') try: while True: d = device.device.read(0x81, 16384, 1000) f.write(d) except KeyboardInterrupt: pass device.vendor_request_out(vendor_requests.LOGIC_ANALYZER_STOP)
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Utility for flashing the GreatFET's onboard SPI flash") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) # 0 - 1024 dac_value = 1024 device.vendor_request_out(vendor_requests.DAC_SET, value=dac_value) print("DAC value set to", dac_value)
#!/usr/bin/env python3 from greatfet import GreatFET from greatfet.peripherals.gpio import DIRECTION_IN, DIRECTION_OUT from greatfet.boards.one import GreatFETOne gf = GreatFET() class Board(): def __init__(self, ports={}): self.ports = ports class Port(): def __init__(self, name, size, unclickable_pins=[]): self.name = name self.pins = {} self.unclickable_pins = unclickable_pins for i in range(1, size): if i not in self.unclickable_pins: self.pins[i] = Pin(i, self) # pin number needs to be a string class Pin(): def __init__(self, number, port, mode=0, state=0): self.name = "P%d" % number self.number = number self.port = port self.tuple = GreatFETOne.GPIO_MAPPINGS.get(port.name + "_" + self.name) self.mode = mode # input/output (i, o)
def main(): logfile = 'log.bin' # logfile = '/tmp/fifo' # Set up a simple argument parser. parser = argparse.ArgumentParser(description="Utility for experimenting with GreatFET's ADC") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-S', dest='samplerate', metavar='<samplerate>', type=int, help="Sample rate for IR Tx", default=1000000) parser.add_argument('-f', dest='filename', metavar='<filename>', type=str, help="File to read or write", default=logfile) parser.add_argument('-r', dest='receive', action='store_true', help="Write data to file") parser.add_argument('-R', dest='repeat', action='store_true', help="Repeat file data (tx only)") parser.add_argument('-v', dest='verbose', action='store_true', help="Increase verbosity of logging") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) if args.receive: device.vendor_request_out(vendor_requests.SDIR_RX_START) time.sleep(1) with open(args.filename, 'wb') as f: try: while True: d = device.device.read(0x81, 0x4000, 1000) # print(d) f.write(d) except KeyboardInterrupt: pass device.vendor_request_out(vendor_requests.SDIR_RX_STOP) else: index = args.samplerate & 0xFFFF value = (args.samplerate >> 16) & 0xFFFF device.vendor_request_out(vendor_requests.SDIR_TX_START, value=value, index=index) time.sleep(1) with open(args.filename, 'rb') as f: try: while True: data = f.read(0x4000) if len(data) != 0x4000: if args.repeat: print("End of file reached. Looping") f.seek(0,0) else: break if len(data) == 0: data = f.read(0x4000) # print(data[:10]) device.device.write(0x02, data) except KeyboardInterrupt: pass device.vendor_request_out(vendor_requests.SDIR_TX_STOP)
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Utility for flashing the GreatFET's onboard SPI flash") parser.add_argument('-a', '--address', metavar='<n>', type=int, help="starting address (default: 0)", default=0) parser.add_argument('-l', '--length', metavar='<n>', type=int, help="number of bytes to read (default: {})".format(MAX_FLASH_LENGTH), default=MAX_FLASH_LENGTH) parser.add_argument('-r', '--read', dest='read', metavar='<filename>', type=str, help="Read data into file", default='') parser.add_argument('-w', '--write', dest='write', metavar='<filename>', type=str, help="Write data from file", default='') parser.add_argument('-s', '--serial', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument('-q', '--quiet', dest='quiet', action='store_true', help="Suppress messages to stdout") parser.add_argument('-R', '--reset', dest='reset', action='store_true', help="Reset GreatFET after performing other operations.") args = parser.parse_args() # Validate our options. # If we don't have an option, print our usage. if not any((args.read, args.write, args.reset,)): parser.print_help() sys.exit(0) # Determine whether we're going to log to the stdout, or not at all. log_function = log_silent if args.quiet else log_verbose # Create our GreatFET connection. try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format(device.board_name(), device.serial_number())) except DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format(args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) # Ensure that the device supports an onboard SPI flash. try: device.onboard_flash except AttributeError: print("The attached GreatFET ({}) doesn't appear to have an SPI flash to program!".format(device.board_name()), file=sys.stderr) sys.exit(errno.ENOSYS) # If we have a write command, write first, to match the behavior of hackrf_spiflash. if args.write: log_function("Writing data to SPI flash...") spi_flash_write(device, args.write, args.address, log_function) log_function("Write complete!") if not args.reset: log_function("Reset not specified; new firmware will not start until next reset.") # Handle any read commands. if args.read: log_function("Reading data from SPI flash...") spi_flash_read(device, args.read, args.address, args.length, log_function) log_function("Read complete!") # Finally, reset the target if args.reset: log_function("Resetting GreatFET...") device.reset() log_function("Reset complete!")
# along with this program; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 51 Franklin Street, # Boston, MA 02110-1301, USA. # from __future__ import print_function import sys import greatfet from greatfet import GreatFET from greatfet.protocol import vendor_requests if __name__ == '__main__': device = GreatFET() if not device: print('No GreatFET devices found!') sys.exit() # Print the board's information... print("Found a {}!".format(device.board_name())) print(" Board ID: {}".format(device.board_id())) print(" Firmware version: {}".format(device.firmware_version())) print(" Part ID: {}".format(device.part_id())) print(" Serial number: {}".format(device.serial_number())) # ... and toggle it's third LED, for fun. device.vendor_request_out(vendor_requests.LED_TOGGLE, 3) # Dev note: you can still easily use this to test low-level interfaces.
def main(): # Set up a simple argument parser. parser = argparse.ArgumentParser( description="Logic analyzer implementation for GreatFET") parser.add_argument('-s', dest='serial', metavar='<serialnumber>', type=str, help="Serial number of device, if multiple devices", default=None) parser.add_argument( '-o', '-b', '--binary', dest='binary', metavar='<filename>', type=str, help="Generate a binary file contianing the captured data.") parser.add_argument('-p', '--pulseview', dest='pulseview', metavar="<filename>", type=str, help="Generate a PulseView session file.") parser.add_argument('-v', dest='verbose', action='store_true', help="Write data from file") args = parser.parse_args() capture_data_name = 'logic-1' log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) device.apis.logic_analyzer.start() time.sleep(1) _, path = tempfile.mkstemp(None, None, os.getcwd()) if args.binary: bin_file_name = arc_name = args.output sr_name = args.output + ".sr" else: bin_file_name = path print("Press Ctrl+C to stop reading data from device") try: with open(bin_file_name, "wb") as bin_file: try: while True: d = device.comms.device.read(0x81, 16384, 1000) bin_file.write(d) except KeyboardInterrupt: print() if args.binary: print("Binary data written to file '%s'" % args.output) if args.pulseview: metadata_str = "[device 1]\n" \ "capturefile={}\n" \ "total probes=8\n" \ "samplerate=17 MHz\n" \ "total analog=0\n" \ "probe1=SGPIO0\n" \ "probe2=SGPIO1\n" \ "probe3=SGPIO2\n" \ "probe4=SGPIO3\n" \ "probe5=SGPIO4\n" \ "probe6=SGPIO5\n" \ "probe7=SGPIO6\n" \ "probe8=SGPIO7\n" \ "unitsize=1\n".format(capture_data_name) # pulseview compatible .sr archive with ZipFile(args.pulseview, "w") as zip: zip.write(bin_file_name, arcname='logic-1') zip.writestr("metadata", metadata_str) zip.writestr("version", "2") print("Pulseview compatible session file created: '%s'" % args.pulseview) finally: try: os.remove(path) except OSError: pass device.apis.logic_analyzer.stop()
def main(): from greatfet.utils import GreatFETArgumentParser # Set up a simple argument parser. parser = GreatFETArgumentParser( description="JTAG debug utility for MSP430") parser.add_argument('-I', '--identify', dest='ident', action='store_true', help="Show target identification") parser.add_argument('-e', '--erase', dest='erase', action='store_true', help="Erase target flash") parser.add_argument('-E', '--erase_info', dest='erase_info', action='store_true', help="Erase target info flash") parser.add_argument('-f', '--flash', dest='flash', type=str, metavar='<filename>', help="Write target flash") parser.add_argument('-V', '--verify', dest='verify', type=str, metavar='<filename>', help="Verify target flash") parser.add_argument('-d', '--dump', dest='dump', type=str, metavar='<filename>', help="Dump target flash") parser.add_argument('-r', '--run', dest='run', action='store_true', help="Run target device") parser.add_argument('-R', '--peek', dest='peek', action='store_true', help="Read from memory location") parser.add_argument('-W', '--poke', dest='poke', type=ast.literal_eval, metavar='<value>', help="Write to memory location") parser.add_argument( '-a', '--address', dest='address', default=0, type=ast.literal_eval, metavar='<address>', help="Address for peek/poke/flash/dump/verify actions (default 0x00)") parser.add_argument('-l', '--length', dest='length', type=ast.literal_eval, metavar='<length>', help="Length for peek/dump actions in bytes") parser.add_argument('-t', '--test', dest='test', action='store_true', help="Test MSP430 JTAG functions (destructive)") args = parser.parse_args() log_function = log_verbose if args.verbose else log_silent try: log_function("Trying to find a GreatFET device...") device = GreatFET(serial_number=args.serial) log_function("{} found. (Serial number: {})".format( device.board_name(), device.serial_number())) except greatfet.errors.DeviceNotFoundError: if args.serial: print("No GreatFET board found matching serial '{}'.".format( args.serial), file=sys.stderr) else: print("No GreatFET board found!", file=sys.stderr) sys.exit(errno.ENODEV) jtag = msp430_jtag.JTAG_MSP430(device) jtag_id = jtag.start() if jtag_id in (0x89, 0x91): log_function("Target dentified as 0x%02x." % jtag_id) else: print("Error, misidentified as 0x%02x." % jtag_id) print("Check wiring, as this should be 0x89 or 0x91.") sys.exit(errno.ENODEV) if args.ident: print("Identifies as %s (0x%04x)" % (jtag.ident_string(), jtag.ident())) if args.dump: if args.length: end = args.address + args.length else: end = 0xffff log_function("Dumping from 0x%04x to 0x%04x to %s." % (args.address, end, args.dump)) with open(args.dump, 'wb') as f: address = args.address while address < end: data = jtag.peek_block(address) f.write(data) address += len(data) if args.erase: log_function("Erasing main flash memory.") jtag.erase_flash() if args.erase_info: log_function("Erasing info flash.") jtag.erase_info() if args.flash: with open(args.flash, 'rb') as f: address = args.address if args.length: end = address + args.length else: end = address + f.seek(0, 2) f.seek(0) log_function("Writing %d bytes of %s to 0x%04x." % (end - address, args.flash, address)) while address < end: if end - address < 0x400: block_size = end - address else: block_size = 0x400 data = f.read(block_size) result = jtag.poke_flash_block(address, data) address += block_size else: log_function("Flash contents written.") if args.verify: with open(args.verify, 'rb') as f: address = args.address if args.length: end = address + args.length else: end = address + f.seek(0, 2) f.seek(0) log_function("Verifying %d bytes of %s from 0x%04x." % (end - address, args.verify, address)) while address < end: if end - address < 0x400: block_size = end - address else: block_size = 0x400 data = jtag.peek_block(address, block_size) buffer = f.read(len(data)) if data != buffer: print("File does not match flash.") break address += len(data) else: print("Flash contents verified.") if args.poke: log_function("Writing 0x%04x to 0x%04x." % (args.poke, args.address)) written = jtag.poke(args.address, args.poke) if written != args.poke: print("Failed to write 0x%04x to 0x%04x" % (args.poke, args.address)) if args.peek: if args.length: length = args.length if length % 2: length += 1 else: length = 2 log_function("Reading %d bytes from 0x%04x." % (length, args.address)) values = jtag.peek(args.address, length) for i, v in enumerate(values): print("%04x: %04x" % (args.address + i * 2, v)) if args.run: log_function("Resuming target execution.") jtag.run() if args.test: log_function("Running test.") msp430_test(jtag)