Exemple #1
0
 def setDebugLevel(self, level):
     """Set level of debugging messages."""
     global DEBUG
     DEBUG = level
     # this option is only available in the mspgcc library
     if backend == CTYPES_MSPGCC:
         _parjtag.configure(DEBUG_OPTION, level)
Exemple #2
0
 def setRamsize(self, ramsize):
     """Set download chunk size."""
     if DEBUG > 1: sys.stderr.write("* setRamsize(%d)\n" % ramsize)
     # this option is only available in the mspgcc library
     if backend == CTYPES_MSPGCC:
         _parjtag.configure(RAMSIZE_OPTION, ramsize)
     else:
         if DEBUG > 1: sys.stderr.write("* setRamsize ignored for %s backend\n" % backend)
Exemple #3
0
def main():
    global DEBUG
    import getopt
    filetype    = None
    filename    = None
    reset       = 0
    wait        = 0
    goaddr      = None
    jtag        = JTAG()
    toinit      = []
    todo        = []
    startaddr   = None
    size        = 2
    outputformat= HEX
    lpt         = None
    funclet     = None
    ramsize     = None

    sys.stderr.write("MSP430 parallel JTAG programmer Version: %s\n" % VERSION)
    try:
        opts, args = getopt.getopt(sys.argv[1:],
            "hl:weEmpvrg:Du:d:s:xbiITfR:S",
            ["help", "lpt=", "wait"
             "masserase", "erasecheck", "mainerase", "program",
             "erase=", "eraseinfo",
             "verify", "reset", "go=", "debug",
             "upload=", "download=", "size=", "hex", "bin", "ihex",
             "intelhex", "titext", "funclet", "ramsize=", "progress"]
        )
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-l", "--lpt"):
            lpt = a
        elif o in ("-w", "--wait"):
            wait = 1
        elif o in ("-e", "--masserase"):
            toinit.append(jtag.actionMassErase)         #Erase Flash
        elif o in ("-E", "--erasecheck"):
            toinit.append(jtag.actionEraseCheck)        #Erase Check (by file)
        elif o in ("-m", "--mainerase"):
            toinit.append(jtag.actionMainErase)         #Erase main Flash
        elif o == "--erase":
            try:
                seg = int(a, 0)
                toinit.append(jtag.makeActionSegmentErase(seg))
            except ValueError:
                sys.stderr.write("segment address must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        elif o == "--eraseinfo":
            toinit.append(jtag.makeActionSegmentErase(0x1000))
            toinit.append(jtag.makeActionSegmentErase(0x1080))
        elif o in ("-p", "--program"):
            todo.append(jtag.actionProgram)             #Program file
        elif o in ("-v", "--verify"):
            todo.append(jtag.actionVerify)              #Verify file
        elif o in ("-r", "--reset"):
            reset = 1
        elif o in ("-g", "--go"):
            try:
                goaddr = int(a, 0)                      #try to convert decimal
            except ValueError:
                sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        elif o in ("-D", "--debug"):
            DEBUG = DEBUG + 1
        elif o in ("-u", "--upload"):
            try:
                startaddr = int(a, 0)                   #try to convert number of any base
            except ValueError:
                sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        elif o in ("-s", "--size"):
            try:
                size = int(a, 0)
            except ValueError:
                sys.stderr.write("upload address must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        #outut formats
        elif o in ("-x", "--hex"):
            outputformat = HEX
        elif o in ("-b", "--bin"):
            outputformat = BINARY
        elif o in ("-i", "--ihex"):
            outputformat = INTELHEX
        #input formats
        elif o in ("-I", "--intelhex"):
            filetype = 0
        elif o in ("-T", "--titext"):
            filetype = 1
        #others
        elif o in ("-f", "--funclet"):
            funclet = 1
        elif o in ("-R", "--ramsize"):
            try:
                ramsize = int(a, 0)
            except ValueError:
                sys.stderr.write("ramsize must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        elif o in ("-S", "--progress"):
            jtag.showprogess = 1

    if len(args) == 0:
        sys.stderr.write("Use -h for help\n")
    elif len(args) == 1:                                #a filename is given
        if not funclet:
            if not todo:                                #if there are no actions yet
                todo.extend([                           #add some useful actions...
                    jtag.actionProgram,
                ])
        filename = args[0]
    else:                                               #number of args is wrong
        usage()
        sys.exit(2)

    if DEBUG:   #debug infos
        sys.stderr.write("debug level set to %d\n" % DEBUG)
        _parjtag.configure(DEBUG_OPTION, DEBUG)
        sys.stderr.write("python version: %s\n" % sys.version)


    #sanity check of options
    if goaddr and reset:
        sys.stderr.write("Warning: option --reset ignored as --go is specified!\n")
        reset = 0

    if startaddr and reset:
        sys.stderr.write("Warning: option --reset ignored as --upload is specified!\n")
        reset = 0

    #prepare data to download
    jtag.data = Memory()                                #prepare downloaded data
    if filetype is not None:                            #if the filetype is given...
        if filename is None:
            raise ValueError("no filename but filetype specified")
        if filename == '-':                             #get data from stdin
            file = sys.stdin
        else:
            file = open(filename,"rb")                  #or from a file
        if filetype == 0:                               #select load function
            jtag.data.loadIHex(file)                    #intel hex
        elif filetype == 1:
            jtag.data.loadTIText(file)                  #TI's format
        else:
            raise ValueError("illegal filetype specified")
    else:                                               #no filetype given...
        if filename == '-':                             #for stdin:
            jtag.data.loadIHex(sys.stdin)               #assume intel hex
        elif filename:
            jtag.data.loadFile(filename)                #autodetect otherwise

    if DEBUG > 5: sys.stderr.write("File: %r\n" % filename)

    try:
        jtag.connect(lpt)                               #try to open port
    except IOError:
        raise                                           #do not handle here
    else:                                               #continue if open was successful
        if ramsize is not None:
            _parjtag.configure(RAMSIZE_OPTION, ramsize)
        #initialization list
        if toinit:  #erase and erase check
            if DEBUG: sys.stderr.write("Preparing device ...\n")
            for f in toinit: f()

        #work list
        if todo:
            if DEBUG > 0:       #debug
                #show a nice list of sheduled actions
                sys.stderr.write("TODO list:\n")
                for f in todo:
                    try:
                        sys.stderr.write("   %s\n" % f.func_name)
                    except AttributeError:
                        sys.stderr.write("   %r\n" % f)
            for f in todo: f()                          #work through todo list

        if reset:                                       #reset device first if desired
            jtag.actionReset()

        if funclet is not None:                         #download and start funclet
            jtag.funclet()

        if goaddr is not None:                          #start user programm at specified address
            jtag.actionRun(goaddr)                      #load PC and execute

        #upload  datablock and output
        if startaddr is not None:
            if goaddr:                                  #if a program was started...
                raise NotImplementedError
                #TODO:
                #sys.stderr.write("Waiting to device for reconnect for upload: ")
            data = jtag.uploadData(startaddr, size)     #upload data
            if outputformat == HEX:                     #depending on output format
                hexdump( (startaddr, data) )            #print a hex display
            elif outputformat == INTELHEX:
                makeihex( (startaddr, data) )           #ouput a intel-hex file
            else:
                sys.stdout.write(data)                  #binary output w/o newline!
            wait = 0    #wait makes no sense as after the upload the device is still stopped

        if wait:                                        #wait at the end if desired
            sys.stderr.write("Press <ENTER> ...\n")     #display a prompt
            raw_input()                                 #wait for newline
        
        _parjtag.reset(1, 1)                            #reset and release target
        #~ jtag.actionReset()
        jtag.close()                                    #Release communication port
Exemple #4
0
 def setRamsize(self, ramsize):
     """Set download chunk size"""
     if DEBUG > 1: sys.stderr.write("* setRamsize(%d)\n" % ramsize)
     _parjtag.configure(RAMSIZE_OPTION, ramsize)
Exemple #5
0
 def setDebugLevel(self, level):
     """Set level of debuggig messages."""
     global DEBUG
     DEBUG = level
     _parjtag.configure(DEBUG_OPTION, level)
Exemple #6
0
 def setRamsize(self, ramsize):
     """Set download chunk size"""
     if DEBUG > 1: sys.stderr.write("* setRamsize(%d)\n" % ramsize)
     _parjtag.configure(RAMSIZE_OPTION, ramsize)
Exemple #7
0
 def setDebugLevel(self, level):
     """Set level of debuggig messages."""
     global DEBUG
     DEBUG = level
     _parjtag.configure(DEBUG_OPTION, level)
Exemple #8
0
            def secure(self):
                """burn JTAG security fuse.
                   Note: not reversibly. use with care.
                   Note: not supported by all JTAG adapters.
                """
                status = MSP430_Secure()
                if status != STATUS_OK:
                    raise IOError("Could not secure device: %s" % MSP430_Error_String(MSP430_Error_Number()))

        _parjtag = ParJTAG()

    # print the used backend
    if DEBUG:
        sys.stderr.write("JTAG backend: %s (%s)\n" % (backend, backend_info))
        if backend == CTYPES_MSPGCC:
            _parjtag.configure(DEBUG_OPTION, DEBUG)


class JTAG:
    """wrap the _parjtag extension.
    The action* methods all do output messages on stderr and they take their
    settings and data from the object and not as parameters.
    """

    def __init__(self):
        self.showprogess = 0
        self.data = None
        self.verbose = 1

    # ---------- direct use API ---------------
def main():
    global DEBUG
    import getopt
    filetype = None
    filename = None
    reset = 0
    wait = 0
    goaddr = None
    jtag = JTAG()
    toinit = []
    todo = []
    startaddr = None
    size = 2
    outputformat = HEX
    lpt = None
    funclet = None
    ramsize = None

    sys.stderr.write("MSP430 parallel JTAG programmer Version: %s\n" % VERSION)
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "hl:weEmpvrg:Du:d:s:xbiITfR:S", [
                "help", "lpt=", "wait"
                "masserase", "erasecheck", "mainerase", "program", "erase=",
                "eraseinfo", "verify", "reset", "go=", "debug", "upload=",
                "download=", "size=", "hex", "bin", "ihex", "intelhex",
                "titext", "funclet", "ramsize=", "progress"
            ])
    except getopt.GetoptError:
        # print help information and exit:
        usage()
        sys.exit(2)

    for o, a in opts:
        if o in ("-h", "--help"):
            usage()
            sys.exit()
        elif o in ("-l", "--lpt"):
            lpt = a
        elif o in ("-w", "--wait"):
            wait = 1
        elif o in ("-e", "--masserase"):
            toinit.append(jtag.actionMassErase)  #Erase Flash
        elif o in ("-E", "--erasecheck"):
            toinit.append(jtag.actionEraseCheck)  #Erase Check (by file)
        elif o in ("-m", "--mainerase"):
            toinit.append(jtag.actionMainErase)  #Erase main Flash
        elif o == "--erase":
            try:
                seg = int(a, 0)
                toinit.append(jtag.makeActionSegmentErase(seg))
            except ValueError:
                sys.stderr.write(
                    "segment address must be a valid number in dec, hex or octal\n"
                )
                sys.exit(2)
        elif o == "--eraseinfo":
            toinit.append(jtag.makeActionSegmentErase(0x1000))
            toinit.append(jtag.makeActionSegmentErase(0x1080))
        elif o in ("-p", "--program"):
            todo.append(jtag.actionProgram)  #Program file
        elif o in ("-v", "--verify"):
            todo.append(jtag.actionVerify)  #Verify file
        elif o in ("-r", "--reset"):
            reset = 1
        elif o in ("-g", "--go"):
            try:
                goaddr = int(a, 0)  #try to convert decimal
            except ValueError:
                sys.stderr.write(
                    "upload address must be a valid number in dec, hex or octal\n"
                )
                sys.exit(2)
        elif o in ("-D", "--debug"):
            DEBUG = DEBUG + 1
        elif o in ("-u", "--upload"):
            try:
                startaddr = int(a, 0)  #try to convert number of any base
            except ValueError:
                sys.stderr.write(
                    "upload address must be a valid number in dec, hex or octal\n"
                )
                sys.exit(2)
        elif o in ("-s", "--size"):
            try:
                size = int(a, 0)
            except ValueError:
                sys.stderr.write(
                    "upload address must be a valid number in dec, hex or octal\n"
                )
                sys.exit(2)
        #outut formats
        elif o in ("-x", "--hex"):
            outputformat = HEX
        elif o in ("-b", "--bin"):
            outputformat = BINARY
        elif o in ("-i", "--ihex"):
            outputformat = INTELHEX
        #input formats
        elif o in ("-I", "--intelhex"):
            filetype = 0
        elif o in ("-T", "--titext"):
            filetype = 1
        #others
        elif o in ("-f", "--funclet"):
            funclet = 1
        elif o in ("-R", "--ramsize"):
            try:
                ramsize = int(a, 0)
            except ValueError:
                sys.stderr.write(
                    "ramsize must be a valid number in dec, hex or octal\n")
                sys.exit(2)
        elif o in ("-S", "--progress"):
            jtag.showprogess = 1

    if len(args) == 0:
        sys.stderr.write("Use -h for help\n")
    elif len(args) == 1:  #a filename is given
        if not funclet:
            if not todo:  #if there are no actions yet
                todo.extend([  #add some useful actions...
                    jtag.actionProgram,
                ])
        filename = args[0]
    else:  #number of args is wrong
        usage()
        sys.exit(2)

    if DEBUG:  #debug infos
        sys.stderr.write("debug level set to %d\n" % DEBUG)
        _parjtag.configure(DEBUG_OPTION, DEBUG)
        sys.stderr.write("python version: %s\n" % sys.version)

    #sanity check of options
    if goaddr and reset:
        sys.stderr.write(
            "Warning: option --reset ignored as --go is specified!\n")
        reset = 0

    if startaddr and reset:
        sys.stderr.write(
            "Warning: option --reset ignored as --upload is specified!\n")
        reset = 0

    #prepare data to download
    jtag.data = Memory()  #prepare downloaded data
    if filetype is not None:  #if the filetype is given...
        if filename is None:
            raise ValueError("no filename but filetype specified")
        if filename == '-':  #get data from stdin
            file = sys.stdin
        else:
            file = open(filename, "rb")  #or from a file
        if filetype == 0:  #select load function
            jtag.data.loadIHex(file)  #intel hex
        elif filetype == 1:
            jtag.data.loadTIText(file)  #TI's format
        else:
            raise ValueError("illegal filetype specified")
    else:  #no filetype given...
        if filename == '-':  #for stdin:
            jtag.data.loadIHex(sys.stdin)  #assume intel hex
        elif filename:
            jtag.data.loadFile(filename)  #autodetect otherwise

    if DEBUG > 5: sys.stderr.write("File: %r\n" % filename)

    try:
        jtag.connect(lpt)  #try to open port
    except IOError:
        raise  #do not handle here
    else:  #continue if open was successful
        if ramsize is not None:
            _parjtag.configure(RAMSIZE_OPTION, ramsize)
        #initialization list
        if toinit:  #erase and erase check
            if DEBUG: sys.stderr.write("Preparing device ...\n")
            for f in toinit:
                f()

        #work list
        if todo:
            if DEBUG > 0:  #debug
                #show a nice list of sheduled actions
                sys.stderr.write("TODO list:\n")
                for f in todo:
                    try:
                        sys.stderr.write("   %s\n" % f.func_name)
                    except AttributeError:
                        sys.stderr.write("   %r\n" % f)
            for f in todo:
                f()  #work through todo list

        if reset:  #reset device first if desired
            jtag.actionReset()

        if funclet is not None:  #download and start funclet
            jtag.funclet()

        if goaddr is not None:  #start user programm at specified address
            jtag.actionRun(goaddr)  #load PC and execute

        #upload  datablock and output
        if startaddr is not None:
            if goaddr:  #if a program was started...
                raise NotImplementedError
                #TODO:
                #sys.stderr.write("Waiting to device for reconnect for upload: ")
            data = jtag.uploadData(startaddr, size)  #upload data
            if outputformat == HEX:  #depending on output format
                hexdump((startaddr, data))  #print a hex display
            elif outputformat == INTELHEX:
                makeihex((startaddr, data))  #ouput a intel-hex file
            else:
                sys.stdout.write(data)  #binary output w/o newline!
            wait = 0  #wait makes no sense as after the upload the device is still stopped

        if wait:  #wait at the end if desired
            sys.stderr.write("Press <ENTER> ...\n")  #display a prompt
            raw_input()  #wait for newline

        _parjtag.reset(1, 1)  #reset and release target
        #~ jtag.actionReset()
        jtag.close()  #Release communication port