Mastering Embedded Rust: Bare Metal, FFI, Crates, Projects

Mastering Embedded Rust: Bare Metal, FFI, Crates, Projects

English | MP4 | AVC 1280×720 | AAC 44KHz 2ch | 172 Lessons (23h 17m) | 9.84 GB

Master safe, modern embedded systems in Rust with bare-metal, FFI, drivers, crates & projects on STM32 microcontrollers

Looking to add another embedded programming language to your arsenal? Give Rust a shot — you won’t be disappointed!!

This course is your starting point for using Rust on ARM Cortex Mx based microcontrollers such as STM32, even if you are new to embedded systems.

This is a fully hands on course that takes you from scratch into real world embedded Rust development on STM32. Each video builds on the previous, helping you progress step-by-step, from writing bare metal code to advanced topics like FFI, crates, driver development, and traits. Ideal for those new to Rust and embedded systems.

Why Rust for embedded?

Rust prevents many common memory issues (like null pointer dereferencing, buffer overflows, and use-after-free errors) through:

  • Ownership model: Rust’s strict rules around ownership, borrowing, and lifetimes prevent most accidental memory misuse.
  • Type safety: Rust’s type system ensures that you access data correctly and helps prevent certain types of invalid memory access by enforcing strict variable usage patterns.

Thanks to Cargo, Rust’s official package manager, you can easily add features by simply including external libraries, or “crates,” which are like plug-and-play components.

What will you learn?

Here’s what you will master in this course:

  1. A beginner-friendly introduction to Rust, tailored for embedded systems
  2. Complete toolchain setup for cross-compiling, flashing, and debugging
  3. Debugging and logging with defmt and probe-rs for real-time tracing
  4. High-level peripheral programming with STM32 HAL crate
  5. Step-by-step, build a real-world Flappy Bird game application using Rust
  6. Interface with real sensors (MPU6050) to control game mechanics
  7. Clean, modular coding practices and hardware abstraction
  8. Build hardware-agnostic drivers using the embedded-hal traits
  9. Writing and understanding your own linker scripts and startup code
  10. Building generic embedded code using Rust generics and traits
  11. Safe and seamless Rust + C integration through FFI
  12. Confidence to write robust, reusable, and production-grade embedded firmware in Rust

Hardware Requirements

Note: If you already have a microcontroller development board, we recommend continuing with it. This course is designed with such thoroughness that the concepts and steps can be applied to most development boards though some minor adjustments may be needed. But, if you prefer to use the exact same board as the instructor for a smoother experience, you can check out the recommended hardware

1) Microcontroller development board

Option-1. STM32F303-Based Board

  • The course primarily utilizes Fastbit STM32 Nano board which is based on the STM32F303 microcontroller and onboard MPU6050 sensor.

Option 2.  Any STM32 Microcontroller Board

  • You can use any development board featuring an STM32 microcontroller. The course content is designed to be adaptable, allowing you to follow along with the specific STM32 board you have available.

2) SWD-Based Debugger

  • An SWD (Serial Wire Debug) based debugger is required for programming and debugging your STM32 microcontroller. This tool is essential for loading your programs onto the microcontroller and for debugging your projects in real-time.

3) LCD shield

  • In one of the projects, you will need a TFT LCD module for experimentation. This course uses the Fastbit 1.28″ TFT LCD with an 8-bit parallel interface, based on the GC9A01 LCD driver. However, you are free to use the same or a similar compatible module

4) MPU6050 sensor

Software requirements

  1. VS Code
  2. STM32CubeIDE

Who this course is for:

  • Embedded developers looking to explore Rust as an alternative to C/C++ or to make it coexist with existing code for microcontroller programming
  • Rust enthusiasts who want to apply their skills to low-level, hardware-focused projects and learn embedded programming.
  • Beginners in embedded systems eager to build practical skills from the ground up
  • Looking to add another embedded language to your arsenal? Give Rust a shot, you won’t be disappointed
Table of Contents

Introduction
1 Welcome
2 Course repository

Rust Toolchain Installation
3 Toolchain installation for Host
4 Toolchain components and target triple of Tier 1 targets
5 Install VS Code IDE
6 Creating a Rust project using Cargo and Important VS code extensions
7 Important tools rustfmt, cargo fix , Clippy

Rust Fundamentals Quick intro to core concepts
8 How Rust ensures memory safety compared to CC++ part 1
9 Variables and numerical data types
10 Byte literal
11 Char and unicode representation
12 Statics
13 Constants
14 How Rust ensures memory safety compared to CC++ part 2
15 Arrays
16 References
17 Borrow(&T and &mut T)
18 Can you help us
19 slice data type
20 if..else as a statement and expression
21 match statement
22 if..let statement
23 How Rust ensures memory safety compared to CC++ part 3
24 Comparison and logical operators
25 Bitwise operators
26 Strings
27 UTF8 encoded string
28 String literal type(&str)
29 Function declaration and parameters
30 Structures
31 Printing the structure
32 Initializing struct with defaults
33 Passing struct variables to functions
34 Creating methods for a struct
35 Associated functions(Constructor) of struct
36 Enums
37 Methods and associated functions of an enum type
38 OptionT
39 ResultT, E
40 Error handling using Result type
41 Error propagation using
42 Generics

Cross compilation
43 About the hardware
44 Intro to cross compilation for target architecture
45 Exercise 001 Generating ELF file for the very basic rust program part 1
46 Generating ELF file for the very basic rust program part 2
47 About Type ‘never'(!)
48 Inspecting ELF file using cargo-binutils

Writing start-up code and linker script for bare metal Rust program
49 Writing start-up code part-1
50 About Linker, Linker flags and Linker script
51 Writing linker script from scratch part 1 [MEMORY]
52 Different types of data in a program
53 Writing linker script from scratch part 2 [SECTIONS]
54 Writing linker script from scratch part 3
55 Writing start-up code part-2 [Vector table]
56 Writing start-up code part-3 [extern C]
57 Writing start-up code part-4 [Default_Handlers]
58 Writing start-up code part-5 [Reset_Handler]
59 Raw pointers in Rust
60 Writing start-up code part-6 [Reset_Handler]
61 Can you help us

Flash and Debug
62 Flashing code to target hardware-1 [Install STM32CubeCLT]
63 Flashing code to target hardware-2 [VsCode and cortex-debug setup]
64 Flashing code using probe.rs tools

Exercise 002 Bare metal Rust application to handle LEDs using Interrupts
65 Introduction
66 Exercise Implementation Part 1
67 Exercise Implementation Part 2
68 Exercise Implementation Part 3
69 Exercise Implementation Part 4
70 Exercise Implementation Part 5
71 Exercise Implementation Part 6
72 Exercise Implementation Part 7 and Testing LED module
73 Unsafe block vs Unsafe fn
74 Commenting and generating documentation part 2 [! Inner documentation]
75 Commenting and generating documentation part 1 [ Outer documentation]
76 Exercise Implementation Part 8; Writing button module
77 Exercise Implementation Part 9; Coding for button interrupt
78 Exercise Implementation Part 10
79 Exercise Implementation Part 11
80 Exercise Implementation Part 12
81 Exercise Implementation Part 13
82 Exercise Implementation Part 14 Testing button interrupt

Exercise 003 Using external crate cortex-m-rt and cortex-m
83 What is a crate
84 Important crates for embedded systems
85 Exercise introduction
86 Cortex-m-rt crate explanation
87 Crate version number syntax
88 Panic handling crates
89 Systick time base generation using cortex-m crate
90 Testing Systick time base generation
91 Can you help us

Exercise 004 ITM prints
92 Exercise 004 introduction
93 Instrumentation Trace Macrocell(ITM)
94 Exercise implementation
95 Refactoring and Testing
96 Critical section
97 Mutex and Refcell

Rust Foreign Function Interface(FFI)
98 Steps involved in dealing with Rust and Foreign language code
99 Types mapping between Rust and C
100 Rust equivalent of C’s void and void pointer
101 Rust equivalent of C’s void and void pointer contd
102 Rust representation of C’s String
103 Rust accepting and processing Strings from ‘C’ (coreffiCstr)
104 Rust sending Strings to ‘C’ (stdffiCString)
105 Struct memory layout Rust Vs C
106 Passing struct from Rust to C

Exercise 005 Flappy Bird game implementation(Rust + C)
107 Introduction to Flappy bird application
108 Implementation Peripheral config and code generation(8 bit parallel LCD)
109 Implementation Peripheral config and code generation(SPI based LCD)
110 Compiling ‘C’ source files from Rust project How it works
111 Writing build.rs part 1
112 Writing build.rs part 2
113 Writing build.rs part 3
114 Writing build.rs part 4
115 Writing build.rs part 5
116 Testing project for systick interrupt generation
117 Copy driver files into the project
118 Analysing the issue related to weak symbol linkage
119 Fixing issue related to weak symbol linkage and testing project
120 Game feature Start screen implementation part-1
121 Game feature Start screen implementation part-2
122 Game feature Start screen implementation part-3
123 Game feature Start screen implementation part-4
124 Game feature Start screen implementation part-5
125 Game feature Start screen implementation part-6
126 Game feature Start screen implementation part-7
127 Game feature Start screen implementation part-8
128 Game feature Start screen implementation part-9
129 Game feature Start screen implementation part-10
130 Game feature Start screen implementation part-11
131 Game feature Start screen implementation part-12
132 Game feature Start screen implementation part-13
133 Game feature Obstacle movement implementation part-1
134 Game feature Obstacle movement implementation part-2
135 Game feature Obstacle movement implementation part-3
136 Game feature Obstacle movement implementation part-4
137 Game feature Obstacle movement implementation part-5
138 Game feature Obstacle movement implementation part-6
139 Game feature Player movement implementation part-1
140 Game feature Player movement implementation part-2
141 Game feature Collision detection implementation part-1
142 Game feature Collision detection implementation part-2
143 Game feature Collision detection implementation part-3

Creating hardware agnostic device driver using embedded-hal
144 About hardware agnostic driver development
145 MPU6050 driver crate implementation part-1
146 MPU6050 driver crate implementation part-2
147 MPU6050 driver crate implementation part-3
148 MPU6050 driver crate implementation part-4
149 MPU6050 driver crate implementation part-5
150 MPU6050 driver crate implementation part-6
151 MPU6050 driver crate implementation part-7
152 MPU6050 driver crate implementation part-8
153 MPU6050 driver crate implementation part-9
154 Adding [features] to driver crate

Working with Hal crate and PAC
155 Exercise 005 Reading from sensor part 1
156 PAC and HAL
157 I2C initialization coding part 1
158 I2C initialization coding part 2
159 I2C initialization coding part 3

Using Traits
160 Handling input device via Trait implementation part 1
161 Handling input device via Trait implementation part 2
162 Handling input device via Trait implementation part 3

Logging
163 Logging data using RTT and probe.rs
164 Logging data using RTT testing

Exercise 005 Flappy Bird game implementation(Rust + C) contd
165 Game feature Calculating roll angle
166 Game feature Map roll angle to bird position
167 Updating bird Y position
168 Note about sensor noise
169 Testing final application
170 TODOs for the students
171 Next videos coming soon
172 BONUS LECTURE

Homepage