Exemplo n.º 1
0
def _main():
    parser = argparse.ArgumentParser(description="Simple command line"
                                     " interface for UPDI programming")
    parser.add_argument("-d",
                        "--device",
                        choices=Device.get_supported_devices(),
                        required=True,
                        help="Target device")
    parser.add_argument(
        "-c",
        "--comport",
        required=True,
        help="Com port to use (Windows: COMx | *nix: /dev/ttyX)")
    parser.add_argument("-e",
                        "--erase",
                        action="store_true",
                        help="Perform a chip erase (implied with --flash)")
    parser.add_argument("-b", "--baudrate", type=int, default=115200)
    parser.add_argument("-f", "--flash", help="Intel HEX file to flash.")
    parser.add_argument("-fs",
                        "--fuses",
                        action="append",
                        nargs="*",
                        help="Fuse to set (syntax: fuse_nr:0xvalue)")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="Set verbose mode")

    args = parser.parse_args(sys.argv[1:])

    if args.fuses is None and args.flash is None and not args.erase:
        print("No action (erase, flash or fuses)")
        sys.exit(0)

    if args.verbose:
        logging.basicConfig(
            format="%(asctime)s %(levelname)s:%(name)s %(message)s",
            level=logging.INFO)
    else:
        logging.basicConfig(format="%(levelname)s:%(name)s %(message)s",
                            level=logging.WARNING)

    nvm = UpdiNvmProgrammer(comport=args.comport,
                            baud=args.baudrate,
                            device=Device(args.device))

    try:
        nvm.enter_progmode()
    except:
        print("Device is locked. Performing unlock with chip erase.")
        nvm.unlock_device()

    nvm.get_device_info()

    if not _process(nvm, args):
        print("Error during processing")

    nvm.leave_progmode()
Exemplo n.º 2
0
def _main():
    if sys.version_info[0] < 3:
        print("WARNING: for best results use Python3")

    parser = argparse.ArgumentParser(description="Simple command line"
                                     " interface for UPDI programming")
    parser.add_argument("-d",
                        "--device",
                        choices=Device.get_supported_devices(),
                        required=True,
                        help="Target device")
    parser.add_argument(
        "-c",
        "--comport",
        required=True,
        help="Com port to use (Windows: COMx | *nix: /dev/ttyX)")
    parser.add_argument("-e",
                        "--erase",
                        action="store_true",
                        help="Perform a chip erase (implied with --flash)")
    parser.add_argument("-b", "--baudrate", type=int, default=115200)
    parser.add_argument("-f", "--flash", help="Intel HEX file to flash.")
    parser.add_argument("-r", "--reset", action="store_true", help="Reset")
    parser.add_argument("-i", "--info", action="store_true", help="Info")
    parser.add_argument("-fs",
                        "--fuses",
                        action="append",
                        nargs="*",
                        help="Fuse to set (syntax: fuse_nr:0xvalue)")
    parser.add_argument("-fr",
                        "--readfuses",
                        action="store_true",
                        help="Read out the fuse-bits")
    parser.add_argument("-fe",
                        "--eeprom",
                        help="Intel HEX file to write to EEPROM.")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="Set verbose mode")

    args = parser.parse_args(sys.argv[1:])

    if not any((args.fuses, args.flash, args.erase, args.reset, args.readfuses,
                args.info, args.eeprom)):
        print("No action (erase, flash, eeprom, reset, fuses or info)")
        sys.exit(0)

    if args.verbose:
        logging.basicConfig(format="%(levelname)s:%(name)s %(message)s",
                            level=logging.INFO)
    else:
        logging.basicConfig(format="%(levelname)s:%(name)s %(message)s",
                            level=logging.WARNING)

    nvm = UpdiNvmProgrammer(comport=args.comport,
                            baud=args.baudrate,
                            device=Device(args.device))
    if not args.reset:  # any action except reset
        # Reteieve info before building the stack to be sure its the correct device
        nvm.get_device_info()
        try:
            nvm.enter_progmode()
        except:
            print("Device is locked. Performing unlock with chip erase.")
            nvm.unlock_device()

        print("Device info: {0:s}".format(str(nvm.get_device_info())))

        if not _process(nvm, args):
            print("Error during processing")

    # Reset only needs this.
    nvm.leave_progmode()
Exemplo n.º 3
0
def _main():
    if sys.version_info[0] < 3:
        print("WARNING: for best results use Python3")

    parser = argparse.ArgumentParser(description="Simple command line"
                                     " interface for UPDI programming")
    parser.add_argument("-d",
                        "--device",
                        choices=Device.get_supported_devices(),
                        required=True,
                        help="Target device")
    parser.add_argument(
        "-c",
        "--comport",
        required=True,
        help="Com port to use (Windows: COMx | *nix: /dev/ttyX)")
    parser.add_argument("-e",
                        "--erase",
                        action="store_true",
                        help="Perform a chip erase (implied with --flash)")
    parser.add_argument("-b", "--baudrate", type=int, default=115200)
    parser.add_argument("-f", "--flash", help="Intel HEX file to flash.")
    parser.add_argument("-k",
                        "--batch",
                        action="store_true",
                        help="Batch flash with Micro-UPDI Programmer")

    parser.add_argument("-r", "--reset", action="store_true", help="Reset")
    parser.add_argument("-fs",
                        "--fuses",
                        action="append",
                        nargs="*",
                        help="Fuse to set (syntax: fuse_nr:0xvalue)")
    parser.add_argument("-fr",
                        "--readfuses",
                        action="store_true",
                        help="Read out the fuse-bits")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="Set verbose mode")

    args = parser.parse_args(sys.argv[1:])

    if not any(
        (args.fuses, args.flash, args.erase, args.reset, args.readfuses)):
        print("No action (erase, flash, reset or fuses)")
        sys.exit(0)

    if args.verbose:
        logging.basicConfig(format="%(levelname)s:%(name)s %(message)s",
                            level=logging.INFO)
    else:
        logging.basicConfig(format="%(levelname)s:%(name)s %(message)s",
                            level=logging.WARNING)

    if args.batch:

        nvm = UpdiNvmProgrammer(comport=args.comport,
                                baud=args.baudrate,
                                device=Device(args.device))

        nvm.setLEDs('off')

        while True:
            '''nvm = UpdiNvmProgrammer(comport=args.comport,
                            baud=args.baudrate,
                            device=Device(args.device))'''

            while not nvm.getBTN():
                time.sleep(0.016)

            state = False

            while nvm.getBTN():
                state = not state
                nvm.setLEDs('green' if state else 'off')
                time.sleep(0.055)

            nvm.setLEDs('yellow')

            try:
                nvm.application.datalink.start()
            except:
                nvm.setLEDs('red')
                while not nvm.getBTN():
                    time.sleep(0.016)
                continue

            if not args.reset:  # any action except reset
                try:
                    nvm.enter_progmode()
                except:
                    print(
                        "Device is locked. Performing unlock with chip erase.")
                    nvm.unlock_device()

                nvm.get_device_info()

                try:
                    if not _process(nvm, args):
                        print("Error during processing")
                        nvm.setLEDs('red')
                    else:
                        nvm.setLEDs('green')
                except:
                    nvm.setLEDs('red')

            nvm.leave_progmode()

            while not nvm.getBTN():
                time.sleep(0.016)
    else:
        nvm = UpdiNvmProgrammer(comport=args.comport,
                                baud=args.baudrate,
                                device=Device(args.device))

        nvm.application.datalink.start()

        if not args.reset:  # any action except reset
            try:
                nvm.enter_progmode()
            except:
                print("Device is locked. Performing unlock with chip erase.")
                nvm.unlock_device()

            nvm.get_device_info()

            if not _process(nvm, args):
                print("Error during processing")

    # Reset only needs this.
    nvm.leave_progmode()