rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
707 stars 151 forks source link

Thoughts on supplementing svd with other sources (.h files) primarily for enumerated values? #159

Open cs2dsb opened 6 years ago

cs2dsb commented 6 years ago

I’ve been using a device crate generated by svd2rust for a project I’m working on and have found the lack of enumerated values defined in my svd quite annoying. It seems ST haven’t added them in most cases.

I’ve been adding them myself from the reference manual as I need them but it’s tedious work.

I was wondering about parsing .h files from the stm cmsis and possibly libopencm3 to get these enumerated values added to the svds.

The cmsis files (for example stm32f303ze.h) contain some in the form peripheral_register_field_enumname. If you discount enum names that are only digits you get a clean looking list. There are some obvious missing ones but it’s a lot better than the svd alone.

I looked around for community driven projects and found libopencm3 which seems to have a fairly complete set (for example).

Has anyone looked into extracting this info from existing libraries? Any thoughts on if it’s worth trying?

japaric commented 6 years ago

👍 for creating tools that add information to SVD files from any other source.

👎 for adding such functionality (e.g. C header parser) to svd2rust, itself. I don't think you were proposing this, though.

I think someone wrote a (Python?) tool for making edition of SVD files easier (i.e. make it easier to add enumeratedValues info) but don't recall any of the details. Perhaps @cr1901 or j_ey (forgot their GH username) know / remember about it?

jgouly commented 6 years ago

Sorry, must be thinking of someone else. I've avoided SVD files so far.

brandonedens commented 6 years ago

@japaric the Python script is discussed here: https://github.com/hackndev/zinc/issues/327 maybe?

jamesmunns commented 6 years ago

@cs2dsb have you had a look at bindgen before? You might be able to use a combo of svd2rust and bindgen to get all the info you need, and perhaps blend them together to make a unified API.

ryankurte commented 6 years ago

This should be reasonably easy to implement in rust (if that's desired) once we land svd generation in svd#46.