8
8
import re
9
9
import argparse
10
10
11
+ validName = re .compile ('^[a-zA-Z0-9_]+$' )
12
+
13
+
11
14
class Device :
12
15
# dummy
13
16
pass
@@ -23,6 +26,13 @@ def formatText(text):
23
26
text = text .strip ()
24
27
return text
25
28
29
+ # Replace characters that are not allowed in a symbol name with a '_'. This is
30
+ # useful to be able to process SVD files with errors.
31
+ def cleanName (text ):
32
+ if not validName .match (text ):
33
+ return '' .join (list (map (lambda c : c if validName .match (c ) else '_' , text )))
34
+ return text
35
+
26
36
def readSVD (path , sourceURL ):
27
37
# Read ARM SVD files.
28
38
device = Device ()
@@ -54,7 +64,9 @@ def readSVD(path, sourceURL):
54
64
groupNameTags = periphEl .findall ('groupName' )
55
65
groupName = None
56
66
if groupNameTags :
57
- groupName = getText (groupNameTags [0 ])
67
+ # Some group names (for example the STM32H7A3x) have an invalid
68
+ # group name. Replace invalid characters with '_'.
69
+ groupName = cleanName (getText (groupNameTags [0 ]))
58
70
59
71
interruptEls = periphEl .findall ('interrupt' )
60
72
for interrupt in interruptEls :
@@ -180,7 +192,9 @@ def readSVD(path, sourceURL):
180
192
def addInterrupt (interrupts , intrName , intrIndex , description ):
181
193
if intrName in interrupts :
182
194
if interrupts [intrName ]['index' ] != intrIndex :
183
- raise ValueError ('interrupt with the same name has different indexes: %s (%d vs %d)'
195
+ # Note: some SVD files like the one for STM32H7x7 contain mistakes.
196
+ # Instead of throwing an error, simply log it.
197
+ print ('interrupt with the same name has different indexes: %s (%d vs %d)'
184
198
% (intrName , interrupts [intrName ]['index' ], intrIndex ))
185
199
if description not in interrupts [intrName ]['description' ].split (' // ' ):
186
200
interrupts [intrName ]['description' ] += ' // ' + description
@@ -195,8 +209,10 @@ def parseBitfields(groupName, regName, fieldsEls, bitfieldPrefix=''):
195
209
fields = []
196
210
if fieldsEls :
197
211
for fieldEl in fieldsEls [0 ].findall ('field' ):
198
- fieldName = getText (fieldEl .find ('name' ))
199
- descrEls = fieldEl .findall ('description' )
212
+ # Some bitfields (like the STM32H7x7) contain invalid bitfield
213
+ # names like 'CNT[31]'. Replace invalid characters with '_' when
214
+ # needed.
215
+ fieldName = cleanName (getText (fieldEl .find ('name' )))
200
216
lsbTags = fieldEl .findall ('lsb' )
201
217
if len (lsbTags ) == 1 :
202
218
lsb = int (getText (lsbTags [0 ]))
0 commit comments