|
| 1 | +## Introduction |
| 2 | + |
| 3 | +Rust has emerged as a powerful and safety-focused programming language, gaining |
| 4 | +traction among embedded developers. Silicon vendors who wish to enable Rust |
| 5 | +support for their System-on-Chip (SoC) products can benefit from this trend by |
| 6 | +attracting a growing community of Rust developers. |
| 7 | + |
| 8 | +This guide aims to help silicon vendors enable Rust support, either |
| 9 | +independently or by empowering third-party developers. It outlines the |
| 10 | +essential resources, tasks, and priorities required to foster a robust Rust |
| 11 | +ecosystem around their System-on-Chip (SoC). |
| 12 | + |
| 13 | +**Note:** For assistance with strategy in engaging with the community, we |
| 14 | +recommend reaching out to the Embedded Rust Working Group (REWG) leads. They |
| 15 | +can provide valuable insights and support to help you navigate the process |
| 16 | +effectively. |
| 17 | + |
| 18 | +## Essential Resources |
| 19 | + |
| 20 | +### Documentation |
| 21 | + |
| 22 | +Detailed documentation is essential for effective development and debugging. It |
| 23 | +enables developers to comprehend the System-on-Chip (SoC), including its memory |
| 24 | +map, peripherals, interrupt handling, low-power modes, etc. Ensure that the |
| 25 | +documentation covers all hardware aspects comprehensively, from register-level |
| 26 | +details to system-level interactions. The documentation should be publicly |
| 27 | +available; in cases where public availability is not feasible, any |
| 28 | +non-disclosure agreement (NDA) must permit the publication of open-source code |
| 29 | +derived from it. |
| 30 | + |
| 31 | +### Register Description Files |
| 32 | + |
| 33 | +Register description files are used to generate Peripheral Access Crates |
| 34 | +(PACs). The most common format for these files is SVD |
| 35 | +([System View Description](https://open-cmsis-pack.github.io/svd-spec)). Rust |
| 36 | +developers have often encountered issues with SVD files, so it is crucial to |
| 37 | +provide clear contact information for reporting any discrepancies or problems. |
| 38 | +Up-to-date SVD files ensure that the community can collaborate effectively to |
| 39 | +resolve issues and improve the quality of the PACs. |
| 40 | + |
| 41 | +### Flash Algorithms |
| 42 | + |
| 43 | +[Flash Algorithms](https://open-cmsis-pack.github.io/Open-CMSIS-Pack-Spec/main/html/flashAlgorithm.html) |
| 44 | +are integrated with debugging tools like `probe-rs`. They facilitate and speed |
| 45 | +up firmware programming and debugging, streamlining development workflows. |
| 46 | +Providing well-supported FlashAlgos will enhance the integration with these |
| 47 | +tools and improve the overall developer experience. |
| 48 | + |
| 49 | +### Vendor Tooling |
| 50 | + |
| 51 | +Some System-on-Chip (SoC) devices require custom tools for generating images or |
| 52 | +flashing them onto the device. It is beneficial to provide these tools in an |
| 53 | +open-source manner, fostering community contributions and accelerating |
| 54 | +ecosystem growth. Open-sourcing vendor tooling enables third-party developers |
| 55 | +to extend and enhance the toolchain, ensuring improved compatibility with the |
| 56 | +broader Embedded Rust ecosystem. |
| 57 | + |
| 58 | +### Contact Information |
| 59 | + |
| 60 | +Providing contact information is vital for addressing maintainer queries and |
| 61 | +issues related to register description files or other resources. The use of a |
| 62 | +public issue tracking system (like GitHub Issues) for reporting and tracking |
| 63 | +problems might help. Actively engage with the community through forums, |
| 64 | +discussions, and updates to build trust and collaboration. |
| 65 | + |
| 66 | +## Maintaining PAC and HAL Crates |
| 67 | + |
| 68 | +Peripheral Access Crates (PACs) and Hardware Abstraction Layer (HAL) crates are |
| 69 | +at the core of enabling Rust support. |
| 70 | + |
| 71 | +### Generate and Maintain PACs |
| 72 | + |
| 73 | +Multiple tools such as `svd2rust`, `chiptool`, `raltool`, and `svd2pac` |
| 74 | +automate the generation of PACs from register description files. Each tool has |
| 75 | +its strengths, and selecting the right one depends on the requirements and the |
| 76 | +complexity of the hardware. |
| 77 | + |
| 78 | +### Develop and Maintain HAL Crates |
| 79 | + |
| 80 | +Implement `embedded-hal` and `embedded-hal-async` traits in your HAL crates. |
| 81 | +Adhering to these traits ensures compatibility across the Embedded Rust |
| 82 | +ecosystem, enhancing interoperability. It is an essential goal that HALs use |
| 83 | +Rust code rather than wrapping existing C code. An incremental porting |
| 84 | +strategy, where Rust is used for all core functionality, but C with Rust |
| 85 | +bindings is used for complex drivers, is acceptable, allowing for gradual |
| 86 | +adoption and community contributions. |
| 87 | + |
| 88 | +Start with essential peripherals (clock, timer, GPIO) and expand progressively |
| 89 | +(I2C, SPI, UART, etc.) based on community feedback. Release early and often to |
| 90 | +engage the community and gather valuable insights for further development. |
| 91 | + |
| 92 | +### Common Recommendations |
| 93 | + |
| 94 | +- Ensure that crates are compatible with `no_std` environments, which are |
| 95 | + common in embedded systems without an operating system. Functionality that |
| 96 | + needs `alloc` or `std` can be included when gated with Cargo "features." |
| 97 | +- Make your crates available on [crates.io](https://crates.io/) to maximize |
| 98 | + visibility and ease of use for developers. |
| 99 | +- Use semantic versioning to maintain consistency and predictability in your |
| 100 | + releases. |
| 101 | +- Prefer licenses like Apache 2.0 and MIT for their permissive nature, which |
| 102 | + encourages broader adoption and collaboration. |
| 103 | + |
| 104 | +### Issue Tracking |
| 105 | + |
| 106 | +Effective issue tracking is crucial for maintaining a healthy and collaborative |
| 107 | +ecosystem. Discuss triaging, labeling, and community involvement in issue |
| 108 | +resolution. Implement transparent processes for: |
| 109 | + |
| 110 | +- Triage and prioritize issues based on severity and impact. |
| 111 | +- Use labels to categorize issues (e.g., bugs, feature requests). |
| 112 | +- Encourage community members to contribute to resolving issues by providing |
| 113 | + feedback or submitting pull requests (PRs). |
| 114 | + |
| 115 | +### Facilitate Debugging and Testing |
| 116 | + |
| 117 | +The use of `probe-rs` is prevalent in the Embedded Rust ecosystem for debugging |
| 118 | +and testing. Combined with debug-based facilities like `defmt-rtt`, which |
| 119 | +offers logging capabilities for embedded systems, the Embedded Rust ecosystem |
| 120 | +has developed numerous tools. `probe-rs` supports a wide range of target |
| 121 | +architectures, debug interfaces, and debug probe protocols. |
| 122 | + |
| 123 | +Thorough testing ensures hardware-software reliability, and leveraging these |
| 124 | +tools can significantly enhance development workflows. |
| 125 | + |
| 126 | +## Nice-to-Have Features for Enhanced Ecosystem Support |
| 127 | + |
| 128 | +### Examples |
| 129 | + |
| 130 | +Including some basic examples as part of the HAL is essential for helping |
| 131 | +developers get started. These examples should demonstrate key functionalities, |
| 132 | +such as initializing peripherals or handling interrupts. They serve as |
| 133 | +practical starting points and learning aids. |
| 134 | + |
| 135 | +### BSP (Board Support Package) Crates |
| 136 | + |
| 137 | +BSP crates are relevant when you need to provide board-specific configurations |
| 138 | +and initializations. Unlike HALs, which focus on hardware abstraction, BSPs |
| 139 | +handle the integration of multiple components for a specific board. Having both |
| 140 | +BSP and HAL crates offers a layered approach, making it easier for developers |
| 141 | +to build applications targeting a particular hardware board. |
| 142 | + |
| 143 | +### Project Templates |
| 144 | + |
| 145 | +Project templates are boilerplate code structures that provide a starting point |
| 146 | +for new projects. They include prevalent configurations, dependencies, and |
| 147 | +setup steps, saving developers time and reducing the learning curve. Examples |
| 148 | +of project templates include bare-metal (using the HAL without any framework), |
| 149 | +Embassy, RTIC, and others. |
| 150 | + |
| 151 | +### Integration with Popular IDEs and Tools |
| 152 | + |
| 153 | +Offer guides on setting up development environments for Embedded Rust projects |
| 154 | +with popular tools such as: |
| 155 | + |
| 156 | +- `rust-analyzer`: for Rust syntax highlighting and error checking. |
| 157 | +- `probe-rs`: for flashing and debugging firmware. |
| 158 | +- `defmt`: a logging framework optimized for embedded systems. |
| 159 | +- `defmt-test`: testing utilities for `defmt`. |
| 160 | + |
| 161 | +Providing setup instructions for these tools will help developers integrate |
| 162 | +them into their workflows, enhancing productivity and collaboration. |
| 163 | + |
| 164 | +## Conclusion |
| 165 | + |
| 166 | +Enabling Rust support for your SoC opens the door to a vibrant community of |
| 167 | +developers who value safety, performance, and reliability. By providing |
| 168 | +essential resources, maintaining high-quality PACs and HAL crates, and |
| 169 | +fostering a supportive ecosystem, you empower both internal teams and |
| 170 | +third-party developers to unlock the full potential of your hardware. |
| 171 | + |
| 172 | +As the Rust embedded ecosystem continues to grow, embracing these practices |
| 173 | +positions your company at the forefront of this movement, attracting developers |
| 174 | +passionate about building robust and innovative systems. Encourage ongoing |
| 175 | +engagement with the Rust community to stay updated on best practices and tools, |
| 176 | +ensuring your System-on-Chip (SoC) remains a preferred choice for Rust |
| 177 | +developers. |
| 178 | + |
| 179 | +By following this guide, you can create a comprehensive and supportive |
| 180 | +environment that not only enables Rust support but also nurtures a thriving |
| 181 | +developer ecosystem around your products. |
0 commit comments