Cargo.toml is the TOML-formatted manifest for a Rust package. It declares package metadata and dependencies and can configure build profiles and features. For embedded firmware, these choices help match the build to the hardware and its memory limits. section 3.1.2
[package]
name = "cortex-m-blinky"
edition = "2024"
version = "0.1.0"
[dependencies]
cortex-m = "0.7"
cortex-m-rt = "0.7"
cortex-m-semihosting = "0.5"
panic-halt = "1.0.0"
stm32f1xx-hal = { version = "0.11.0", features = ["stm32f103", "medium"] }
[profile.release]
opt-level = 'z'
codegen-units = 1
lto = true
This manifest declares an STM32 HAL dependency with hardware features and a release profile optimized for a small binary. The opt-level setting favors size, while link-time optimization further reduces the code footprint. section 3.1.2
Cargo features are named compile-time switches. A dependency can expose features for a microcontroller variant or runtime integration, allowing the build to include what the application needs rather than every available code path. section 3.1.2
[package]
name = "feature-demo"
version = "0.1.0"
edition = "2024"
[dependencies]
cortex-m = "0.7.7"
cortex-m-rt = "0.7.5"
panic-halt = { version = "1.0.0", optional = true }
panic-semihosting = { version = "0.6", optional = true }
cortex-m-semihosting = { version = "0.5", optional = true }
[features]
default = ["panic-halt"]
semihosting = ["dep:panic-semihosting", "dep:cortex-m-semihosting"]
Optional dependencies and named features select a panic handler. The default enables panic-halt; the semihosting feature enables dependencies for diagnostic output. section 3.3.2
Use conditional compilation in Rust code to select the corresponding behavior. For the preceding manifest, cargo run uses the default feature; cargo run --no-default-features --features semihosting selects the alternative. Running on hardware also requires an appropriately configured runner. section 3.3.2
Check dependency features before using a crate in a bare-metal build: desktop defaults can include std. For example, arrayvec = { version = "0.7", default-features = false } disables its default features. Use cargo tree -e features to inspect which features are enabled and how they propagate. section 3.3.4
Cargo.toml is distinct from .cargo/config.toml, which can define targets, linker arguments and runner commands. Cargo.lock records dependency versions, while memory.x specifies the firmware memory layout. section 3.6




