mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-12 06:53:40 +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 re
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
validName = re.compile('^[a-zA-Z0-9_]+$')
|
||||||
|
|
||||||
|
|
||||||
class Device:
|
class Device:
|
||||||
# dummy
|
# dummy
|
||||||
pass
|
pass
|
||||||
@@ -23,6 +26,13 @@ def formatText(text):
|
|||||||
text = text.strip()
|
text = text.strip()
|
||||||
return text
|
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):
|
def readSVD(path, sourceURL):
|
||||||
# Read ARM SVD files.
|
# Read ARM SVD files.
|
||||||
device = Device()
|
device = Device()
|
||||||
@@ -54,7 +64,9 @@ def readSVD(path, sourceURL):
|
|||||||
groupNameTags = periphEl.findall('groupName')
|
groupNameTags = periphEl.findall('groupName')
|
||||||
groupName = None
|
groupName = None
|
||||||
if groupNameTags:
|
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')
|
interruptEls = periphEl.findall('interrupt')
|
||||||
for interrupt in interruptEls:
|
for interrupt in interruptEls:
|
||||||
@@ -180,7 +192,9 @@ def readSVD(path, sourceURL):
|
|||||||
def addInterrupt(interrupts, intrName, intrIndex, description):
|
def addInterrupt(interrupts, intrName, intrIndex, description):
|
||||||
if intrName in interrupts:
|
if intrName in interrupts:
|
||||||
if interrupts[intrName]['index'] != intrIndex:
|
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))
|
% (intrName, interrupts[intrName]['index'], intrIndex))
|
||||||
if description not in interrupts[intrName]['description'].split(' // '):
|
if description not in interrupts[intrName]['description'].split(' // '):
|
||||||
interrupts[intrName]['description'] += ' // ' + description
|
interrupts[intrName]['description'] += ' // ' + description
|
||||||
@@ -195,8 +209,10 @@ def parseBitfields(groupName, regName, fieldsEls, bitfieldPrefix=''):
|
|||||||
fields = []
|
fields = []
|
||||||
if fieldsEls:
|
if fieldsEls:
|
||||||
for fieldEl in fieldsEls[0].findall('field'):
|
for fieldEl in fieldsEls[0].findall('field'):
|
||||||
fieldName = getText(fieldEl.find('name'))
|
# Some bitfields (like the STM32H7x7) contain invalid bitfield
|
||||||
descrEls = fieldEl.findall('description')
|
# names like 'CNT[31]'. Replace invalid characters with '_' when
|
||||||
|
# needed.
|
||||||
|
fieldName = cleanName(getText(fieldEl.find('name')))
|
||||||
lsbTags = fieldEl.findall('lsb')
|
lsbTags = fieldEl.findall('lsb')
|
||||||
if len(lsbTags) == 1:
|
if len(lsbTags) == 1:
|
||||||
lsb = int(getText(lsbTags[0]))
|
lsb = int(getText(lsbTags[0]))
|
||||||
|
|||||||
Reference in New Issue
Block a user