NUCLEO-G474RE-blink-for-embedded-rust

Crates.ioNUCLEO-G474RE-blink-for-embedded-rust
lib.rsNUCLEO-G474RE-blink-for-embedded-rust
version0.2.0
created_at2025-12-27 04:56:46.84059+00
updated_at2026-01-02 23:13:31.789014+00
descriptionExample project for blinking an LED on the NUCLEO-G474RE board using embedded Rust.
homepage
repositoryhttps://github.com/Patricio-Andre/NUCLEO-G474RE-blink-for-embedded-rust
max_upload_size
id2006702
size2,985,599
André Patricio (Patricio-Andre)

documentation

README

blink_minimum — Nucleo G474RE

This repository contains a minimal Rust example that blinks the LED on the Nucleo G474RE board. The project is intended as a starting point for embedded Rust development on the STM32G4xx family. The repository includes a canonical project layout, Cargo.toml, .cargo/config.toml, a Makefile, and memory.x linker script — common components for embedded Rust projects.

Main contents:

  • src/main.rs — embedded application (main loop toggling PA5).
  • src/utils/ — utilities for the example (previously included logging helpers).
  • memory.x — linker script (Flash/RAM layout).
  • Makefile — convenient targets (build, release, embed, flash, clippy, ...).
  • .cargo/config.toml — build/target configuration.

Quick overview

The crate is configured for the thumbv7em-none-eabihf target and uses the stm32g474 feature of stm32g4xx-hal. This example focuses on blinking the LED and does not depend on any logging backend by default.

Prerequisites

  • Rust toolchain (rustup)
  • Add the target:
rustup target add thumbv7em-none-eabihf
  • Cross toolchain / linker (example for Debian/Ubuntu):
sudo apt update
sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi
  • Flashing / debug tools (choose one or more):
cargo install probe-rs         # runner for `cargo run`
cargo install cargo-flash      # cargo-flash
cargo install cargo-embed      # cargo-embed (optional, supports many boards)

Notes about .cargo/config.toml

This project includes .cargo/config.toml with target = "thumbv7em-none-eabihf". It also contains a rustflags entry:

[target.thumbv7em-none-eabihf]
rustflags = ["-C", "link-arg=-Tlink.x"]

[build]
target = "thumbv7em-none-eabihf"

Important: the provided linker script is named memory.x.

Local build

Debug build:

cargo build

Release build (optimized):

cargo build --release

Using the Makefile is convenient but you should understand the underlying commands.

Flash / Run on Nucleo G474RE

If automatic detection fails, specify the chip explicitly:

cargo run
# or (with cargo-embed)
cargo embed

Board Manuals and References

Use the product pages above to download the latest datasheet and reference manuals for the MCU and the Nucleo board. These manuals contain pinouts, electrical characteristics, peripheral descriptions, and programming guidelines that are helpful when adapting this example to other boards.

SVD file for debugging purposes: https://github.com/modm-io/cmsis-svd-stm32.git

Logging

Uses defmt for logging, enabled via RTT by default. Read the documentation to use it properly: https://defmt.ferrous-systems.com/

VsCode Debugging Setup

This project includes a .vscode/launch.json file configured for debugging with the Cortex-Debug extension. Make sure to install the extension and adjust the executable path if necessary.

Commit count: 0

cargo fmt