mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
c49d80628c
commit
fa928e8cd3
+20
-4
@@ -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]))
|
||||
|
||||
Reference in New Issue
Block a user