1- # Guide for Silicon Vendors to Enable Rust Support for Their SoCs
1+ # Guide for silicon vendors to enable Rust support for their SoCs
22
33## Introduction
44
@@ -17,7 +17,7 @@ recommend reaching out to the Rust Embedded Working Group (REWG) leads. They
1717can provide valuable insights and support to help you navigate the process
1818effectively.
1919
20- ## Essential Resources
20+ ## Essential resources
2121
2222### Documentation
2323
@@ -30,7 +30,7 @@ available; in cases where public availability is not feasible, any
3030non-disclosure agreement (NDA) must permit the publication of open-source code
3131derived from it.
3232
33- ### Register Description Files
33+ ### Register description files
3434
3535Register description files are used to generate Peripheral Access Crates
3636(PACs). The most common format for these files is SVD
@@ -48,7 +48,7 @@ facilitate and speed up firmware programming and debugging, streamlining
4848development workflows. Providing well-supported FlashAlgos will enhance the
4949integration with these tools and improve the overall developer experience.
5050
51- ### Vendor Tooling
51+ ### Vendor tooling
5252
5353Some System-on-Chip (SoC) devices require custom tools for generating images or
5454flashing them onto the device. It is beneficial to provide these tools in an
@@ -57,20 +57,20 @@ ecosystem growth. Open-sourcing vendor tooling enables third-party developers
5757to extend and enhance the toolchain, ensuring improved compatibility with the
5858broader Embedded Rust ecosystem.
5959
60- ### Contact Information
60+ ### Contact information
6161
6262Providing contact information is vital for addressing maintainer queries and
6363issues related to register description files or other resources. The use of a
6464public issue tracking system (like GitHub Issues) for reporting and tracking
6565problems might help. Actively engage with the community through forums,
6666discussions, and updates to build trust and collaboration.
6767
68- ## Maintaining PAC and HAL Crates
68+ ## Maintaining PAC and HAL crates
6969
7070Peripheral Access Crates (PACs) and Hardware Abstraction Layer (HAL) crates are
7171at the core of enabling Rust support.
7272
73- ### Generate and Maintain PACs
73+ ### Generate and maintain PACs
7474
7575Multiple tools such as [ svd2rust] ( https://crates.io/crates/svd2rust ) ,
7676[ chiptool] ( https://github.com/embassy-rs/chiptool ) ,
@@ -79,22 +79,23 @@ Multiple tools such as [svd2rust](https://crates.io/crates/svd2rust),
7979from register description files. Each tool has its strengths, and selecting the
8080right one depends on the requirements and the complexity of the hardware.
8181
82- ### Develop and Maintain HAL Crates
82+ ### Develop and maintain HAL crates
8383
84- Implement [ embedded-hal] ( https://crates.io/crates/embedded-hal ) and
85- [ embedded-hal-async] ( https://crates.io/crates/embedded-hal-async ) traits in
86- your HAL crates. Adhering to these traits ensures compatibility across the
87- Embedded Rust ecosystem, enhancing interoperability. It is an essential goal
88- that HALs use Rust code rather than wrapping existing C code. An incremental
89- porting strategy, where all core functionality is implemented in Rust, but C
90- with Rust bindings is used for complex drivers, is acceptable, allowing for
91- gradual adoption and community contributions.
84+ Implement [ embedded-hal] ( https://crates.io/crates/embedded-hal ) ,
85+ [ embedded-hal-async] ( https://crates.io/crates/embedded-hal-async ) , and
86+ [ embedded-io] ( https://crates.io/crates/embedded-io ) traits in your HAL crates.
87+ Adhering to these traits ensures compatibility across the Embedded Rust
88+ ecosystem, enhancing interoperability. It is an essential goal that HALs use
89+ Rust code rather than wrapping existing C code. An incremental porting
90+ strategy, where all core functionality is implemented in Rust, but C with Rust
91+ bindings is used for complex drivers, is acceptable, allowing for gradual
92+ adoption and community contributions.
9293
9394Start with essential peripherals (clock, timer, GPIO) and expand progressively
9495(I2C, SPI, UART, etc.) based on community feedback. Release early and often to
9596engage the community and gather valuable insights for further development.
9697
97- ### Common Recommendations
98+ ### Common recommendations
9899
99100- Ensure that crates are compatible with ` no_std ` environments, which are
100101 common in embedded systems without an operating system. Functionality that
@@ -107,7 +108,7 @@ engage the community and gather valuable insights for further development.
107108- Prefer licenses like Apache 2.0 and MIT for their permissive nature, which
108109 encourages broader adoption and collaboration.
109110
110- ### Issue Tracking
111+ ### Issue tracking
111112
112113Effective issue tracking is crucial for maintaining a healthy and collaborative
113114ecosystem. Discuss triaging, labeling, and community involvement in issue
@@ -118,7 +119,7 @@ resolution. Implement transparent processes for:
118119- Encourage community members to contribute to resolving issues by providing
119120 feedback or submitting pull requests (PRs).
120121
121- ### Facilitate Debugging and Testing
122+ ### Facilitate debugging and testing
122123
123124The Embedded Rust ecosystem offers various tools used for debugging
124125and testing, with [ probe-rs] ( https://probe.rs ) being one of the most widely
@@ -132,7 +133,7 @@ development.
132133Thorough testing ensures hardware-software reliability, and leveraging these
133134tools can significantly enhance development workflows.
134135
135- ## Nice-to-Have Features for Enhanced Ecosystem Support
136+ ## Nice-to-have features for enhanced ecosystem support
136137
137138### Examples
138139
@@ -141,23 +142,23 @@ developers get started. These examples should demonstrate key functionalities,
141142such as initializing peripherals or handling interrupts. They serve as
142143practical starting points and learning aids.
143144
144- ### BSP (Board Support Package) Crates
145+ ### BSP (Board Support Package) crates
145146
146147BSP crates are relevant when you need to provide board-specific configurations
147148and initializations. Unlike HALs, which focus on hardware abstraction, BSPs
148149handle the integration of multiple components for a specific board. Separation
149150in BSP and HAL crates offers a layered approach, making it easier for developers
150151to build applications targeting a particular hardware board.
151152
152- ### Project Templates
153+ ### Project templates
153154
154155Project templates are boilerplate code structures that provide a starting point
155156for new projects. They include prevalent configurations, dependencies, and
156157setup steps, saving developers time and reducing the learning curve. Examples
157158of project templates include bare-metal (using the HAL without any framework),
158159Embassy, RTIC, and others.
159160
160- ### Integration with Popular IDEs and Tools
161+ ### Integration with popular IDEs and tools
161162
162163Offer guides on setting up development environments for Embedded Rust projects
163164with popular tools such as:
@@ -172,6 +173,45 @@ with popular tools such as:
172173Providing setup instructions for these tools will help developers integrate
173174them into their workflows, enhancing productivity and collaboration.
174175
176+ ## Suggested flow for adding SoC Support
177+
178+ - A preliminary requirement of this flow is that the Rust toolchain includes
179+ a [ target] ( https://doc.rust-lang.org/rustc/platform-support.html ) that
180+ matches System-on-Chip (SoC). If this not the case the solution can be as simple as adding a
181+ [ custom target] ( https://doc.rust-lang.org/rustc/targets/custom.html ) or as
182+ difficult as adding support for the underlying architecture to
183+ [ LLVM] ( https://llvm.org ) .
184+ - Before starting from scratch, check if any existing community efforts for
185+ already exist (e.g. checking on
186+ [ awesome-embedded-rust] ( https://github.com/rust-embedded/awesome-embedded-rust )
187+ or joining the
188+ [ Rust Embedded Matrix room] ( https://matrix.to/#/#rust-embedded:matrix.org ) ).
189+ This could save significant development time.
190+ - Ensure that your target is supported by [ probe-rs] ( https://probe.rs ) . The
191+ ability to debug using SWD or JTAG is highly beneficial. Support for flashing
192+ programming can be added with a Flash Algorithm (e.g. from a CMSIS-Pack).
193+ - Generate Peripheral Access Crates (PACs) from register description files with
194+ SVD (System View Description) being the most common and preferred format.
195+ Alternatives include extracting the register descriptions from PDF datasheets
196+ or C header files, but this much more labor-intensive.
197+ - Create a minimal project containing the PAC and/or an empty Hardware
198+ Abstraction Layer (HAL). The goal is to get a minimal working binary that
199+ either blinks an LED or sends messages through
200+ [ defmt-rtt] ( https://crates.io/crates/defmt-rtt ) using only the PAC crate or
201+ with a minimal HAL. This will require a linker script and exercise the
202+ availability to flash and debug programs. Additional crates for core
203+ registers and peripheral, or startup code and interrupt handling will also be
204+ required (see [ Cortex-M] ( https://github.com/rust-embedded/cortex-m ) or
205+ [ RISC-V] ( https://github.com/rust-embedded/riscv ) ).
206+ - Add core functionality in HAL: clocks, timers, interrupts. Verify the
207+ accuracy of timers and interrupts with external tools like a logic analyzer
208+ or an oscilloscope.
209+ - Progressively add drivers for other peripherals (GPIO, I2C, SPI, UART, etc.)
210+ implementing standard Rust Embedded traits
211+ ([ embedded-hal] ( https://crates.io/crates/embedded-hal ) ,
212+ [ embedded-hal-async] ( https://crates.io/crates/embedded-hal-async ) ,
213+ [ embedded-io] ( https://crates.io/crates/embedded-io ) ).
214+
175215## Conclusion
176216
177217Enabling Rust support for your SoC opens the door to a vibrant community of
0 commit comments