Control Servo Motor - Embedded-rust Typing CST Test
Loading…
Control Servo Motor — Embedded-rust Code
Sweep a servo motor using PWM on pin D9.
#![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);
}
}
}Embedded-rust Language Guide
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.
Primary Use Cases
- ▸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
Notable Features
- ▸Memory safety without runtime overhead
- ▸Zero-cost abstractions and high performance
- ▸Strong type system preventing common bugs
- ▸Hardware-level control through HALs and PACs
- ▸Support for concurrency and async programming
Origin & Creator
Rust was created by Mozilla in 2010 to offer a safe, fast, and concurrent systems programming language. Embedded Rust emerged through the community’s adaptation of Rust for microcontroller and bare-metal programming.
Industrial Note
Embedded Rust is increasingly adopted in safety-critical industries such as automotive, aerospace, and industrial IoT for reliable, memory-safe firmware development.