aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2018-09-22 01:05:22 +0200
committerAyke van Laethem <[email protected]>2018-09-22 01:05:22 +0200
commitd841daa32b3b61ead4b5f439c993ec9213d83751 (patch)
treec019112fa9ecf3d4f9b291658f089cdbec18922a /tools
parent9fa08bf51d5084eb3e24d814e7d512090b2e7ae2 (diff)
downloadtinygo-d841daa32b3b61ead4b5f439c993ec9213d83751.tar.gz
tinygo-d841daa32b3b61ead4b5f439c993ec9213d83751.zip
tools/gen-device-svd: emit correct Go code for stm32
Groups were not recognized because the parser only looked at the derivedFrom attribute and not at <groupName> tags for matching peripherals.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-svd.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/tools/gen-device-svd.py b/tools/gen-device-svd.py
index efa9fd56f..ca9a338ef 100755
--- a/tools/gen-device-svd.py
+++ b/tools/gen-device-svd.py
@@ -41,6 +41,7 @@ def readSVD(path):
device.peripherals = []
peripheralDict = {}
+ groups = {}
interrupts = OrderedDict()
@@ -52,25 +53,29 @@ def readSVD(path):
description = formatText(getText(descriptionTags[0]))
baseAddress = int(getText(periphEl.getElementsByTagName('baseAddress')[0]), 0)
groupNameTags = periphEl.getElementsByTagName('groupName')
- groupName = name
+ groupName = None
if groupNameTags:
groupName = getText(groupNameTags[0])
- if periphEl.hasAttribute('derivedFrom'):
- derivedFromName = periphEl.getAttribute('derivedFrom')
- derivedFrom = peripheralDict[derivedFromName]
+ if periphEl.hasAttribute('derivedFrom') or groupName in groups:
+ if periphEl.hasAttribute('derivedFrom'):
+ derivedFromName = periphEl.getAttribute('derivedFrom')
+ derivedFrom = peripheralDict[derivedFromName]
+ else:
+ derivedFrom = groups[groupName]
peripheral = {
'name': name,
'groupName': derivedFrom['groupName'],
- 'description': description if description is not None else derivedFrom['description'],
+ 'description': description or derivedFrom['description'],
'baseAddress': baseAddress,
}
device.peripherals.append(peripheral)
+ peripheralDict[name] = peripheral
continue
peripheral = {
'name': name,
- 'groupName': groupName,
+ 'groupName': groupName or name,
'description': description,
'baseAddress': baseAddress,
'registers': [],
@@ -78,6 +83,9 @@ def readSVD(path):
device.peripherals.append(peripheral)
peripheralDict[name] = peripheral
+ if groupName and groupName not in groups:
+ groups[groupName] = peripheral
+
for interrupt in periphEl.getElementsByTagName('interrupt'):
intrName = getText(interrupt.getElementsByTagName('name')[0])
intrIndex = int(getText(interrupt.getElementsByTagName('value')[0]))
@@ -96,7 +104,7 @@ def readSVD(path):
if regsEls:
for el in regsEls[0].childNodes:
if el.nodeName == 'register':
- peripheral['registers'].append(parseSVDRegister(groupName, el, baseAddress))
+ peripheral['registers'].append(parseSVDRegister(groupName or name, el, baseAddress))
elif el.nodeName == 'cluster':
if el.getElementsByTagName('dim'):
continue # TODO
@@ -104,7 +112,7 @@ def readSVD(path):
clusterOffset = int(getText(el.getElementsByTagName('addressOffset')[0]), 0)
for regEl in el.childNodes:
if regEl.nodeName == 'register':
- peripheral['registers'].append(parseSVDRegister(groupName, regEl, baseAddress + clusterOffset, clusterPrefix))
+ peripheral['registers'].append(parseSVDRegister(groupName or name, regEl, baseAddress + clusterOffset, clusterPrefix))
else:
continue