Skip to content

Commit a124ee3

Browse files
committed
Add suggested flow and minor edits
Suggested flow based on @jamesmunns's guide in Embassy FAQ
1 parent 02b473e commit a124ee3

File tree

1 file changed

+63
-23
lines changed

1 file changed

+63
-23
lines changed

src/soc-support.md

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
1717
can provide valuable insights and support to help you navigate the process
1818
effectively.
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
3030
non-disclosure agreement (NDA) must permit the publication of open-source code
3131
derived from it.
3232

33-
### Register Description Files
33+
### Register description files
3434

3535
Register 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
4848
development workflows. Providing well-supported FlashAlgos will enhance the
4949
integration with these tools and improve the overall developer experience.
5050

51-
### Vendor Tooling
51+
### Vendor tooling
5252

5353
Some System-on-Chip (SoC) devices require custom tools for generating images or
5454
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
5757
to extend and enhance the toolchain, ensuring improved compatibility with the
5858
broader Embedded Rust ecosystem.
5959

60-
### Contact Information
60+
### Contact information
6161

6262
Providing contact information is vital for addressing maintainer queries and
6363
issues related to register description files or other resources. The use of a
6464
public issue tracking system (like GitHub Issues) for reporting and tracking
6565
problems might help. Actively engage with the community through forums,
6666
discussions, and updates to build trust and collaboration.
6767

68-
## Maintaining PAC and HAL Crates
68+
## Maintaining PAC and HAL crates
6969

7070
Peripheral Access Crates (PACs) and Hardware Abstraction Layer (HAL) crates are
7171
at the core of enabling Rust support.
7272

73-
### Generate and Maintain PACs
73+
### Generate and maintain PACs
7474

7575
Multiple 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),
7979
from register description files. Each tool has its strengths, and selecting the
8080
right 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

9394
Start with essential peripherals (clock, timer, GPIO) and expand progressively
9495
(I2C, SPI, UART, etc.) based on community feedback. Release early and often to
9596
engage 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

112113
Effective issue tracking is crucial for maintaining a healthy and collaborative
113114
ecosystem. 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

123124
The Embedded Rust ecosystem offers various tools used for debugging
124125
and testing, with [probe-rs](https://probe.rs) being one of the most widely
@@ -132,7 +133,7 @@ development.
132133
Thorough testing ensures hardware-software reliability, and leveraging these
133134
tools 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,
141142
such as initializing peripherals or handling interrupts. They serve as
142143
practical starting points and learning aids.
143144

144-
### BSP (Board Support Package) Crates
145+
### BSP (Board Support Package) crates
145146

146147
BSP crates are relevant when you need to provide board-specific configurations
147148
and initializations. Unlike HALs, which focus on hardware abstraction, BSPs
148149
handle the integration of multiple components for a specific board. Separation
149150
in BSP and HAL crates offers a layered approach, making it easier for developers
150151
to build applications targeting a particular hardware board.
151152

152-
### Project Templates
153+
### Project templates
153154

154155
Project templates are boilerplate code structures that provide a starting point
155156
for new projects. They include prevalent configurations, dependencies, and
156157
setup steps, saving developers time and reducing the learning curve. Examples
157158
of project templates include bare-metal (using the HAL without any framework),
158159
Embassy, RTIC, and others.
159160

160-
### Integration with Popular IDEs and Tools
161+
### Integration with popular IDEs and tools
161162

162163
Offer guides on setting up development environments for Embedded Rust projects
163164
with popular tools such as:
@@ -172,6 +173,45 @@ with popular tools such as:
172173
Providing setup instructions for these tools will help developers integrate
173174
them 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

177217
Enabling Rust support for your SoC opens the door to a vibrant community of

0 commit comments

Comments
 (0)