Notes

Rust Setup

Installation

bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Updating Rust Version

bash
rustup update

Hello World

https://rust-lang.org/learn/get-started/

bash
cargo new hello # hello/ # .gitignore # Cargo.toml # src/ # main.rs

Cargo.toml

toml
[package] name = "hello" version = "0.1.0" edition = "2024" [dependencies]

main.rs

rust
fn main() { println!("Hello, world!"); }

Build and run

bash
cargo build # Compiling hello v0.1.0 (/home/mike/Work/science/hello) # Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.68s cargo run # Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s # Running `target/debug/hello` # Hello, world! ./target/debug/hello # Hello, world! cargo build -r cargo build --release # Compiling hello v0.1.0 (/home/mike/Work/science/hello) # Finished `release` profile [optimized] target(s) in 0.16s cargo run -r cargo run --release # Finished `release` profile [optimized] target(s) in 0.01s # Running `target/release/hello` # Hello, world! ./target/release/hello # Hello, world! find . -name 'hello' -print0 | xargs -0 ls -lhS # 3.8M ./target/debug/hello # 439K ./target/release/hello

Generating a smaller binary

Cargo.toml

toml
[package] name = "hello" version = "0.1.0" edition = "2024" [dependencies] [profile.release] opt-level = "z" # Optimize for size strip = true # Strip symbols lto = true # Link-time optimizations codegen-units = 1 # Certain optimizations only work if parallel code generation is disabled panic = "abort" # Don't generate helpful backtraces on panic!()

More here: https://github.com/johnthagen/min-sized-rust

WCH RISC-V Microcontrollers

Noteworthy chips (IMO)

ChipArchSpeedSRAMFlashPowerNotes
CH32V003V2A48MHz2KB16KB??
CH32V002V2C48MHz4KB16KB2-5VPin compatible with V003
CH32V006V2C48MHz8KB16KB2-5V
CH32V203V4B144MHz20KB??KB3.3VNo PMP, Slow DIV opcode
CH32V305V4F144MHz32KB??KB3.3VFPU
CH32V307V4F144MHz64KB??KB3.3VFPU, Ethernet

More here: https://github.com/ch32-rs/ch32-data#Families

Flashing devices

Via WCH-LinkE (Dongle with CH32V305)

This is the method you want to program bare chips (or modules without a USB port and/or buttons).