-
Notifications
You must be signed in to change notification settings - Fork 101
Supporting adafruit ATSAMD21 based boards #61
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
Comments
I'm interested in this as well, and would have published said The biggest missing svd2rust feature, register clusters, just landed (rust-embedded/svd2rust#107), but I haven't had a chance to test it yet. The timers, RTC, SERCOM, and USB peripherals have their entire interface within SVD Remaining missing features that I know of: (updated from my comment here)
|
What @kevinmehall said. I've written code for the ATSAMD20 a while ago (https://github.com/therealprof/atsamd20e15a) to support https://github.com/LuckyResistor/SnowFlakeProject so I might be able to help out with a few bits and pieces. However that MCU is so quirky, the documentation incomplete and utter crap and the a community pretty much non-existent so I don't want to sink a lot of time there... |
@kevinmehall ah, interesting. I skimmed those two outstanding issues; do you have a sense of how complicated they'd be to resolve? Does it require deep-diving into the svd spec and rewriting the parser/code generator for svd? I'm hesitant to dive in there because I saw commentary on #46 that suggested that that code was really in need of love to make it easier to maintain. Alternatively, can we squeak by without those by making some tweaks to the SVD? Obviously not a long term strategy; just trying to get a sense of how much ocean boiling is needed to get things going :-) |
FWIW, I just ran svd2rust; rust-embedded/svd2rust#191 is the only hard error I get with svd2rust master at the moment. There are also warnings about overlapping registers for |
I work for Adafruit on CircuitPython and would love to see Rust support. I work with the SAMD21 and SAMD51 day-to-day and would be happy to answer any questions. It'd be awesome to produce UF2 files for easy loading with our bootloader. Also, if anyone needs hardware, let me know ([email protected]) and I'll see what I can do (no promises). The Metro is usually the easiest to develop on because it has an SWD header. As far as board definitions go, our equivalent in CircuitPython lives here: https://github.com/adafruit/circuitpython/tree/master/ports/atmel-samd/boards |
https://github.com/wez/svd2rust/tree/derivedFrom and https://github.com/wez/svd/tree/altreg are the current state of my svd changes (including @nsabovic's rust-embedded/svd2rust#190). With that build I can generate the atsamd21 svd with no warnings, with unions for the overlapping portions and with |
I've created https://github.com/wez/atsamd21-rs to hold the svd2rust generated bits as well as the hal bits that I'm going to be looking at this weekend. It requires the changes that I've submitted as PRs to I'm not sure if the current structure is or should be the final structure; there are a number of board variants and it would be nice to do something to automatically extract the common parts. I'm going to ignore that aspect for now and focus instead on the basic hal for the board I have. |
These both live in the same repo, so I'm not sure if you'd prefer to break this out and link to the subdirs in that repo or just keep this one entry. rust-embedded/wg#61 is the issue I opened with some background on this.
192: Emit unions for overlapping/overloaded registers r=Emilgardis a=wez I want to get a complete working build for ATSAMD21 (rust-embedded/wg#61) so I'm taking a stab at that. * Introduced a `FieldRegion` helper to reason about overlapping regions * If overlaps are detected, a `union` container is emitted * If the only item in a `RegisterBlock` is a union, that `RegisterBlock` is emitted as a union * Otherwise: we generate a name for the union field by taking the longest common prefix of the union's alternates, or just pick an artificial name like `u1` if there was no common prefix. * If the starting address offset of elements in a union are not all the same, we don't have a way to emit padding for them today. We will emit a warning (and bad code) in that case (example below). The one example of this I see in ATSAMD21 is due to missing `derivedFrom` support for registers; we're currently generating bad code for these anyway. I have resolved in another branch that I'll turn into a PR once this one is landed. ``` WARNING: field Some(Ident("pmux1_1")) has different offset 177 than its union container 176 WARNING: field Some(Ident("pmux1_2")) has different offset 178 than its union container 176 ``` Examples: ``` #[doc = "Real-Time Counter"] pub mod rtc { #[doc = r" Register block"] #[repr(C)] pub union RegisterBlock { #[doc = "0x00 - Clock/Calendar with Alarm"] pub mode2: MODE2, #[doc = "0x00 - 16-bit Counter with Two 16-bit Compares"] pub mode1: MODE1, #[doc = "0x00 - 32-bit Counter with Single 32-bit Compare"] pub mode0: MODE0, } ``` ``` #[doc = r" Register block"] #[repr(C)] pub struct USART { #[doc = "0x00 - USART Control A"] pub ctrla: self::usart::CTRLA, #[doc = "0x04 - USART Control B"] pub ctrlb: self::usart::CTRLB, _reserved2: [u8; 4usize], #[doc = "USART Baud Rate"] pub baud: baud_union, ... } #[doc = "USART Baud Rate"] #[repr(C)] pub union baud_union { #[doc = "0x0c - USART Baud Rate"] pub baud_usartfp_mode: self::usart::BAUD_USARTFP_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud_fracfp_mode: self::usart::BAUD_FRACFP_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud_frac_mode: self::usart::BAUD_FRAC_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud: self::usart::BAUD, } ``` Refs: #191 #16 Co-authored-by: Wez Furlong <[email protected]> Co-authored-by: Emil Gardström <[email protected]>
192: Emit unions for overlapping/overloaded registers r=Emilgardis a=wez I want to get a complete working build for ATSAMD21 (rust-embedded/wg#61) so I'm taking a stab at that. * Introduced a `FieldRegion` helper to reason about overlapping regions * If overlaps are detected, a `union` container is emitted * If the only item in a `RegisterBlock` is a union, that `RegisterBlock` is emitted as a union * Otherwise: we generate a name for the union field by either taking the shortest common prefix of the union's alternates or the shortest register name (depending on type name conflicts). If that doesn't work just pick an artificial name like `u1`. * If the starting address offset of elements in a union are not all the same, we don't have a way to emit padding for them today. We will emit a warning (and bad code) in that case (example below). The one example of this I see in ATSAMD21 is due to missing `derivedFrom` support for registers; we're currently generating bad code for these anyway. I have resolved in another branch that I'll turn into a PR once this one is landed. ``` WARNING: field Some(Ident("pmux1_1")) has different offset 177 than its union container 176 WARNING: field Some(Ident("pmux1_2")) has different offset 178 than its union container 176 ``` Examples: ``` #[doc = "Real-Time Counter"] pub mod rtc { #[doc = r" Register block"] #[repr(C)] pub union RegisterBlock { #[doc = "0x00 - Clock/Calendar with Alarm"] pub mode2: MODE2, #[doc = "0x00 - 16-bit Counter with Two 16-bit Compares"] pub mode1: MODE1, #[doc = "0x00 - 32-bit Counter with Single 32-bit Compare"] pub mode0: MODE0, } ``` ``` #[doc = r" Register block"] #[repr(C)] pub struct USART { #[doc = "0x00 - USART Control A"] pub ctrla: self::usart::CTRLA, #[doc = "0x04 - USART Control B"] pub ctrlb: self::usart::CTRLB, _reserved2: [u8; 4usize], #[doc = "USART Baud Rate"] pub baud: baud_union, ... } #[doc = "USART Baud Rate"] #[repr(C)] pub union baud_union { #[doc = "0x0c - USART Baud Rate"] pub baud_usartfp_mode: self::usart::BAUD_USARTFP_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud_fracfp_mode: self::usart::BAUD_FRACFP_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud_frac_mode: self::usart::BAUD_FRAC_MODE, #[doc = "0x0c - USART Baud Rate"] pub baud: self::usart::BAUD, } ``` Refs: #191 #16 Co-authored-by: Wez Furlong <[email protected]> Co-authored-by: Emil Gardström <[email protected]>
Hey @wez, are you okay if we close this issue? |
Yep, fine by me! |
I hack on keyboard hardware and firmware in my spare time, and I do it in bursts. I've previously worked with the nrf52 boards from adafruit and have made contact with @jamesmunns on that front.
I have a few adafruit boards that I'd love to use with rust and I'm willing to help move the ball forwards, but I'm not super sure what to do, in which order, and I'm not sure what the current best practices are.
I'm going to list my assumptions below, can you correct me and/or point me in the right direction?
I suspect some of this aligns with the weekly driver initiative, but some of these are lower level board support things.
Available M0 hardware
I have these boards floating around; they're all based on the ATSAMD21:
I'm looking at targeting the Feather M0 express for a future build, but want to make some progress on the rust side first. Ultimately, I'd like to get pure rust USB peripheral support working on one of these things. I have a couple of cheap SWD debugging adapters.
Game plan
atsamd21_svd
for thiscortex-m-quickstart
is sufficient. Is there an alternative approach that should be taken? DoesOne step setup #43 make some of this obsolete?
Does that sound like the right plan? What am I missing? Are there folks interested in reviewing/providing feedback on these steps?
Thanks!
The text was updated successfully, but these errors were encountered: