SlideShare a Scribd company logo
Embedded Rust 

On IoT Devices
Lars Gregori

Hybris Labs
Hybris Labs Prototypes
https://labs.hybris.com/prototype/
Motivation
Functional IoT (http://fpiot.metasepi.org/):
Imagine IoT devices are:
• connected to the internet
• developed in a short time
• storing personal data
• secure
• more intelligence
• inexpensive
Can C design IoT devices like that? No, can't.
Agenda
• Rust Overview
• Embedded Rust
• Cross Compiling
• MCU Debugging
Rust Overview
rust-lang.org
1.9.0
rust-lang.org
Rust is a systems programming language
that runs blazingly fast, prevents segfaults,
and guarantees thread safety.
Rust Overview
Rust FAQ
Rust FAQ
• safe, concurrent, practical system language
• “We do not intend to be 

100% static, 

100% safe, 

100% reflective, 

or too dogmatic in any other sense.”
• Mozilla Servo
Rust FAQ
• multi-paradigm
• OO
• no garbage collection
• strong influences from the world of functional programming
• built on LLVM
Rust FAQ
• Cross-Platform
• Android, iOS, …
• Conditional compilation

#[cfg(target_os	=	"macos")]
Rust Overview
Control & Safety
Control & Safety
C/C++
Safety
Control
Haskell
Go
Java
Python
Control & Safety
C/C++
Safety
Control
Haskell
Go
Java
Rust
Python
Rust Overview
Rust Concepts
Rust Concepts
• ownership, the key concept
• borrowing, and their associated feature ‘references’
• lifetimes, an advanced concept of borrowing
‘fighting with the borrow checker’
https://doc.rust-lang.org/book/
Rust Concepts: Ownership
let v = vec![1, 2, 3];
let v2 = v;
// …
println!("v[0] is: {}", v[0]);
Rust Concepts: Ownership
let v = vec![1, 2, 3];
let v2 = v;
// …
println!("v[0] is: {}", v[0]); ERROR
use of moved value: `v`
Rust Concepts: Ownership
let v = vec![1, 2, 3];
let v2 = v;
take_something(v2);
println!("v[0] is: {}", v[0]); ERROR
use of moved value: `v`
Rust Concepts: Ownership
let v = 1;
let v2 = v;
println!("v is: {}", v);
Rust Concepts: Ownership
let v = 1;
let v2 = v;
println!("v is: {}", v); OK
Copy Type
Rust Concepts: Ownership
fn foo(v1: Vec<i32>, v2: Vec<i32>) -> (Vec<i32>, Vec<i32>, i32) {
// do stuff with v1 and v2
(v1, v2, 42) // hand back ownership, and the result of our function
}
let v1 = vec![1, 2, 3];
let v2 = vec![1, 2, 3];
let (v1, v2, answer) = foo(v1, v2);
Rust Concepts: References and Borrowing
fn foo(v1: &Vec<i32>, v2: &Vec<i32>) -> i32 {
// do stuff with v1 and v2
42 // return the answer
}
let v1 = vec![1, 2, 3];
let v2 = vec![1, 2, 3];
let answer = foo(&v1, &v2);
// we can use v1 and v2 here!
Rust Concepts: References and Borrowing
fn foo(v: &Vec<i32>) {
v.push(5);
}
let v = vec![];
foo(&v);
Rust Concepts: References and Borrowing
fn foo(v: &Vec<i32>) {
v.push(5);
}
let v = vec![];
foo(&v);
ERROR
cannot borrow immutable borrowed content `*v` as mutable
Rust Concepts: References and Borrowing
let mut x = 5;
{
let y = &mut x;
*y += 1;
}
println!("{}", x);
RUN
Rust Concepts: References and Borrowing
let mut x = 5;
{
let y = &mut x;
*y += 1;
}
println!("{}", x); OK: 6
RUN
Rust Concepts: References and Borrowing
let mut x = 5;
{
let y = &mut x;
*y += 1;
}
println!("{}", x); OK: 6
☜
☜
☟
RUN
Rust Concepts: References and Borrowing
The Rules for borrowing:
1. Any borrow must last for a scope no greater than that of the owner.
2. Only one of these kinds of borrows, but not both at the same time:
• one or more references (&T) to a resource
• exactly one mutable reference (&mut T)
Rust Concepts: References and Borrowing
let mut x = 5;
let y = &mut x;
*y += 1;
println!("{}", x); Error
RUN
cannot borrow `x` as immutable 

because it is also borrowed as mutable
Agenda
• Rust Overview
• Embedded Rust
• Cross Compiling
• MCU Debugging
Embedded Rust
zinc.rs
zinc.rs
Zinc is an experimental attempt to write an ARM stack
that would be similar to CMSIS or mbed in capabilities
but would show rust’s best safety features applied to
embedded development.
Zinc is mostly assembly-free and completely C-free at
the moment.
STM32 Nucleo-F411RE
STM32 Nucleo-F411RE
☜
▶︎Embedded Rust
Agenda
• Rust Overview
• Embedded Rust
• Cross Compiling
• MCU Debugging
Cross-Compiling
Rustup
https://www.rustup.rs/
rustup is an installer for the systems programming language Rust
> rustup install nightly-2016-09-17
> rustup override set nightly-2016-09-17
GNU ARM Embedded Toolchain
https://launchpad.net/gcc-arm-embedded/+download
arm-none-eabi-gcc
arm-none-eabi-gdb
…
eabi = Embedded Application Binary Interface (>)
Building
cargo	build	--target=thumbv7em-none-eabi	--features	mcu_stm32f4
▶︎Cross-Compiling
Agenda
• Rust Overview
• Embedded Rust
• Cross Compiling
• MCU Debugging
MCU Debugging
Debugging Rust
zinc.rs Issue #336
Failing to build example. #336
src/hal/layout_common.ld
comment out *(.debug_gdb_scripts)
Debugging Rust
>	openocd	…	-c	gdb_port	3333	
>	arm-none-eabi-gdb	
(gdb)	target	remote	:3333	
(gdb)	file	./target/thumbv7em-none-eabi/debug/blink_stm32f4	
(gdb)	break	main	
(gdb)	continue	
(gdb)	next
Debugging Rust
(gdb) set delay = 1000
(gdb) list
(gdb) disassemble
▶︎MCU Debugging
What we’ve seen
• Rust Overview ✔
• Embedded Rust ✔
• Cross Compiling ✔
• MCU Debugging ✔
• Hello World
Thank you!
@choas
labs.hybris.com
Embedded Rust on IoT devices

More Related Content

PDF
Rust system programming language
PDF
Introduction to rust: a low-level language with high-level abstractions
PDF
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
PPT
Rust Programming Language
PDF
Deep drive into rust programming language
PDF
An introduction to Rust: the modern programming language to develop safe and ...
PDF
PHPUnit 入門介紹
PPTX
Rust system programming language
Introduction to rust: a low-level language with high-level abstractions
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Rust Programming Language
Deep drive into rust programming language
An introduction to Rust: the modern programming language to develop safe and ...
PHPUnit 入門介紹

What's hot (20)

PDF
Mutation Testing
PPTX
Guide to GraalVM (JJUG CCC 2019 Fall)
PDF
Building the Game Server both API and Realtime via c#
PDF
WebRTC と Native とそれから、それから。
PDF
Introduction to Rust
PDF
Software Analytics: Data Analytics for Software Engineering
PDF
Linuxにて複数のコマンドを並列実行(同時実行数の制限付き)
PDF
libinjection : SQLi から XSS へ by ニック・ガルブレス
PDF
コールバックと戦う話
PDF
constexpr関数はコンパイル時処理。これはいい。実行時が霞んで見える。cpuの嬌声が聞こえてきそうだ
PPTX
設計品質とアーキテクチャ
PDF
キメるClojure
PDF
Heterogeneous multiprocessing on androd and i.mx7
PDF
入門Transducers
PDF
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
PDF
The Internals of "Hello World" Program
PPTX
インフラエンジニアのお仕事 ~ daemontools から systemdに乗り換えた話 ~
PDF
台科逆向簡報
PPTX
明日からはじめられる Docker + さくらvpsを使った開発環境構築
PPT
Mutation Testing
Guide to GraalVM (JJUG CCC 2019 Fall)
Building the Game Server both API and Realtime via c#
WebRTC と Native とそれから、それから。
Introduction to Rust
Software Analytics: Data Analytics for Software Engineering
Linuxにて複数のコマンドを並列実行(同時実行数の制限付き)
libinjection : SQLi から XSS へ by ニック・ガルブレス
コールバックと戦う話
constexpr関数はコンパイル時処理。これはいい。実行時が霞んで見える。cpuの嬌声が聞こえてきそうだ
設計品質とアーキテクチャ
キメるClojure
Heterogeneous multiprocessing on androd and i.mx7
入門Transducers
Windows PowerShell によるWindows Server 管理の自動化 v4.0 2014.03.13 更新版
The Internals of "Hello World" Program
インフラエンジニアのお仕事 ~ daemontools から systemdに乗り換えた話 ~
台科逆向簡報
明日からはじめられる Docker + さくらvpsを使った開発環境構築
Ad

Viewers also liked (16)

PDF
Embedded Rust – Rust on IoT devices
PDF
Rust: Systems Programming for Everyone
PPTX
JavaScript and Internet Controlled Electronics
PPTX
Programming The Arduino Due in Rust
PDF
Internet of things, lafayette tech
PDF
Let's Play STM32
PDF
Servo: The parallel web engine
PDF
Stm32 f4 first touch
PPTX
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
PPTX
présentation STM32
PPT
PDF
Track 2 session 2 - st dev con 2016 - stm32 open development environment
PDF
Rust Workshop - NITC FOSSMEET 2017
PDF
AWSマネージドサービスをフル活用したヘルスケアIoTプラットフォーム
PDF
スマートファクトリーを支えるIoTインフラをつくった話
PPTX
Microservices Done Right: Key Ingredients for Microservices Success
Embedded Rust – Rust on IoT devices
Rust: Systems Programming for Everyone
JavaScript and Internet Controlled Electronics
Programming The Arduino Due in Rust
Internet of things, lafayette tech
Let's Play STM32
Servo: The parallel web engine
Stm32 f4 first touch
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
présentation STM32
Track 2 session 2 - st dev con 2016 - stm32 open development environment
Rust Workshop - NITC FOSSMEET 2017
AWSマネージドサービスをフル活用したヘルスケアIoTプラットフォーム
スマートファクトリーを支えるIoTインフラをつくった話
Microservices Done Right: Key Ingredients for Microservices Success
Ad

Similar to Embedded Rust on IoT devices (20)

PDF
Intro to Rust 2019
PDF
Guaranteeing Memory Safety in Rust
PDF
Le langage rust
PPTX
Rust Intro
PDF
Rust: Reach Further
PDF
Rust Intro @ Roma Rust meetup
ODP
Rust Primer
PDF
Rust "Hot or Not" at Sioux
PDF
Rust: Unlocking Systems Programming
PDF
Introduction to Rust Programming Language
PDF
Short intro to the Rust language
PDF
Be pinched by a cRUSTacean to prevent programming errors !
PDF
Introduction to the rust programming language
PDF
The Rust Programming Language
PPTX
Briefly Rust
PDF
Introduction to Rust
PDF
Why rust?
PPTX
Introduction to Rust language programming
PPTX
Tour of Rust
PDF
Rust: Reach Further (from QCon Sao Paolo 2018)
Intro to Rust 2019
Guaranteeing Memory Safety in Rust
Le langage rust
Rust Intro
Rust: Reach Further
Rust Intro @ Roma Rust meetup
Rust Primer
Rust "Hot or Not" at Sioux
Rust: Unlocking Systems Programming
Introduction to Rust Programming Language
Short intro to the Rust language
Be pinched by a cRUSTacean to prevent programming errors !
Introduction to the rust programming language
The Rust Programming Language
Briefly Rust
Introduction to Rust
Why rust?
Introduction to Rust language programming
Tour of Rust
Rust: Reach Further (from QCon Sao Paolo 2018)

More from Lars Gregori (20)

PDF
BYOM - Bring Your Own Model
PDF
uTensor - embedded devices and machine learning models
PDF
SAP Leonardo Machine Learning
PDF
Minecraft and reinforcement learning
PDF
Machine Learning Models on Mobile Devices
PDF
Minecraft and Reinforcement Learning
PDF
IoT protocolls - smart washing machine
PDF
[DE] AI und Minecraft
PDF
Minecraft and Reinforcement Learning
PDF
[DE] IoT Protokolle
PDF
Using a trained model on your mobile device
PDF
Using a trained model on your mobile device
PDF
AI and Minecraft
PDF
[German] Boards für das IoT-Prototyping
PDF
IoT, APIs und Microservices - alles unter Node-RED
PDF
Web Bluetooth - Next Generation Bluetooth?
PDF
IoT mit Rust programmieren
PDF
Boards for the IoT-Prototyping
PDF
Groß steuert klein - Wie lässt sich ein Arduino steuern?
PDF
Connecting Minecraft and e-Commerce business services
BYOM - Bring Your Own Model
uTensor - embedded devices and machine learning models
SAP Leonardo Machine Learning
Minecraft and reinforcement learning
Machine Learning Models on Mobile Devices
Minecraft and Reinforcement Learning
IoT protocolls - smart washing machine
[DE] AI und Minecraft
Minecraft and Reinforcement Learning
[DE] IoT Protokolle
Using a trained model on your mobile device
Using a trained model on your mobile device
AI and Minecraft
[German] Boards für das IoT-Prototyping
IoT, APIs und Microservices - alles unter Node-RED
Web Bluetooth - Next Generation Bluetooth?
IoT mit Rust programmieren
Boards for the IoT-Prototyping
Groß steuert klein - Wie lässt sich ein Arduino steuern?
Connecting Minecraft and e-Commerce business services

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity

Embedded Rust on IoT devices