1
- # Guide for Silicon Vendors to Enable Rust Support for Their SoCs
1
+ # Guide for silicon vendors to enable Rust support for their SoCs
2
2
3
3
## Introduction
4
4
@@ -17,7 +17,7 @@ recommend reaching out to the Rust Embedded Working Group (REWG) leads. They
17
17
can provide valuable insights and support to help you navigate the process
18
18
effectively.
19
19
20
- ## Essential Resources
20
+ ## Essential resources
21
21
22
22
### Documentation
23
23
@@ -30,7 +30,7 @@ available; in cases where public availability is not feasible, any
30
30
non-disclosure agreement (NDA) must permit the publication of open-source code
31
31
derived from it.
32
32
33
- ### Register Description Files
33
+ ### Register description files
34
34
35
35
Register description files are used to generate Peripheral Access Crates
36
36
(PACs). The most common format for these files is SVD
@@ -48,7 +48,7 @@ facilitate and speed up firmware programming and debugging, streamlining
48
48
development workflows. Providing well-supported FlashAlgos will enhance the
49
49
integration with these tools and improve the overall developer experience.
50
50
51
- ### Vendor Tooling
51
+ ### Vendor tooling
52
52
53
53
Some System-on-Chip (SoC) devices require custom tools for generating images or
54
54
flashing 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
57
57
to extend and enhance the toolchain, ensuring improved compatibility with the
58
58
broader Embedded Rust ecosystem.
59
59
60
- ### Contact Information
60
+ ### Contact information
61
61
62
62
Providing contact information is vital for addressing maintainer queries and
63
63
issues related to register description files or other resources. The use of a
64
64
public issue tracking system (like GitHub Issues) for reporting and tracking
65
65
problems might help. Actively engage with the community through forums,
66
66
discussions, and updates to build trust and collaboration.
67
67
68
- ## Maintaining PAC and HAL Crates
68
+ ## Maintaining PAC and HAL crates
69
69
70
70
Peripheral Access Crates (PACs) and Hardware Abstraction Layer (HAL) crates are
71
71
at the core of enabling Rust support.
72
72
73
- ### Generate and Maintain PACs
73
+ ### Generate and maintain PACs
74
74
75
75
Multiple tools such as [ svd2rust] ( https://crates.io/crates/svd2rust ) ,
76
76
[ chiptool] ( https://github.com/embassy-rs/chiptool ) ,
@@ -79,22 +79,23 @@ Multiple tools such as [svd2rust](https://crates.io/crates/svd2rust),
79
79
from register description files. Each tool has its strengths, and selecting the
80
80
right one depends on the requirements and the complexity of the hardware.
81
81
82
- ### Develop and Maintain HAL Crates
82
+ ### Develop and maintain HAL crates
83
83
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.
92
93
93
94
Start with essential peripherals (clock, timer, GPIO) and expand progressively
94
95
(I2C, SPI, UART, etc.) based on community feedback. Release early and often to
95
96
engage the community and gather valuable insights for further development.
96
97
97
- ### Common Recommendations
98
+ ### Common recommendations
98
99
99
100
- Ensure that crates are compatible with ` no_std ` environments, which are
100
101
common in embedded systems without an operating system. Functionality that
@@ -107,7 +108,7 @@ engage the community and gather valuable insights for further development.
107
108
- Prefer licenses like Apache 2.0 and MIT for their permissive nature, which
108
109
encourages broader adoption and collaboration.
109
110
110
- ### Issue Tracking
111
+ ### Issue tracking
111
112
112
113
Effective issue tracking is crucial for maintaining a healthy and collaborative
113
114
ecosystem. Discuss triaging, labeling, and community involvement in issue
@@ -118,7 +119,7 @@ resolution. Implement transparent processes for:
118
119
- Encourage community members to contribute to resolving issues by providing
119
120
feedback or submitting pull requests (PRs).
120
121
121
- ### Facilitate Debugging and Testing
122
+ ### Facilitate debugging and testing
122
123
123
124
The Embedded Rust ecosystem offers various tools used for debugging
124
125
and testing, with [ probe-rs] ( https://probe.rs ) being one of the most widely
@@ -132,7 +133,7 @@ development.
132
133
Thorough testing ensures hardware-software reliability, and leveraging these
133
134
tools can significantly enhance development workflows.
134
135
135
- ## Nice-to-Have Features for Enhanced Ecosystem Support
136
+ ## Nice-to-have features for enhanced ecosystem support
136
137
137
138
### Examples
138
139
@@ -141,23 +142,23 @@ developers get started. These examples should demonstrate key functionalities,
141
142
such as initializing peripherals or handling interrupts. They serve as
142
143
practical starting points and learning aids.
143
144
144
- ### BSP (Board Support Package) Crates
145
+ ### BSP (Board Support Package) crates
145
146
146
147
BSP crates are relevant when you need to provide board-specific configurations
147
148
and initializations. Unlike HALs, which focus on hardware abstraction, BSPs
148
149
handle the integration of multiple components for a specific board. Separation
149
150
in BSP and HAL crates offers a layered approach, making it easier for developers
150
151
to build applications targeting a particular hardware board.
151
152
152
- ### Project Templates
153
+ ### Project templates
153
154
154
155
Project templates are boilerplate code structures that provide a starting point
155
156
for new projects. They include prevalent configurations, dependencies, and
156
157
setup steps, saving developers time and reducing the learning curve. Examples
157
158
of project templates include bare-metal (using the HAL without any framework),
158
159
Embassy, RTIC, and others.
159
160
160
- ### Integration with Popular IDEs and Tools
161
+ ### Integration with popular IDEs and tools
161
162
162
163
Offer guides on setting up development environments for Embedded Rust projects
163
164
with popular tools such as:
@@ -172,6 +173,45 @@ with popular tools such as:
172
173
Providing setup instructions for these tools will help developers integrate
173
174
them into their workflows, enhancing productivity and collaboration.
174
175
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
+
175
215
## Conclusion
176
216
177
217
Enabling Rust support for your SoC opens the door to a vibrant community of
0 commit comments