modm_data.html2svd.stmicro
def
memory_map_from_reference_manual(rm):
361def memory_map_from_reference_manual(rm): 362 if "RM0438" in rm.name or "RM0456" in rm.name: 363 print("RM0438, RM0456 are ARMv8-M with two memory maps!") 364 return [] 365 366 all_chapters = rm.chapters() 367 type_chapters = { 368 rm.chapter(f"chapter {s.split('.')[0]} ") for pers in rm.peripherals.values() for locs in pers for s in locs[4] 369 } 370 peripheral_types = defaultdict(set) 371 instance_offsets = {} 372 for chapter in all_chapters: 373 print() 374 peripheral_maps, peripheral_offsets = rm.peripheral_maps(chapter, assert_table=chapter in type_chapters) 375 instance_offsets.update(peripheral_offsets) 376 peripheral_maps = _peripheral_map_to_tree(chapter, peripheral_maps) 377 if not _expand_register_offsets(peripheral_maps): 378 exit(1) 379 for pmap in peripheral_maps: 380 print(pmap) 381 # print(RenderTree(pmap, maxlevel=2)) 382 peripheral_types[pmap.name].add(pmap) 383 384 for name, pmaps in peripheral_types.items(): 385 print(name) 386 for pmap in pmaps: 387 print(pmap.section, pmap._chapter._relpath) 388 print(RenderTree(pmap, maxlevel=2)) 389 390 memtrees = _build_device_trees(rm, peripheral_types, instance_offsets) 391 # for tree in memtrees: 392 # print(RenderTree(tree, maxlevel=2)) 393 # exit(1) 394 memtrees = _compactify_device_trees(memtrees) 395 memtrees = [_normalize_order(memtree) for memtree in memtrees] 396 return memtrees
def
memory_map_from_datasheet(ds):
361def memory_map_from_datasheet(ds): 362 register = ds.chapter(r"chapter +\d+ +register +mapping") 363 table = register.tables("register")[0] 364 print(table) 365 for row in table.cell_rows(): 366 cname = row.match_value("name")[0].text() 367 ctype = row.match_value("type")[0].text() 368 caddr = row.match_value(r"address.*?hex")[0].text() 369 cvalue = row.match_value(r"default")[0].text() 370 ccomment = row.match_value(r"comment")[0].text() 371 if not ctype: 372 continue 373 cvalue = int(cvalue, 2) if cvalue.isdigit() else None 374 print(cname, ctype, int(caddr, 16), cvalue, ccomment) 375 376 exit(1) 377 378 peripheral_types = defaultdict(set) 379 instance_offsets = {} 380 for chapter in all_chapters: # noqa: F821 381 print() 382 peripheral_maps, peripheral_offsets = ds.peripheral_maps(chapter, assert_table=chapter in type_chapters) # noqa: F821 383 instance_offsets.update(peripheral_offsets) 384 peripheral_maps = _peripheral_map_to_tree(chapter, peripheral_maps) 385 if not _expand_register_offsets(peripheral_maps): 386 exit(1) 387 for pmap in peripheral_maps: 388 print(pmap) 389 # print(RenderTree(pmap, maxlevel=2)) 390 peripheral_types[pmap.name].add(pmap) 391 392 for name, pmaps in peripheral_types.items(): 393 print(name) 394 for pmap in pmaps: 395 print(pmap.section, pmap._chapter._relpath) 396 print(RenderTree(pmap, maxlevel=2)) 397 398 memtrees = _build_device_trees(ds, peripheral_types, instance_offsets) 399 # for tree in memtrees: 400 # print(RenderTree(tree, maxlevel=2)) 401 # exit(1) 402 memtrees = _compactify_device_trees(memtrees) 403 memtrees = [_normalize_order(memtree) for memtree in memtrees] 404 return memtrees