Skip to content

Commit bfd67e9

Browse files
committed
Fix TypeError where address_offset and base_address are treated as strings
This happened for example for the rp2040 pac: ``` $ svd patch svd/rp2040.yaml Traceback (most recent call last): File "/home/jan/.local/bin/svd", line 10, in <module> sys.exit(svdtools_cli()) File "/home/jan/.local/lib/python3.7/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "/home/jan/.local/lib/python3.7/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/jan/.local/lib/python3.7/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/jan/.local/lib/python3.7/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/jan/.local/lib/python3.7/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/home/jan/.local/lib/python3.7/site-packages/svdtools/cli.py", line 16, in patch svdtools.patch.main(yaml_file) File "/home/jan/.local/lib/python3.7/site-packages/svdtools/patch.py", line 1639, in main process_device(svd, root) File "/home/jan/.local/lib/python3.7/site-packages/svdtools/patch.py", line 1616, in process_device d.process_peripheral(periphspec, device[periphspec], update_fields) File "/home/jan/.local/lib/python3.7/site-packages/svdtools/patch.py", line 717, in process_peripheral p.derive_register(rname, rderive) File "/home/jan/.local/lib/python3.7/site-packages/svdtools/patch.py", line 865, in derive_register ET.SubElement(rtag, "addressOffset").text = address_offset File "src/lxml/etree.pyx", line 1041, in lxml.etree._Element.text.__set__ File "src/lxml/apihelpers.pxi", line 748, in lxml.etree._setNodeText File "src/lxml/apihelpers.pxi", line 736, in lxml.etree._createTextNode File "src/lxml/apihelpers.pxi", line 1539, in lxml.etree._utf8 TypeError: Argument must be bytes or unicode, got 'int' ``` To fix that error, convert the addresses to hex strings explicitly.
1 parent e2a9f85 commit bfd67e9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

svdtools/patch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,14 +530,14 @@ def derive_peripheral(self, pname, pmod):
530530
if ptag is None:
531531
ptag = ET.SubElement(parent, "register")
532532
ET.SubElement(ptag, "name").text = pname
533-
ET.SubElement(ptag, "addressOffset").text = base_address
533+
ET.SubElement(ptag, "addressOffset").text = hex(base_address)
534534
else:
535535
for value in list(ptag):
536536
if value.tag in ("name", "baseAddress", "interrupt", "description"):
537537
continue
538538
ptag.remove(value)
539539
if base_address:
540-
ptag.find("baseAddress").text = base_address
540+
ptag.find("baseAddress").text = hex(base_address)
541541
if description:
542542
ptag.find("description").text = description
543543
for value in ptag:
@@ -862,14 +862,14 @@ def derive_register(self, rname, rmod):
862862
if rtag is None:
863863
rtag = ET.SubElement(parent, "register")
864864
ET.SubElement(rtag, "name").text = rname
865-
ET.SubElement(rtag, "addressOffset").text = address_offset
865+
ET.SubElement(rtag, "addressOffset").text = hex(address_offset)
866866
else:
867867
for value in list(rtag):
868868
if value.tag in ("name", "addressOffset", "description"):
869869
continue
870870
rtag.remove(value)
871871
if address_offset:
872-
rtag.find("addressOffset").text = address_offset
872+
rtag.find("addressOffset").text = hex(address_offset)
873873
if description:
874874
rtag.find("description").text = description
875875
for value in rtag:

0 commit comments

Comments
 (0)