A Tale Of Rust, The ESP32 And IoT

2y ago
135 Views
5 Downloads
3.51 MB
37 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Carlos Cepeda
Transcription

A tale of Rust,the ESP32 and IoTIt can‘t be that hard

Who am I?Jens Reimann Principal Software Engineer Red Hat Middleware, Messaging, IoT Programming languages 90s: Basic, Pascal, C 00s: C, C , Java 10s: Java, Go, Rust@ctronhttps://dentrassi.de

Telemetry data for Eclipse Hono

Goal of this talk?Get you excited about Rust!

Why Rust?Do we really need another programming language?

Rust"A language empowering everyone tobuild reliable and efficient software."https://www.rust-lang.org/

Rust“Rust is a language for systems programming.”Jim Blandy & Jason Orendorff, Programming Rust“Systems programming is for: Code that runs in very cheap devices, or devices that must beextremely reliable ”

Rust is “A safe, concurrent language with the performance of Cand C ”Jim Blandy & Jason Orendorff, Programming Rust“ eliminate many classes of bugs at compile-time.”https://www.rust-lang.org/

History of html

History of Rust Started 2006 by Mozilla employee Graydon Hoare Announced 2010 by the Mozilla Foundation Self-compiled 2011 Getting things right, before moving on A community to grow the language, not only use it

“Rust was the third-most-lovedprogramming language in the 2015Stack Overflow annual survey, and tookfirst place in 2016, 2017, 2018, and2019.” – Wikipedia

Fixing stuff at compile time Have a compiler which understands your code Have language rules which prevent bugs Eliminate “undefined behavior” Reduce “unexpected behavior”

What is undefined behavior?Undefined behavior: behavior, upon use of a nonportable orerroneous program construct or of erroneous data, for which thisInternational Standard imposes no requirements§3.4.3, Cx11Undefined behavior: Renders the entire program meaningless ifcertain rules of the language are violated.cppreference.com

Undefined / unexpected behaviorGo FAQJava „CME“ - HashSetQ: „Why are map operations notdefined to be atomic? ““Fail-fast iterators throwConcurrentModificationException ona best-effort basis. Therefore, itwould be wrong to write a programthat depended on this exception forits correctness: the fail-fast behaviorof iterators should be used only todetect bugs.”A: „ This was not an easy decision,however, since it means uncontrolledmap access can crash theprogram. “

A helping compiler CodeOutputfn main() {Compiling playground v0.0.1 (/playground)error[E0597]: s2 does not live long enough-- src/main.rs:8:13 8 x &mut s2; borrowed value does not live long enough9 } - s2 dropped here while still borrowed10 assert eq!(*x, "Bar"); ---------------------- borrow later used here note: this error originates in a macro outside of the current crate (inNightly builds, run with -Z external-macro-backtrace for more info)let mut s1 "Foo";let mut x &mut s1;assert eq!(*x, "Foo");{let mut s2 "Bar";x &mut s2;}error: aborting due to previous errorassert eq!(*x, "Bar");}For more information about this error, try rustc --explain E0597 .error: Could not compile playground .To learn more, run the command again with --verbose.https://play.rust-lang.org/?version stable&mode debug&edition 2018&gist cc5f9c6bbb709ac1c0e292b3042a4b40

The cost of a bug over time Bugs1009080706050403020100CompileTestReleaseBugs

with gs

Dependencies “Crates” are the “JAR files ofRust” but contain code, notbinaries! Then “crates.io” is “MavenCentral for Rust” “cargo” managesdependencies, andorchestrates the buildand testMy Appfoobarstdbazlibbaz.sobaz.dll

The problem with „std“ „std“ provides all kinds of functionality Files, Streams, Network, Sockets, But also requires a POSIX-like operating system So, what about embedded systems? Like the ESP32?

#![no std], “core” & “alloc” You can disable the usage of “std” and switch to “core” instead If you can provide an allocator, you can also use “alloc” fordynamic memory allocations (like String, Vec, ) Some crates support this by using “features”, whichenable/disable features of the crate at compile time e.g. “serde” with std

Unsafe Superpowers How? “unsafe {}” block“unsafe” keywordWhy? Call other „unsafe“ methodsDereference raw pointers

ESP-IDF & RustMy Appserde / JSONRustcoreC – ESP IDF /IPWiFi

End-to-end examplehttps://github.com/ctron/rust-esp32-hono

End-to-end example

IDE Integration

Eclipse Corrosion

IntelliJ Rust

One more thing

How to compile for the Xtensaarchitecture?

Forked LLVM, forked rustc and a bunch ofscripts Execute 50 different commands Hope you have the right OS, in the right version, with the rightpackages Wait 3½ hours Enjoy or try again

Containerized docker run quay.io/ctron/rust-esp –ti –v PWD:/home/project Runs on Windows, Linux, (and should on Mac OS)

What lies ahead? Rust Runtime for AWS Lambda me-for-awslambda/ Rust Embedded Book https://rust-embedded.github.io/book/ Linux kernel experiments with Rust https://lwn.net/Articles/797828/ Microsoft tive-approachto-more-secure-code/ „ 70% of the vulnerabilities Microsoft assigns a CVE eachyear continue to be memory safety issues”

Questions? and answers!

A few links Rust https://www.rust-lang.org/ Rust Embedded Book https://rustembedded.github.io/book/ Programming Rust O'Reilly Media Eclipse Corrosion rustedition-eclipse-ide Rust for ESP32 https://github.com/ctron/rustesp-container/ Rust, ESP32, ESP-IDF, Hono https://github.com/ctron/rustesp32-hono LLVM for Xtensa https://github.com/espressif/llvm-xtensa Rust fork for Xtensa https://github.com/MabezDev/rust-xtensa

Thank you!

Rust “Rust is a language for systems programming.” Jim Blandy & Jason Orendorff, Programming Rust “Systems programming is for: Code

Related Documents:

May 02, 2018 · D. Program Evaluation ͟The organization has provided a description of the framework for how each program will be evaluated. The framework should include all the elements below: ͟The evaluation methods are cost-effective for the organization ͟Quantitative and qualitative data is being collected (at Basics tier, data collection must have begun)

Silat is a combative art of self-defense and survival rooted from Matay archipelago. It was traced at thé early of Langkasuka Kingdom (2nd century CE) till thé reign of Melaka (Malaysia) Sultanate era (13th century). Silat has now evolved to become part of social culture and tradition with thé appearance of a fine physical and spiritual .

On an exceptional basis, Member States may request UNESCO to provide thé candidates with access to thé platform so they can complète thé form by themselves. Thèse requests must be addressed to esd rize unesco. or by 15 A ril 2021 UNESCO will provide thé nomineewith accessto thé platform via their émail address.

̶The leading indicator of employee engagement is based on the quality of the relationship between employee and supervisor Empower your managers! ̶Help them understand the impact on the organization ̶Share important changes, plan options, tasks, and deadlines ̶Provide key messages and talking points ̶Prepare them to answer employee questions

Dr. Sunita Bharatwal** Dr. Pawan Garga*** Abstract Customer satisfaction is derived from thè functionalities and values, a product or Service can provide. The current study aims to segregate thè dimensions of ordine Service quality and gather insights on its impact on web shopping. The trends of purchases have

*The Tale of Benjamin Bunny *The Tale of Mrs. Tiggy-Winkle *The Tale of Mr. Jeremy Fisher *The Tale of Jemima Puddle-Duck *The Tale of the Flopsy Bunnies *The Tale of Two Bad Mice *The Tale of Timmy Tiptoes *The Tale of Mr. Tod *The Tale of Pigling Bland *The Roly Poly Pudding *The Pie and the Patty-pan *Ginger and Pickles *The Story of Miss Moppet

Chính Văn.- Còn đức Thế tôn thì tuệ giác cực kỳ trong sạch 8: hiện hành bất nhị 9, đạt đến vô tướng 10, đứng vào chỗ đứng của các đức Thế tôn 11, thể hiện tính bình đẳng của các Ngài, đến chỗ không còn chướng ngại 12, giáo pháp không thể khuynh đảo, tâm thức không bị cản trở, cái được

Altitude, rainfall and harvest effects on the coffee rust progress curve Avelino et al., 2002, modificado de Avelino et al., 1990 (Chiapas, México) e f leaves th rust Time Month/year l) Harvest period 460 m 730 m 1100 m More rust at low altitude More rainfall does not necessarily mean more rust (spore washing) Coffee rust peak at the end of the