aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-07-06 15:51:53 +0200
committerRon Evans <[email protected]>2019-07-06 17:16:18 +0200
commitfa928e8cd34bd63db41d96dd28a686e283324ccf (patch)
treebb83c366d1da79218dabb5f68fcbde9203b791f9
parentc49d80628cf1bbd3623be856dc42f189100c3341 (diff)
downloadtinygo-fa928e8cd34bd63db41d96dd28a686e283324ccf.tar.gz
tinygo-fa928e8cd34bd63db41d96dd28a686e283324ccf.zip
tools/gen-device-svd: be a bit more forgiving for stm32 svd files
Some newer files have a few mistakes. Allow them to be processed.
-rwxr-xr-xtools/gen-device-svd.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/tools/gen-device-svd.py b/tools/gen-device-svd.py
index 049710c9f..0f6085fac 100755
--- a/tools/gen-device-svd.py
+++ b/tools/gen-device-svd.py
@@ -8,6 +8,9 @@ from collections import OrderedDict
import re
import argparse
+validName = re.compile('^[a-zA-Z0-9_]+$')
+
+
class Device:
# dummy
pass
@@ -23,6 +26,13 @@ def formatText(text):
text = text.strip()
return text
+# Replace characters that are not allowed in a symbol name with a '_'. This is
+# useful to be able to process SVD files with errors.
+def cleanName(text):
+ if not validName.match(text):
+ return ''.join(list(map(lambda c: c if validName.match(c) else '_', text)))
+ return text
+
def readSVD(path, sourceURL):
# Read ARM SVD files.
device = Device()
@@ -54,7 +64,9 @@ def readSVD(path, sourceURL):
groupNameTags = periphEl.findall('groupName')
groupName = None
if groupNameTags:
- groupName = getText(groupNameTags[0])
+ # Some group names (for example the STM32H7A3x) have an invalid
+ # group name. Replace invalid characters with '_'.
+ groupName = cleanName(getText(groupNameTags[0]))
interruptEls = periphEl.findall('interrupt')
for interrupt in interruptEls:
@@ -180,7 +192,9 @@ def readSVD(path, sourceURL):
def addInterrupt(interrupts, intrName, intrIndex, description):
if intrName in interrupts:
if interrupts[intrName]['index'] != intrIndex:
- raise ValueError('interrupt with the same name has different indexes: %s (%d vs %d)'
+ # Note: some SVD files like the one for STM32H7x7 contain mistakes.
+ # Instead of throwing an error, simply log it.
+ print ('interrupt with the same name has different indexes: %s (%d vs %d)'
% (intrName, interrupts[intrName]['index'], intrIndex))
if description not in interrupts[intrName]['description'].split(' // '):
interrupts[intrName]['description'] += ' // ' + description
@@ -195,8 +209,10 @@ def parseBitfields(groupName, regName, fieldsEls, bitfieldPrefix=''):
fields = []
if fieldsEls:
for fieldEl in fieldsEls[0].findall('field'):
- fieldName = getText(fieldEl.find('name'))
- descrEls = fieldEl.findall('description')
+ # Some bitfields (like the STM32H7x7) contain invalid bitfield
+ # names like 'CNT[31]'. Replace invalid characters with '_' when
+ # needed.
+ fieldName = cleanName(getText(fieldEl.find('name')))
lsbTags = fieldEl.findall('lsb')
if len(lsbTags) == 1:
lsb = int(getText(lsbTags[0]))