diff --git a/.gitmodules b/.gitmodules index c877bbafb6..0806c1ab23 100644 --- a/.gitmodules +++ b/.gitmodules @@ -20,3 +20,6 @@ [submodule "lib/picolibc"] path = lib/picolibc url = https://github.com/keith-packard/picolibc.git +[submodule "lib/stm32-rs"] + path = lib/stm32-rs + url = https://github.com/stm32-rs/stm32-rs.git diff --git a/Makefile b/Makefile index ac9284bacb..78bb6455ce 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,12 @@ gen-device-kendryte: build/gen-device-svd GO111MODULE=off $(GO) fmt ./src/device/kendryte gen-device-stm32: build/gen-device-svd - ./build/gen-device-svd -source=https://github.com/posborne/cmsis-svd/tree/master/data/STMicro lib/cmsis-svd/data/STMicro/ src/device/stm32/ + make -C ./lib/stm32-rs/ svd/.extracted + make -C ./lib/stm32-rs/ patch + mkdir -p ./lib/stm32-rs/patched + $(foreach file, $(wildcard ./lib/stm32-rs/svd/*.svd.patched), \ + cp $(file) $(patsubst ./lib/stm32-rs/svd/%.svd.patched,./lib/stm32-rs/patched/%.svd,$(file)) &&) true + ./build/gen-device-svd -source=https://github.com/stm32-rs/stm32-rs lib/stm32-rs/patched/ src/device/stm32/ GO111MODULE=off $(GO) fmt ./src/device/stm32 diff --git a/lib/stm32-rs b/lib/stm32-rs new file mode 160000 index 0000000000..9d283001fc --- /dev/null +++ b/lib/stm32-rs @@ -0,0 +1 @@ +Subproject commit 9d283001fc29523612835086977af150703b126b diff --git a/tools/gen-device-svd/gen-device-svd.go b/tools/gen-device-svd/gen-device-svd.go index 4c8867ab2a..8617778f4d 100755 --- a/tools/gen-device-svd/gen-device-svd.go +++ b/tools/gen-device-svd/gen-device-svd.go @@ -61,10 +61,14 @@ type SVDField struct { BitWidth *uint32 `xml:"bitWidth"` BitRange *string `xml:"bitRange"` EnumeratedValues []struct { - Name string `xml:"name"` - Description string `xml:"description"` - Value string `xml:"value"` - } `xml:"enumeratedValues>enumeratedValue"` + Name string `xml:"name"` + Usage string `xml:"usage"` + Values []struct { + Name string `xml:"name"` + Description string `xml:"description"` + Value string `xml:"value"` + } `xml:"enumeratedValue"` + } `xml:"enumeratedValues"` } type SVDCluster struct { @@ -528,35 +532,51 @@ func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPre value: 1 << lsb, }) } - for _, enumEl := range fieldEl.EnumeratedValues { - enumName := enumEl.Name - if strings.EqualFold(enumName, "reserved") || !validName.MatchString(enumName) { - continue - } - if !unicode.IsUpper(rune(enumName[0])) && !unicode.IsDigit(rune(enumName[0])) { - enumName = strings.ToUpper(enumName) + + hasUsageSuffix := len(fieldEl.EnumeratedValues) > 1 + for _, enumsEl := range fieldEl.EnumeratedValues { + usageSuffix := "" + if hasUsageSuffix { + switch enumsEl.Usage { + case "read": + usageSuffix = "_R" + case "write": + usageSuffix = "_W" + case "read-write": + usageSuffix = "_RW" + } } - enumDescription := strings.Replace(enumEl.Description, "\n", " ", -1) - enumValue, err := strconv.ParseUint(enumEl.Value, 0, 32) - if err != nil { - if enumBitSpecifier.MatchString(enumEl.Value) { - // NXP SVDs use the form #xx1x, #x0xx, etc for values - enumValue, err = strconv.ParseUint(strings.Replace(enumEl.Value[1:], "x", "0", -1), 2, 32) - if err != nil { + + for _, enumEl := range enumsEl.Values { + enumName := enumEl.Name + if strings.EqualFold(enumName, "reserved") || !validName.MatchString(enumName) { + continue + } + if !unicode.IsUpper(rune(enumName[0])) && !unicode.IsDigit(rune(enumName[0])) { + enumName = strings.ToUpper(enumName) + } + enumDescription := strings.Replace(enumEl.Description, "\n", " ", -1) + enumValue, err := strconv.ParseUint(enumEl.Value, 0, 32) + if err != nil { + if enumBitSpecifier.MatchString(enumEl.Value) { + // NXP SVDs use the form #xx1x, #x0xx, etc for values + enumValue, err = strconv.ParseUint(strings.Replace(enumEl.Value[1:], "x", "0", -1), 2, 32) + if err != nil { + panic(err) + } + } else { panic(err) } - } else { - panic(err) } + enumName = fmt.Sprintf("%s_%s%s_%s_%s%s", groupName, bitfieldPrefix, regName, fieldName, enumName, usageSuffix) + _, seen := enumSeen[enumName] + enumSeen[enumName] = seen + fields = append(fields, Bitfield{ + name: enumName, + description: enumDescription, + value: uint32(enumValue), + }) } - enumName = fmt.Sprintf("%s_%s%s_%s_%s", groupName, bitfieldPrefix, regName, fieldName, enumName) - _, seen := enumSeen[enumName] - enumSeen[enumName] = seen - fields = append(fields, Bitfield{ - name: enumName, - description: enumDescription, - value: uint32(enumValue), - }) } } // check if any of the field names appeared more than once. if so, append