-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
svd2rust support for autogenerating ARM device drivers/memory maps #10
Comments
👍 I'm the maintainer of https://github.com/posborne/cmsis-svd which currently has a bunch of SVD files from various vendors and a reference SVD parser in python. Generating definitions for Rust would not necessarily require the parser to be in Rust, but I am not opposed to it by any means. This is something we have explored some on Zinc: hackndev/zinc#327 |
@posborne Thanks for cmsis-svd! I'm using the "bunch of SVD files" in my svd parser as a test suite. @cwoodall I haven't look at svd2ada yet but I expect they generate an API that does a bunch of validation at compile time thanks to its integer ranges and what not (I'm not really familiar with Ada). I have a hacky, unpublished svd -> Rust generator where I'm using my svd parser plus the awesome aster to generate Rust One important thing to consider when writing svd2rust is that there are SVD files of different qualities out there. For example, the STM32 ones that I've seen don't make use of |
Out of interest, how does SVD compare/contrast to DeviceTree? |
For reference device tree and svd. I haven't compared them yet, but both seemed like good resources. |
SVD is a more pure description of a particular processor whereas Device Tree typically contains more configuration that is specific to a given design. I would never create an SVD to describe my board (using a particular SoC) but this is exactly what I do frequently for board bringup with embedded Linux on various SoCs. |
@posborne Thanks! |
Hi folks. I built a SVD to Rust source code generator as CLI or Rust macro. Its called svd-mmap and is available at: It needs a little more work; a README and possible alternative backend to Zinc's VolatileCell that I've locally modified to work xargo built cores. I'll also post some of my example usage of the software in short order. |
Awesome, @brandonedens! For those that want to try out
|
I've published my generator as well: svd2rust! Which I've just started using in f3 (cf. japaric/f3#22). It's main differences with ioregs are:
|
Neat. I'll poke through svd2rust as soon as possible and investigate switching to volatile-register. I'm also going to look at a possible pull request against Zinc to swap out ioreg for SVD generated hardware interface. A basic README.md is now present in the svd-mmap repo. I noticed the aster breakage as well. Hopefully aster / quasi fix soon; they tend to be quick (otherwise I'll maybe issue the pull request Monday or so). svd-mmap is set to use aster / quasi version "*" so the fixes should immediately percolate. I'll also add a .ld emitter as a CLI argument to svd-mmap. |
Yes, please. I think it's a great idea to breathe some life back into Zinc. If they check in generated register maps instead of re-rebuilding them at build time using
Someone already sent a PR fixing aster but it hasn't been merged yet. I think it's healthy to have competition / choices in the svd -> rust generator space. It's relatively easy to build one today using |
Aster 0.30.0 is out with a fix for the most recent nightlies. Sorry about the delay - this was the most complicated merge conflict we have had in a long time because there were significant changes to macro expansion in libsyntax. |
@dtolnay no worries! That build error prompted us to look into syn+quote and we have already ported svd2rust to it 😄. BTW, syn and quote are really nice to use, thanks for creating them ❤️. |
Any thoughts on strategies for generating shared register access layers within a chip family, particularly in a way that can be used as a base for a common HAL? I'm thinking a vendor-specific HAL similar to the libraries that most provide in C as part of their SDKs, not higher-level cross-vendor traits such as Serial I/O. I've spent a couple of weeks working on SVD tooling (including testing some non-XML representations that may be easier to work with by hand and to extend) but I'm having a tough time picturing a way to do this without either (a) building massive register access modules for each individual device and selecting between them at a high level with #cfg switches, or (b) building a single register access module with massive amounts of #cfg switches down at individual registers. I'm finding that compile time starts becoming an issue when you start doing codegen for all of the peripherals for a device, and I imagine it would become much worse if you have 4-6 different sets in a single crate. Or are we simply going to have to live with building and maintaining independent crates for each class of device, including startup code, clock management, etc? |
So svd2rust has been out there for a while and it has more users and developers than just me 😄. Also, @whitequark wrote the dslite2svd tool which you can use to convert TI's version of SVD to standard SVD and then feed to svd2rust. Can we consider this issue done? Further discussion about the API that svd2rust generates should be discussed on its issue tracker. @jcsoo SVD files usually describe whole device families (or at least the STM32 ones do). For example, the |
@japaric btw,
from https://users.rust-lang.org/t/zinc-mini-post-mortem/7079 |
@whitequark I know. I saw that post back when it was first posted, but there was still some activity in the repo when I made this comment. Today, Zinc has seen no activity for like 5+ months, so I think it's time to let it rest in peace. |
I'm going to close this since svd2rust already exists. If you would like to raise an issue against that implementation please open a ticker in the issue tracker. On that note, I would like to request your help to improve svd2rust! I have created a cmsis-svd milestone that tracks progress towards making svd2rust work with all the SVD files in the cmsis-svd database. I think those issues should be prioritized since some people are hitting bugs in svd2rust when using it with files that are not part of the current svd2rust test suite (which is rather small atm). |
Rust should support the ability to autogenerate device drivers/memory maps from SVD files similar to the ARM CMSIS support or the AdaCore support for for Ada provided by svd2ada.
I know that @japaric started working on this in the japaric/svd repository, but I think in the long run this would go a long way to improving Rusts ability to compete in the ecosystem. The team at AdaCore has been doing some great work building out Ada support for embedded systems, while their model is a little more centralized than the more modular nature of the rust community, it would be interesting to be able to match their capabilities one day.
The text was updated successfully, but these errors were encountered: