Difference between revisions of "Rust"

From Wiki at Neela Nurseries
Jump to navigation Jump to search
m (Minor formatting)
m (Useful Crates : link to Rust crate for GC9A01 display driver)
 
(5 intermediate revisions by the same user not shown)
Line 66: Line 66:
 
<ul>
 
<ul>
 
*  https://doc.rust-lang.org/rust-by-example/mod/super.html
 
*  https://doc.rust-lang.org/rust-by-example/mod/super.html
 +
</ul>
 +
 +
Constants
 +
<ul>
 +
*  https://doc.rust-lang.org/rust-by-example/custom_types/constants.html
 
</ul>
 
</ul>
  
Line 73: Line 78:
 
</ul>
 
</ul>
 
-->
 
-->
 +
 +
<-- odne komentar -->
 +
 +
== [[#top|^]] Language Constructs ==
 +
 +
Arrays in Rust
 +
<ul>
 +
*  https://doc.rust-lang.org/std/primitive.array.html
 +
</ul>
 +
 +
<!--
 +
<ul>
 +
*  URL
 +
</ul>
 +
-->
 +
 +
<-- odne komentar -->
  
 
== [[#top|^]] Rust for Embedded Systems ==
 
== [[#top|^]] Rust for Embedded Systems ==
Line 103: Line 125:
  
 
*  https://docs.embassy.dev/embassy-nrf/git/nrf51/index.html
 
*  https://docs.embassy.dev/embassy-nrf/git/nrf51/index.html
 +
 +
<!-- odne komentar -->
  
 
=== [[#top|^]] Specific development boards and Rust ===
 
=== [[#top|^]] Specific development boards and Rust ===
Line 121: Line 145:
  
 
*  https://github.com/br0kenpixel/microbit-rust-std/blob/main/Cargo.toml
 
*  https://github.com/br0kenpixel/microbit-rust-std/blob/main/Cargo.toml
 +
 +
<!-- odne komentar -->
  
 
=== [[#top|^]] Crate Microbit-V2 ===
 
=== [[#top|^]] Crate Microbit-V2 ===
Line 133: Line 159:
  
 
*  https://github.com/mytechnotalent/rust_embassy_microbit_project - Rust Embassy Microbit Project mytechnotalent
 
*  https://github.com/mytechnotalent/rust_embassy_microbit_project - Rust Embassy Microbit Project mytechnotalent
 +
 +
<!-- odne komentar -->
 +
 +
== [[#top|^]] Sensor driver development ==
 +
 +
https://medium.com/@FAANG/advanced-embedded-programming-in-rust-from-bare-metal-to-real-time-systems-e911f782a44f
  
 
<!-- odne komentar -->
 
<!-- odne komentar -->
Line 185: Line 217:
  
 
*  https://github.com/nrf-rs/microbit/blob/7726c24603291f44eafc96a181906893cd2a630d/microbit-common/src/v2/board.rs#L202
 
*  https://github.com/nrf-rs/microbit/blob/7726c24603291f44eafc96a181906893cd2a630d/microbit-common/src/v2/board.rs#L202
 +
 +
Display GC9A01 crate and Git CI worksflows for crate repository
 +
 +
*  https://github.com/IniterWorker/esp32-s3-touch-lcd-1-28/blob/master/.github/workflows/rust_ci.yml
  
 
<!-- odne komentar -->
 
<!-- odne komentar -->

Latest revision as of 01:43, 17 March 2026

Notes on Rust programming language

See also local notes on algorithms

Overview

This local page about the programming language of Rust aims to answer among other questions: How suitable is Rust for embedded development?

Rust By Example (RBE) home page here:

MIT mirror of Rust introduction by chapters:

^ Organizations for Rust

^ Rust Books Online

^ Installation and Other Specific Notes

Install Rust on Ubuntu:

Adoption and popularity of Rust:

2025-12-16

Rust crates


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

^ Rust Language Concepts

Explicit lifetime annotation

Closures and type anonymity

Keywords `super` and `self` to express Rust crate and module scope

Constants


<-- odne komentar -->

^ Language Constructs

Arrays in Rust


<-- odne komentar -->

^ Rust for Embedded Systems

Books on Rust language for embedded systems, and a link to a specific topic regarding memory:

(1) https://docs.rust-embedded.org/book/

(2) https://docs.rust-embedded.org/discovery/microbit/07-uart/send-a-single-byte.html

(3) https://docs.rust-embedded.org/discovery-mb2/

(4) https://docs.rust-embedded.org/embedonomicon/memory-layout.html

Reference (2) and (3) are, or appear to be, first and second editions of the Rust book on embedded development with the Microbit dev board as the readers' example and target hardware. Note as well that Rust Embedded Discovery-mb2 has its code repository at:

Awesome Embedded Rust has an extensive list of links to supported architectures and boards:

Rust crates for STM32:

Rust Embassy examples for Nordic Semi nrf:


^ Specific development boards and Rust

Rust Embassy project has board support crates for certain MCU families. Ted found a crate or sub-project named `stm32f0` which is adaptable to support STMicro's stm32f401re. Needed only to change the MCU name from something other than `stm32f401re` to this MCU name in the Cargo.toml file.

(Thought the Cargo.toml file referenced an STM part with "7" in the name but see https://github.com/embassy-rs/embassy/blob/main/examples/stm32f0/Cargo.toml which is similar to the starting point Ted found.)

Charles Muchene is a software developer working in Rust and other languages. He shares an article on Medium dot com and a github project which presents a minimal start-up program in Rust for the Microbit V2:

Some kind of project template for Rust projects for Microbit-v2:


^ Crate Microbit-V2

^ Microbit example apps


^ Sensor driver development

https://medium.com/@FAANG/advanced-embedded-programming-in-rust-from-bare-metal-to-real-time-systems-e911f782a44f


^ Panic Handling

When setting panic compilation to 'abort' on panic, may be necessary to write one's own panic function:

How Rust panic is implemented . . . in crates core and std:


^ Rust General Topics

Following sections touch on Rust language features, use and practice. These notes are not specific to embedded development.

^ Memory Ownership in Rust

^ Crates versus Modules

Excellent article at MIT explaining Rust crates and modules, and how to organize them:

^ Specific Topics

Error handling . . .

^ Useful Crates

Rust Embassy crate to convey debug messages over USB

RGB LED related

Microbit-v2 board crate. This link found with search pattern "Rust microbit p0::P0_10":

Display GC9A01 crate and Git CI worksflows for crate repository


^ Timer related

nRF52833 timers and interrupt configuration:

Tstellanova Rust crate for RPi real time clock:

52833 Module base interrupts (base_interrupts):

^ Linker Flags

^ Significant Projects in Rust

A link to Oxide Computer real time operating system Hubris . . .

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

^ Questions to Answer

(1) For what is Rust language 'derive' keyword used?

  #[derive(Clone)]

  #[derive(Default)]

(2) How is the `.await` method working, and is this kind of element called a method in Rust?

(3) Rust `match` construct, is this equal to C switch statement?

(4) what does at or near top of source file `use defmt::*;` mean?

(5) Rust `impl` a keyword? Seeing this in lines like `impl CanTxChannel`.

(6) `.await.unwrap()` versus `.await`?

(7) What is the following forward arrow operator in this context?:

  pub async fn <function_name>(var declarations) -> () { ... }

(8) What mean the following top of file lines?:

#![no_std]
#![no_main]

^ Things To Learn Well

Topics in Rust and programming in general to learn well.

Type-level programming in Rust . . .

Analysis and debugging tool rust-analyzer . . .


^ References Rust and Embassy

What are `Some` and `None` in Rust . . .

A Rust Embedded book by Ferrous Systems . . .