-
Notifications
You must be signed in to change notification settings - Fork 156
don't generate core peripherals if SVD is explicitly not Cortex M #117
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
Conversation
Perhaps this can be made even more generic, by adding a When your CPU is not cortex-m some may also want to use another base crate instead of |
I do agree that the dependency on Would all general embedded features (like Or rather implement these general embedded features in the file generated from svd2rust and make it self contained? Would it be worth doing since "most" MCUs with svd files are ARM cores? |
This seems OK as a first step but the generated file will still contain a dependency on the @ahixon Could you tell us more about your target device? Cortex A? non ARM device? |
Yeah, the end-goal was basically to remove the hard dependency on the as @kjetilkjeka mentions, that probably means I think the former makes the most sense anyway. @japaric The target device is a Rockchip RK3399. It has a dual-core Cortex-A72 and quad-core Cortex-A53, as well as two separate Cortex-M0 cores. Currently, svd2rust sticks in all the Cortex peripherals in the Cortex A library; which isn't a problem as long as you make sure your code doesn't use them, but they don't really belong there. Also interestingly, the Cortex-M0's peripheral blocks are just memory mapped to the AP's peripheral set, so the ones svd2rust generates aren't actually valid there either (i.e. they are not the standard ones provided by the ARMv7 spec). |
I'm in favor of sharing abstractions like Looking just at svd2rust generated code these are the cortex-m things it depends on:
Looking at the msp430 and cortex-m crates these are the things they share in common:
So it probably makes sense to put all those in common crate, and have svd2rust generated code directly depend on the common crate rather than on cortex-m or msp430. The big question is how do we call that common crate? @ahixon We may be able to get away with doing this without breaking the cortex-m crate if the cortex-m crate re-exports all the common crate API exactly where it currently provides e.g. |
svd2rust generated code also depends on Also there is still one open question, do we go with cpu section in SVD file, like is suggested by this patch, or do we have a command line switch. I don't have a strong preference here, but it has to be decided at some point. |
I took a stab at extracting the common bits. The common crate contains the bits that both cortex-m and msp430 can reuse. @pftbest Could you test if you can implement your msp430 crate on top of the common crate? @ahixon How much of the common crate can you use for your use case? Note that the common crate is missing an implementation of critical sections so you would have to create your own. I suppose that the criticical section in the cortex-m crate (interrupt::free) is applicable for your use case but you probably don't want to depend on the cortex-m crate. I also made a branch where I have changed the cortex-m crate to re-export all the stuff in common rather than re-implement it. I believe the public interface hasn't changed with this refactor. Finally I tried to make svd2rust generated code not depend on the cortex-m crate. I found two problems:
I have a revamp of the interrupt/exception registration mechanism in the works which might make the second problem disappear but I have yet to post a RFC on the topic. |
My preference would be a command line switch instead of trying to make svd2rust "too smart". cpu.name is an enumeration as per the SVD spec and there's no MSP430 variant in it so we probably can't do option 1 in any case. |
@japaric I've merged your patch in branch common, and it looks good. The one example project based on msp430g2553 crate that I use for testing didn't show any regressions. |
Yeah, probably makes sense then we just go the command line flag route, if there's also the Possibly the default interrupt handler could then be sourced from whatever crate is specified via the command line? @japaric all the Cortex-A stuff I've been doing so far runs with interrupts disabled, so I haven't written any interrupt handling support yet (I'm not sure if I'll even end up doing that for my project). However, if I do, it will require some special thought since I need to worry about multiple exception tables for each Exception Level, and configuring the GIC. The M0, will, yeah, probably have the same Because of that, I'll probably be supplementing the interrupt stuff from a separate tool and simply rely on svd2rust for peripheral generation. |
@pftbest Thanks for testing. BTW, could you open an issue about the svd2rust changes you had to do to get it working with msp430? @ahixon I hope that cortex_m::exception::default_handler won't be required once I refactor the exception registration stuff. I suppose that for your use case you want a We need a better name for the |
I have opened an RFC about the exception registration refactor in rust-embedded/cortex-m#51. The required svd2rust changes are in #118. With those changes the generated crate will no longer depend on cortex-m's |
☔ The latest upstream changes (presumably 5e2da93) made this pull request unmergeable. Please resolve the merge conflicts. |
Although the SVD spec states:
a bunch of SVDs from vendors (eg Fujistu) don't define a
cpu
element.So, to avoid any regression, svd2rust will continue to generate core peripherals even if it isn't specified. It will only skip generation if the cpu
name
tag is a non-Cortex M CPU.Relies on rust-embedded/svd#34