A cargo-generate template for Rust embedded projects on STM32 chips. It includes Embassy, Defmt, and Probe-rs configurations.
- Configuration: Sets the target architecture based on the chip model.
- Embassy: Includes Embassy Executor and common components.
- Defmt: Includes
defmtanddefmt-rttlogging with RTT support. - Structure: Organized into
controller,system, andtasksmodules. - Debugging:
- Probe-rs: Default runner.
- OpenOCD: Optional OpenOCD configuration.
- RTT Forwarding: Optional RTT log forwarding.
Before using this template, please ensure the following tools are installed:
-
Rust Toolchain
pacman -S rustup rustup default stable
-
cargo-generate
pacman -S cargo-generate
-
probe-rs
pacman -S probe-rs
-
OpenOCD (Optional)
pacman -S openocd
Generate a new project using the following command:
cargo generate --git https://github.com/Salfa-04/quickstart --name my-projectDuring the generation process, you will need to answer the following questions:
- Target Chip: Enter your target chip model (e.g.,
stm32g473re). The template will automatically identify the chip series and set the correct compilation target. - Include RTT Forwarding Support?: Whether to enable RTT log forwarding support.
- If enabled, you need to enter the RTT Server Address (e.g.,
127.0.0.1:1008).
- If enabled, you need to enter the RTT Server Address (e.g.,
- Include OpenOCD Configuration Files?: Whether to generate OpenOCD configuration files.
- If enabled, you need to select the corresponding configuration file (e.g.,
stm32g4x.cfg).
- If enabled, you need to select the corresponding configuration file (e.g.,
The generated project contains the following main parts:
.
├── Cargo.toml # Workspace configuration
├── .cargo/config.toml # Build and run configuration (Auto-generated Target and Runner)
├── utils/ # Common utility library (Initialization, macros, etc.)
└── <project-name>/ # Your application crate
├── Cargo.toml
├── Embed.toml # probe-rs configuration
├── build.rs
└── src/
├── main.rs # Program entry point
├── controller/ # Control logic
├── system/ # Hardware abstraction and system configuration (GPIO, Clock, Interrupts, etc.)
└── tasks/ # Async tasks (Blinky, Health check, etc.)
The template configures probe-rs as the runner by default.
-
Run in Debug Mode:
cargo run # Or use the alias cargo r -
Run in Release Mode:
cargo run --release # Or use the alias cargo rr
If you chose to generate OpenOCD configuration:
-
Start the OpenOCD Service:
openocd -f openocd.cfg
-
Download and Run the Program:
openocd -f <project-name>/openocd.cfg
(Note: You may need to modify the runner configuration in
.cargo/config.tomlto adapt to GDB/OpenOCD)
- Which chips are supported?
Currently, the script supports common STM32 series (F0, F1, F3, F4, F7, G0, G4, H7, L0, L4, U5, etc.). If you encounter an unsupported chip, please check
prehooks.rhaior manually modify the generated.cargo/config.toml.