-
Notifications
You must be signed in to change notification settings - Fork 151
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
Support field arrays #44
Comments
I propose the following:
If there are gaps then 1 of 2 things can happen:
|
Doesn't SVD natively support this kind of arrays? I would argue this is a definition bug (or at least should be handled by an SVD-to-SVD transformation...) |
@whitequark It does but, IIRC, the problem was that sometimes the memory layout is 'A B C A B C A B C' but instead of having a "A B C repeats itself N times at address 0x0" in the SVD, you have "C repeats N times at address 0x8 with offset pattern of 0xC", "A repeats N times at address 0x4 with offset pattern of 0xC", "B1 is at address 0x4", "B2 is at address 0x10", etc. so I punted on it because it wasn't trivial to merge those bits of information and just "unrolled" all the array information in what you see in the issue description. |
I ran into what I think is a similar problem recently while trying to come up with generic GPIO pin code for the stm32f41x - using the standard svd file and svd2rust I end up with a huge number of differently typed/named pin control functions, and that in turn forces me to write big match statements to convert a port and pin number to a pin control function. I tried to modify the svd file I was using to use svd dim arrays for GPIO ports and pins, and I think svd2rust supports that at the register level, but not at the field level. Am I trying to do a thing (simplify GPIO pin control code by making the pin register interface more uniform and array based) that is not intended? Am I missing an alternative to large match blocks that I could use instead? Alternately, if other people have the same problems, would it be helpful to implement SVD arrays for fields? |
This sounds like the right path here to me. |
Depending on what exactly you are doing you could simply use the
It actually seems that SVD does support field arrays but I have never encountered one in a SVD file provided by a vendor. Also, I don't know how that would map to Rust code. Register arrays make sense because a register maps to a Rust integer type in size (u8, u16, u32) so a field with type |
The
I suppose it is possible to use
My opinion here is that I'd like to move all the bitwise arithmetic into generated code so that the bugs can be fixed once and won't occur in code layered on top of svd2rust translations. As you're the driving force in the rust embedded ecosystem @japaric, I would love to know what your plan is on this stuff. (I would also like (where the hardware actually does all behave the same over all the instances of it) for that Led code to be generic over port and pin number so that you could say wire additional leds to unused pins on a board and not need to modify any code other than the array of Leds) |
Thanks for the examples, @archaelus. I think the We should start by finding some official vendor SVD that makes uses of arrays for fields. Or read carefully the SVD spec and add arrays to an existing SVD fiel, and probably run the XML linter on it as well. Then there is at least one unresolved question about your API. What should be the behavior when one calls
You can already do that. All the GPIO instances that have the same register block layout are actually newtypes over a common register block type and implement struct Led<'a, P>
where
P: Deref<Target = gpioa::RegisterBlock>
{
port: &'a P,
pin: u8,
}
let pa0 = Led { port: gpioa, pin: 0 };
let pb1 = Led { port: gpiob, pin: 1 }; Or you could maybe turn the port into a phantom type to drop the |
related issue: #90 (non contiguous register arrays) |
People seem to agree that this issue is more about supporting field arrays, so maybe it's a good idea to rename it to reflect this? Or maybe make a new issue about field array support and refer to it here? I noticed the lack of support for this myself and only found that it's discussed here by obsessively reading issues :) |
Yeah, that was my fault. I mistitled the issue about being about field arrays when the issue description was talking about register arrays. I'll ... just create another issue about the original issue. |
I think this would help/resolve one of the things I've bumped into in my code. I'll explain it here in case it's not quite the same. I want to have a nice api over the ADCs that will allow channels to be turned on with a call like: I've implemented this with a bunch of nested macros making match statements which results in 34000 lines of code. This is because there are 3 adc * 18 channels * 16 ranks * 8 sample time cycle counts = 6912 unique combinations of register configuration. I believe the compiler will get rid of all the branches that aren't used and inline the actually used bits but I've not checked this at all - for now I'm just happy if it works. This is what 1 branch of the huge match statement looks like for reference:
|
This is done in #400, released in v0.18, right? |
Start here
The text was updated successfully, but these errors were encountered: