Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions lib/stm32-rs
Submodule stm32-rs added at 9d2830
76 changes: 48 additions & 28 deletions tools/gen-device-svd/gen-device-svd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down