Example #1
0
File: svd.py Project: 0xc0170/pyOCD
    def load(self):
        if not isCmsisSvdAvailable:
            return

        if self.is_local:
            self.device = SVDParser.for_xml_file(self.filename).get_device()
        else:
            self.device = SVDParser.for_packaged_svd(self.vendor, self.filename).get_device()
Example #2
0
def get_parser(mcu, svd):
    try:
        if mcu:
            return SVDParser.for_packaged_svd(mcu[0], "{}.svd".format(mcu[1]))
        return SVDParser(ET.ElementTree(ET.fromstring(svd.read())))
    except IOError:
        print("No SVD file found")
        sys.exit()
Example #3
0
    def load(self):
        if not isCmsisSvdAvailable:
            return

        if self.is_local:
            self.device = SVDParser.for_xml_file(self.filename).get_device()
        else:
            self.device = SVDParser.for_packaged_svd(self.vendor, self.filename).get_device()
Example #4
0
    def load(self):
        if not IS_CMSIS_SVD_AVAILABLE:
            return

        if self.is_local:
            self.device = SVDParser.for_xml_file(self.filename).get_device()
        else:
            self.device = SVDParser.for_packaged_svd(
                self.vendor, self.filename).get_device()
Example #5
0
    def invoke(self, args, from_tty):
        args = gdb.string_to_argv(args)
        argc = len(args)
        if argc == 1:
            gdb.write("Loading SVD file {}...\n".format(args[0]))
            parser = SVDParser.for_xml_file(svd_file)
        elif argc == 2:
            gdb.write("Loading SVD file {}/{}...\n".format(args[0], args[1]))
            parser = SVDParser.for_packaged_svd(vendor, device)

        self.dont_repeat()
Example #6
0
    def invoke(self, arg, from_tty):
        args = gdb.string_to_argv(arg)
        if len(args) >= 1:
            if args[0] not in self.vendors:
                raise gdb.GdbError("Invalid vendor name")
                return
            vendor_name = args[0]
            vendor_filenames = self.vendors[vendor_name]
            if len(args) == 1:
                raise gdb.GdbError(
                    "Usage: svd_load <vendor-name> <filename.svd>")
            elif len(args) >= 2:
                filename = args[1]
                try:
                    parser = SVDParser.for_packaged_svd(vendor_name, filename)
                    _svd_printer.set_device(parser.get_device())
                except IOError:
                    raise gdb.GdbError("Failed to load SVD file")
                else:
                    print("Loaded {}/{}".format(vendor_name, filename))

                    for peripheral in _svd_printer.device.peripherals:
                        print("%s @ 0x%08x" %
                              (peripheral.name, peripheral.base_address))

        else:
            raise gdb.GdbError("Usage: svd_load <vendor-name> <filename.svd>")
Example #7
0
 def monitor(self, arg):
     if not self.svd_device:
         try:
             from cmsis_svd.parser import SVDParser
             if os.path.isfile(SvdRegisters.FILE):
                 with open(SvdRegisters.FILE, 'r') as f:
                     lines = [l.strip() for l in f.readlines()]
                     parser = SVDParser.for_xml_file(lines[0])
                     self.svd_device = parser.get_device()
         except:
             raise Exception(
                 "Cannot open or parse SVD file. Check 'cmsis_svd' library installed"
             )
     if self.svd_device and arg:
         args = arg.split()
         name = args[0]
         if name not in self.table:
             r = self.find_register(name)
             if r:
                 r.alias = args[1] if len(args) > 1 else "_"
                 with open(SvdRegisters.FILE, "a") as f:
                     f.write(str(r) + "\n")
             else:
                 raise Exception("Register {} not found".format(name))
         else:
             raise Exception("Register {} already exists".format(name))
Example #8
0
File: data.py Project: Jegeva/idarm
    def data_from_svd(self, cmsis_svd_datapath, segment_size, vendor, chip):
        if vendor == None:
            self.vendors = os.listdir(cmsis_svd_datapath)
            for v in self.vendors:
                self.data_top_hash["vendors"][v] = {}
                for f in glob.glob(os.path.join(cmsis_svd_datapath, v,
                                                '*.svd')):
                    c = f.split(os.path.sep)[-1][:-4]
                    self.data_top_hash["vendors"][v][c] = {}
                    self.data_top_hash["vendors"][v][c]["file"] = f
                    self.data_top_hash["vendors"][v][c]["dirty"] = True
        else:
            self.vendors = [vendor]
            self.data_top_hash["vendors"][vendor] = {}
            if (chip):
                self.data_top_hash["vendors"][vendor][chip] = {}
                self.data_top_hash["vendors"][vendor][chip][
                    "file"] = os.path.join(cmsis_svd_datapath, vendor,
                                           chip + '.svd')
                self.data_top_hash["vendors"][vendor][chip]["dirty"] = True
            else:
                for f in glob.glob(
                        os.path.join(cmsis_svd_datapath, vendor, '*.svd')):
                    c = f.split(os.path.sep)[-1][:-4]
                    self.data_top_hash["vendors"][vendor][c] = {}
                    self.data_top_hash["vendors"][vendor][c]["file"] = f
                    self.data_top_hash["vendors"][vendor][c]["dirty"] = True

            #print(   self.data_top_hash)
        for v in self.data_top_hash["vendors"].keys():
            for c in sorted(self.data_top_hash["vendors"][v].keys()):
                print(v, c)
                self.parse_chip_svd(self.data_top_hash["vendors"][v][c],
                                    SVDParser.for_packaged_svd(v, c + '.svd'))
Example #9
0
File: data.py Project: Jegeva/idarm
    def core_data_from_svd(self, core_svd_datapath, segment_size, core):
        if core == None:
            for f in sorted(glob.glob(os.path.join(core_svd_datapath,
                                                   '*.svd'))):
                c = f.split(os.path.sep)[-1][:-4]
                if (c.lower().find("cortex-") == 0):
                    c = c[7:]
                if (c.lower().find("CM") == 0):
                    c = c[1:]
                print(f, "\t", c)
                self.data_top_hash["cores"][c] = {}
                self.data_top_hash["cores"][c]["file"] = f
                self.data_top_hash["cores"][c]["dirty"] = True
        else:
            f = os.path.join(core_svd_datapath, core) + ".svd"
            if (core.lower().find("cortex-") > -1):
                core = core[7:]

            self.data_top_hash["cores"][core] = {}
            self.data_top_hash["cores"][core]["file"] = f
            self.data_top_hash["cores"][core]["dirty"] = True

        for c in self.data_top_hash["cores"].keys():
            #print("---------->",core_svd_datapath ,c + '.svd')
            self.parse_chip_svd(
                self.data_top_hash["cores"][c],
                SVDParser.for_xml_file(self.data_top_hash["cores"][c]["file"]))
Example #10
0
def parse_svd(svds_directory, family, cpu):
    """
    Parse the SVD files (if available) and return the peripherals.

    The data is returned from cache if available, to speedup the parsing
    process.
    """

    if not svds_directory:
        return []

    svd_file = os.path.join(svds_directory, family.upper(),
                            "%s.svd" % (cpu.upper()))
    cache_key = hashlib.md5(svd_file.encode("ascii")).hexdigest()
    cache_file = os.path.join("cache", cache_key)

    if not os.path.isfile(svd_file):
        return []

    if not os.path.isfile(cache_file):
        device = SVDParser.for_xml_file(svd_file).get_device()

        with open(cache_file, "w") as fp:
            json.dump(
                [peripheral.to_dict() for peripheral in device.peripherals],
                fp)

    with open(cache_file, "r") as fp:
        return json.load(fp)
Example #11
0
    def __init__(self, device_name):
        pylink.JLink.__init__(
            self,
            lib=pylink.library.Library(dllpath=os.getcwd() + os.path.sep +
                                       'JLinkARM.dll'))
        if self.num_connected_emulators() == 0:
            print('No emulator connected. Leaving...')
            exit()
        elif self.num_connected_emulators() == 1:
            self.open()
        else:
            print('List of available emulators:')
            print(self.connected_emulators())
            print('Enter serial number of emulator which shall be connected:')
            snum = input()
            self.open(snum)

        svd = SVDParser.for_mcu(device_name)
        if svd is None:
            print('SVD parser input parameters could not be determined')
            exit()

        # Store device rather than svd object, as parsing to device takes much time. So store this in ram.
        self.svd_device = svd.get_device()

        self.connect(device_name, verbose=True)

        self.restart()

        self.rtt_start()
Example #12
0
def main(unused_argv):
    del unused_argv

    svd_path = os.path.abspath(FLAGS.svd_path)
    if FLAGS.svd_yaml_patch:
        patch_path = os.path.abspath(FLAGS.svd_yaml_patch)
        with open(patch_path, "r") as f:
            root = yaml.safe_load(f)
            root["_path"] = patch_path
        svd = ET.parse(svd_path)
        svdtools.patch.yaml_includes(root)
        svdtools.patch.process_device(svd, root)
        _, svd_path = tempfile.mkstemp()
        svd.write(svd_path)

    parser = SVDParser.for_xml_file(svd_path)
    peripheral = None
    for p in parser.get_device().peripherals:
        if p.name.lower() == FLAGS.peripheral.lower():
            peripheral = p
            break

    formatter = Formatter(FLAGS.output_path)
    Biffile(formatter).write_peripheral(peripheral)
    formatter.finish()

    if FLAGS.verify:
        verify(FLAGS.output_path, peripheral)
Example #13
0
 def parse_cores(self, core_svd_datapath):
     self.core_files = sorted(
         glob.glob(os.path.join(core_svd_datapath, '*.svd')))
     self.cores = {}
     pp = pprint.PrettyPrinter(indent=4)
     for c in self.core_files:
         self.parse_core(c, SVDParser.for_xml_file(c))
Example #14
0
    def on_cmbSVD_currentIndexChanged(self, path):
        if not os.path.exists(path): return

        self.device = SVDParser.for_xml_file(path).get_device()

        self.cmbPeriph.clear()
        self.cmbPeriph.addItems(
            sorted([periph.name for periph in self.device.peripherals]))
Example #15
0
 def verify_cmsis_output(self, filename):
     filepath = 'test/sampleData/cmsis-svd/' + filename + '.svd'
     print('Parsing ' + filepath)
     parser = SVDParser.for_xml_file(filepath)
     self.assertEqual(
         filename,
         parser.get_device().peripherals[0].name,
         msg="{0} is not the provided name in the CMSIS SVD file")
Example #16
0
def load_svd(self, vendor, file):
    parser = SVDParser.for_packaged_svd(vendor, file)
    for peripheral in parser.get_device().peripherals:
        p_dict = peripheral.to_dict()
        base_addr = p_dict['base_address']
        size = int(p_dict['address_block']['size']) - 1  #hackhack
        name = peripheral.name
        self.add_memory_range(base_addr, size)
Example #17
0
def get_parser(mcu, svd):
    try:
        if mcu:
            return SVDParser.for_packaged_svd(mcu[0], "{}.svd".format(mcu[1]))
        return SVDParser(ET.ElementTree(ET.fromstring(svd.read())))
    except IOError:
        print("No SVD file found")
        sys.exit()
Example #18
0
def main():
    parser = SVDParser.for_packaged_svd('Nordic', 'nrf51.svd')
    #dump_json(parser)
    interrupts = get_peripheral_interrupts(parser)
    dump_macros(interrupts,
            open("src/chips/nrf51822/peripheral_interrupts.h", "w"))
    peripherals = get_peripheral_registers(parser, ["GPIO"])
    dump_registers(peripherals,
            open("src/chips/nrf51822/peripheral_registers.rs", "w"))
Example #19
0
def main():
    parser = SVDParser.for_packaged_svd('STMicro', 'STM32F0xx.svd')
    address2peripheral = {}
    for peripheral in parser.get_device().peripherals:
        address2peripheral[peripheral.base_address] = peripheral
    for _, peripheral in sorted(address2peripheral.items()):
        print(f'{peripheral.name: <16} @ 0x{peripheral.base_address:08x}')
    svd_dict = parser.get_device().to_dict()
    print(json.dumps(svd_dict, sort_keys=True, indent=4))
Example #20
0
def LPC43xxTarget(device):
    """ Factory function that creates a low-level LPC43xx target. """

    from .. import find_greatfet_asset

    svd_file = find_greatfet_asset('LPC43xx_43Sxx.svd')
    svd = SVDParser.for_xml_file(svd_file)

    return VirtualLPC43xxTarget.from_svd(svd.get_device(), device)
Example #21
0
    def invoke(self, arg, from_tty):
        args = gdb.string_to_argv(arg)
        if len(args) != 1:
            raise gdb.GdbError("Usage: svd_load_file <filename.svd>")

        path = args[0]
        try:
            parser = SVDParser.for_xml_file(path)
            _svd_printer.set_device(parser.get_device())
        except IOError:
            raise gdb.GdbError("Failed to load SVD file")
        else:
            print("Loaded {}".format(path))
Example #22
0
def main():
    from jinja2 import Environment, FileSystemLoader

    parser = SVDParser.for_packaged_svd('Nordic', 'nrf51.svd')
    #dump_json(parser)
    interrupts = get_peripheral_interrupts(parser)
    dump_macros(interrupts,
                open("src/chips/nrf51822/src/peripheral_interrupts.h", "w"))
    peripherals = get_peripheral_registers(parser, ["GPIO"])

    env = Environment(loader=FileSystemLoader('src/chips/nrf51822/src'))
    template = env.get_template('peripheral_registers.rs.jinja')
    template.stream(program=PROGRAM, peripherals=peripherals).dump(
        'src/chips/nrf51822/src/peripheral_registers.rs')
Example #23
0
def main():
    from jinja2 import Environment, FileSystemLoader

    parser = SVDParser.for_packaged_svd('Nordic', 'nrf51.svd')
    #dump_json(parser)
    interrupts = get_peripheral_interrupts(parser)
    dump_macros(interrupts,
            open("src/chips/nrf51822/peripheral_interrupts.h", "w"))
    peripherals = get_peripheral_registers(parser, ["GPIO"])

    env = Environment(loader=FileSystemLoader('src/chips/nrf51822'))
    template = env.get_template('peripheral_registers.rs.jinja')
    template.stream(program=PROGRAM, peripherals=peripherals).dump(
            'src/chips/nrf51822/peripheral_registers.rs')
Example #24
0
def parseFile(company, file):
    print("Parsing %s,%s " % (company, file))
    parser = SVDParser.for_packaged_svd(company, file + ".svd", 1)
    extention = []
    jsonPath = posixpath.join(posixpath.dirname(posixpath.abspath(__file__)),
                              "Extention", company, file + ".json")
    #print(jsonPath)
    device = parser.get_device()
    if posixpath.isfile(jsonPath):
        extFile = open(jsonPath, "r", encoding='utf-8')
        extention = json.load(extFile)
    subdir = Ft.formatCpuName(Ft.getKey(extention, ["device", "cpu", "name"]),
                              device)
    chipDir = posixpath.join('..', '..', 'Lib', 'Chip')
    subdir = posixpath.join(chipDir, subdir)
    if not posixpath.exists(subdir):
        os.makedirs(subdir)
    subdir = posixpath.join(subdir, company)
    if not posixpath.exists(subdir):
        os.makedirs(subdir)
    subdir = posixpath.join(subdir, file)
    if not posixpath.exists(subdir):
        os.makedirs(subdir)
    chipText = "#pragma once \n"
    chipText += "#include <cstdint>\n"
    incDir = subdir[10:]
    if Ft.getKey(extention, ["kvasir", "io"]):
        parseIo(extention, device, subdir)
        chipText += "#include <%s>\n" % (posixpath.join(incDir, "Io.hpp"))
    for peripheral in device.peripherals:
        if peripheral.name is not None:
            chipText += "#include <%s>\n" % (posixpath.join(
                incDir, peripheral.name + ".hpp"))
            out = "#pragma once \n#include <Register/Utility.hpp>\n"
            out += "namespace Kvasir {\n"
            out += parsePeripheral(
                peripheral, Ft.getKey(extention, ['.' + peripheral.name]))
            out += "}\n"

            outFile = open(posixpath.join(subdir, peripheral.name + ".hpp"),
                           'w',
                           encoding='utf-8')
            outFile.write(out)
        else:
            print("error no name in %s" % (file))
    outFile = open(posixpath.join(chipDir, file + ".hpp"),
                   'w',
                   encoding='utf-8')
    outFile.write(chipText)
Example #25
0
def main():
    parser = SVDParser.for_packaged_svd(sys.argv[1], sys.argv[2] + '.svd')
    device = parser.get_device()

    zig_fmt = subprocess.Popen(('zig', 'fmt', '--stdin'),
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               encoding='utf8')

    generator = MMIOFileGenerator(zig_fmt.stdin)
    generator.generate_file(device)

    zig_fmt.stdin.flush()
    zig_fmt.stdin.close()
    print(zig_fmt.stdout.read())
Example #26
0
def main(mcu, mcu_peripheral=None):
    """Given a chip and peripheral, prints the registers.
    """
    parser = SVDParser.for_packaged_svd(*MCU2VENDOR_FILE[mcu])
    address2peripheral = {}
    for peripheral in parser.get_device().peripherals:
        address2peripheral[peripheral.base_address] = peripheral
    for _, peripheral in sorted(address2peripheral.items()):
        print(
            f'{peripheral.name: <16} @ 0x{peripheral.base_address:08x} ({peripheral.address_block.size: >4})'
        )
    if mcu_peripheral:
        for peripheral in parser.get_device().peripherals:
            if peripheral.name == mcu_peripheral or mcu_peripheral == ALL:
                show_peripheral(peripheral)
Example #27
0
def main():
	parser = argparse.ArgumentParser(description = 'Generate C++ project from CMSIS SVD XML file')
	parser.add_argument('input', metavar='inputsvd', nargs=1, help='Input SVD file to generate BSP from')
	parser.add_argument('project', metavar='project', nargs=1, help='Path to output project')
	args = parser.parse_args()

	if args.input:
		file = args.input[0]

	if args.project:
		if os.path.exists(args.project[0]):
			print("Path exists, exiting!")
			exit(-1)
		else:
			os.mkdir(args.project[0])
			os.mkdir(os.path.join(args.project[0], "inc"))
			os.mkdir(os.path.join(args.project[0], "src"))

	name = getProjName(args.project[0])

	parser = SVDParser.for_xml_file(file)
	dev = parser.get_device()
	outfile = dev.name+".h"

	f=open(os.path.join(args.project[0], "inc", outfile), "w+")
	f.write("#pragma once\r\n")
	f.write("#include <cstdint>\r\n")
	f.write("#include <reg.h>\r\n")
	f.write("\r\nnamespace %s {\r\n" % dev.name)

	DeviceStartup(dev, args.project[0])

	for peripheral in dev.peripherals:
		p = PeripheralNamespace(peripheral)
		p.dump(f)
	f.write("};\r\n")
	f.close()
	shutil.copyfile("reg.h.template", os.path.join(os.path.join(args.project[0], "inc"),'reg.h'))
	shutil.copyfile("load_target.sh.template", os.path.join(args.project[0],'load_target.sh'))
	shutil.copyfile("target.cfg.template", os.path.join(args.project[0],'target.cfg'))
	shutil.copyfile("linker.template", os.path.join(args.project[0],'linker.ld'))

	subst_target('runme.gdb.template', os.path.join(args.project[0],'runme.gdb'), getProjName(args.project[0]))
	subst_target('Makefile.template', os.path.join(args.project[0],'Makefile'), getProjName(args.project[0]))

	targetMain = open(os.path.join(args.project[0],getProjName(args.project[0])+".cpp"), "w+")
	targetMain.write("int main(void)\r\n{\r\n    while(1);\r\n}\r\n");
	targetMain.close()
Example #28
0
    def invoke(self, arg, from_tty):
        args = gdb.string_to_argv(arg)
        if len(args) != 1:
            raise gdb.GdbError("Usage: svd_load_file <filename.svd>")

        path = args[0]
        try:
            parser = SVDParser.for_xml_file(path)
            _svd_printer.set_device(parser.get_device())

        except IOError:
            raise gdb.GdbError("Failed to load SVD file")
        else:
            print("Loaded {}".format(path))

            for peripheral in _svd_printer.device.peripherals:
                print("%s @ 0x%08x" %
                      (peripheral.name, peripheral.base_address))
Example #29
0
def parseFile(company,file):
    print("Parsing %s,%s " % (company,file))
    parser = SVDParser.for_packaged_svd(company, file + ".svd",1,1)
    extention = []
    jsonPath = os.path.join(os.path.dirname(os.path.abspath(__file__)),"Extention",company,file+".json")
    #print(jsonPath)
    device = parser.get_device()
    if os.path.isfile(jsonPath):
        extFile = open(jsonPath,"r",encoding='utf-8')
        extention = json.load(extFile)
    subdir = Ft.formatCpuName(Ft.getKey(extention,["device","cpu","name"]),device)
    chipDir = os.path.join('..','..','Lib','Chip')
    subdir = os.path.join(chipDir, subdir)
    if not os.path.exists(subdir):
        os.makedirs(subdir)
    subdir = os.path.join(subdir,company)
    if not os.path.exists(subdir):
        os.makedirs(subdir)
    subdir = os.path.join(subdir,file)
    if not os.path.exists(subdir):
        os.makedirs(subdir)
    chipText = "#pragma once \n"
    incDir = subdir[10:]
    if Ft.getKey(extention,["kvasir","io"]):
        parseIo(extention,device,subdir)
        chipText += "#include \"%s\"\n" % (os.path.join(incDir,"Io.hpp"))
    for peripheral in device.peripherals:
        if peripheral.name is not None:
            chipText += "#include \"%s\"\n" % (os.path.join(incDir,peripheral.name+".hpp"))
            out = "#pragma once \n#include \"Register/Utility.hpp\"\n"
            out += "namespace Kvasir {\n"
            out += parsePeripheral(peripheral,Ft.getKey(extention,['.'+peripheral.name]))
            out += "}\n"

            outFile = open(os.path.join(subdir,peripheral.name+".hpp"), 'w',encoding='utf-8')
            outFile.write(out)
        else:
            print("error no name in %s" % (file))
    outFile = open(os.path.join(chipDir,file + ".hpp"), 'w',encoding='utf-8')
    outFile.write(chipText)
Example #30
0
    def __init__(self, path):
        parser = [periph for periph in SVDParser.for_xml_file(path).get_device().peripherals]

        # Read peripherals and their registers
        self.device = []
        for periph in parser:
            self.device += [{"type": "periph",
                             "name": periph.name,
                             "description": periph.description,
                             "base_address": periph.base_address,
                             "group_name": periph.group_name,
                             "regs": periph.derived_from}]  # regs value will be replaced with regs list
            if (self.device[-1]["regs"] is not None):
                    self.device[-1]["regs"] = next(periph for periph in self.device if periph["name"] == self.device[-1]["regs"])["regs"].copy()
            else:
                self.device[-1]["regs"] = []
                for reg in periph.registers:
                    self.device[-1]["regs"] += [{"type": "reg",
                                                 "name": reg.name,
                                                 "description": reg.description,
                                                 "address_offset": reg.address_offset,
                                                 "fields": []}]
                    for field in reg.fields:
                        self.device[-1]["regs"][-1]["fields"] += [{"type": "field",
                                                                   "name": field.name,
                                                                   "description": field.description,
                                                                   "address_offset": reg.address_offset,
                                                                   "lsb": field.bit_offset,
                                                                   "msb": field.bit_offset + field.bit_width - 1,
                                                                   "access": field.access,
                                                                   "enums": None}]
                        if field.enumerated_values:
                            self.device[-1]["regs"][-1]["fields"][-1]["enums"] = []
                            for enum in field.enumerated_values:
                                self.device[-1]["regs"][-1]["fields"][-1]["enums"] += [{"name": enum.name,
                                                                                        "description": enum.description,
                                                                                        "value": enum.value}]

        self.device = sorted(self.device, key=itemgetter('base_address'))
Example #31
0
    def invoke(self, arg, from_tty):
        try:
            argv = gdb.string_to_argv(arg)
            if len(argv) != 1:
                raise Exception("Invalide parameter")

            pathfile = argv[0]
            gdb.write("Svd Loading {} ".format(pathfile))
            parser = SVDParser.for_xml_file(pathfile)
            device = parser.get_device()
            peripherals = dict((peripheral.name, peripheral)
                               for peripheral in device.peripherals)
            GdbSvdGetCmd(device, peripherals)
            GdbSvdSetCmd(device, peripherals)
            GdbSvdInfoCmd(device, peripherals)

        except Exception as inst:
            gdb.write("\n{}\n".format(inst))
            gdb.execute("help svd")
        except IOError:
            gdb.write("\nFailed to load SVD file\n")
        else:
            gdb.write("Done\n")
Example #32
0
 def test_packaged_xml(self):
     parser = SVDParser.for_packaged_svd('Freescale', 'MK20D7.svd')
     device = parser.get_device()
     self.assertTrue(len(device.peripherals) > 0)
Example #33
0
 def load(self):
     if self.is_local:
         self.device = SVDParser.for_xml_file(self.filename).get_device()
     else:
         self.device = SVDParser.for_packaged_svd(self.vendor, self.filename).get_device()
#
# Copyright 2015 Paul Osborne <*****@*****.**>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from cmsis_svd.parser import SVDParser

parser = SVDParser.for_packaged_svd('Freescale', 'MK20D7.xml')
for peripheral in parser.get_device().peripherals:
    print("%s @ 0x%08x" % (peripheral.name, peripheral.base_address))
Example #35
0
def load_svd_for_mcu(mcu):
    vendor, filename = find_for_mcu(mcu)
    if (vendor is None) or (filename is None):
        return None
    return SVDParser.for_packaged_svd(vendor, filename).get_device()
Example #36
0
 def setUpClass(cls):
     svd = os.path.join(DATA_DIR, "Nordic", "nrf51.svd")
     cls.parser = SVDParser.for_xml_file(svd)
     cls.device = cls.parser.get_device()
# pip install -U cmsis-svd
# python3 nrf51.py >> nrf51.flags.r2

from cmsis_svd.parser import SVDParser

parser = SVDParser.for_packaged_svd('Nordic', 'nrf51.svd')
for peripheral in parser.get_device().peripherals:
    print("f %s = 0x%08x" % (peripheral.name, peripheral.base_address))
    for register in peripheral.registers:
        print("f %s.%s = 0x%08x" %
              (peripheral.name, register.name,
               peripheral.base_address + register.address_offset))
Example #38
0
 def test_packaged_xml_for_mcu(self):
     parser = SVDParser.for_mcu('STM32F103C8T6')
     self.assertTrue(parser is not None)
     device = parser.get_device()
     self.assertTrue(len(device.peripherals) > 0)
	print(comment_str(x))

def banner(x):
	comment('==== {:=<55}'.format("%s " % x))

def caption(x):
	print()
	comment('---- {:-<55}'.format("%s " % x))

def comment(x):
	print(comment_str(x))


# ------------------------------------

parser = SVDParser.for_packaged_svd('STMicro', svd_name)
device = parser.get_device()

print()
banner('%s PERIPHERALS' % device.name)
comment('')
comment('CTU Prague, FEL, Department of Measurement')
comment('')
comment('-' * 60)
comment('')
comment('Generated from "%s"' % svd_name)
comment('')
comment('SVD parsing library (c) Paul Osborne, 2015-2016')
comment('    https://github.com/posborne/cmsis-svd')
comment('ASM building script (c) Ondrej Hruska, 2016')
comment('')
Example #40
0
import json
from cmsis_svd.parser import SVDParser

parser = SVDParser.for_packaged_svd('STMicro', 'STM32F042x.svd')
svd_dict = parser.get_device().to_dict()
print(json.dumps(svd_dict, sort_keys=True,
                 indent=4, separators=(',', ': ')))
Example #41
0
 def setUpClass(cls):
     cls.svd_path = os.path.join(DATA_DIR, "Freescale", "MKL25Z4.svd")
     cls.json_path = os.path.join(THIS_DIR, "MKL25Z4.json")
     cls.parser = SVDParser.for_xml_file(cls.svd_path)
     cls.device = cls.parser.get_device()
Example #42
0
 def verify_svd_validity():
     parser = SVDParser.for_xml_file(svd_path)
     device = parser.get_device()
     assert device is not None
Example #43
0
 def setUp(self):
     svd = os.path.join(DATA_DIR, "Freescale", "MKL25Z4.xml")
     self.parser = SVDParser.for_xml_file(svd)
Example #44
0
 def setUpClass(cls):
     cls.svd_path = os.path.join(DATA_DIR, "Freescale", "MKL25Z4.svd")
     cls.json_path = os.path.join(THIS_DIR, "MKL25Z4.json")
     cls.parser = SVDParser.for_xml_file(cls.svd_path)
     cls.device = cls.parser.get_device()