Learn Embedded-rust - 3 Code Examples & CST Typing Practice Test
Embedded Rust refers to using the Rust programming language to develop software for embedded systems, microcontrollers, and resource-constrained devices. It focuses on safety, performance, and concurrency without relying on runtime environments or garbage collection.
View all 3 Embedded-rust code examples →
Learn EMBEDDED-RUST with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
Blink an LED
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f4xx_hal::{prelude::*, stm32};
#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let gpiod = dp.GPIOD.split();
let mut led = gpiod.pd12.into_push_pull_output();
loop {
led.toggle().unwrap();
cortex_m::asm::delay(8_000_000);
}
}
Toggle an LED on pin 13 every 500 ms using Embedded Rust.
Read Analog Sensor
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f4xx_hal::{adc::Adc, prelude::*, serial::Serial, stm32};
#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let mut adc = Adc::adc1(dp.ADC1, true);
let mut serial = Serial::usart2(dp.USART2, ...);
loop {
let value: u16 = adc.read(&mut dp.GPIOA.pa0).unwrap();
writeln!(serial, "ADC value: {}", value).unwrap();
}
}
Read a potentiometer value from an ADC pin and print via serial.
Control Servo Motor
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f4xx_hal::{prelude::*, pwm, stm32};
use cortex_m::asm::delay;
#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let pwm_pin = ...; // configure PWM for servo
loop {
for duty in 40..=115 {
pwm_pin.set_duty(duty);
delay(1_000_000);
}
for duty in (40..=115).rev() {
pwm_pin.set_duty(duty);
delay(1_000_000);
}
}
}
Sweep a servo motor using PWM on pin D9.
Frequently Asked Questions about Embedded-rust
What is Embedded-rust?
Embedded Rust refers to using the Rust programming language to develop software for embedded systems, microcontrollers, and resource-constrained devices. It focuses on safety, performance, and concurrency without relying on runtime environments or garbage collection.
What are the primary use cases for Embedded-rust?
Firmware development for microcontrollers. Real-time control of sensors and actuators. IoT device programming and communication. Embedded systems prototyping and development. Safety-critical and low-level hardware software
What are the strengths of Embedded-rust?
Safe low-level programming with performance close to C/C++. Reduced risk of memory corruption and undefined behavior. Growing ecosystem for embedded hardware support. Concurrency and parallelism safety built into the language. Active community and modern tooling
What are the limitations of Embedded-rust?
Learning curve for ownership, lifetimes, and concurrency models. Limited ecosystem compared to C/C++ in some niche hardware. Compile times can be longer than C/C++. Tooling for debugging embedded Rust is still maturing. Some microcontroller support requires nightly Rust features
How can I practice Embedded-rust typing speed?
CodeSpeedTest offers 3+ real Embedded-rust code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.