Skip to content

Commit 0866451

Browse files
committed
tools/gen: ignore cluster registers with no actual clusters in them, and handle parsing binary integer fields in versions of Go before 1.13
Signed-off-by: deadprogram <[email protected]>
1 parent cf930f6 commit 0866451

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tools/gen-device-svd/gen-device-svd.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func readSVD(path, sourceURL string) (*Device, error) {
350350
sort.SliceStable(clusterRegisters, func(i, j int) bool {
351351
return clusterRegisters[i].address < clusterRegisters[j].address
352352
})
353-
if dimIncrement == -1 {
353+
if dimIncrement == -1 && len(clusterRegisters) > 0 {
354354
lastReg := clusterRegisters[len(clusterRegisters)-1]
355355
lastAddress := lastReg.address
356356
if lastReg.array != -1 {
@@ -537,7 +537,14 @@ func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPre
537537
enumName = strings.ToUpper(enumName)
538538
}
539539
enumDescription := strings.Replace(enumEl.Description, "\n", " ", -1)
540-
enumValue, err := strconv.ParseUint(enumEl.Value, 0, 32)
540+
var enumValue uint64
541+
var err error
542+
if strings.HasPrefix(enumEl.Value, "0b") {
543+
val := strings.TrimPrefix(enumEl.Value, "0b")
544+
enumValue, err = strconv.ParseUint(val, 2, 32)
545+
} else {
546+
enumValue, err = strconv.ParseUint(enumEl.Value, 0, 32)
547+
}
541548
if err != nil {
542549
if enumBitSpecifier.MatchString(enumEl.Value) {
543550
// NXP SVDs use the form #xx1x, #x0xx, etc for values

0 commit comments

Comments
 (0)