The Embedded Working Group Newsletter - 15

This is the fifteenth newsletter of the Embedded WG where we highlight new progress, celebrate cool projects, thank the community, and advertise projects that need help!

Discuss on users.rust-lang.org, on twitter, or on reddit!

If you want to mention something in the next newsletter, send us a pull request!

Embedded at Rust All Hands 2019

Some members of the Embedded Working Group attended the Rust All Hands two weeks ago. There they had the chance to discuss the needs of the embedded community (as identified in this survey) with the different Rust teams and other WGs. Here's a summary of what was discussed:

"const generics"

The ability to parameterize over values, for example you could use this feature to write a fixed capacity Vec : struct Vec<T, const N: usize> { buffer: [T; N], len: usize } . There are a few compiler refactors going on that are required to land this in nightly so the status is "WIP". We'll have future meetings with the compiler team to try to identify and prioritize the parts of the feature that embedded developers need.

const fn with trait bounds on stable.

For example, impl<T> Struct<T> where T: Trait { pub const fn new() -> Self { .. } } . A lengthy pre-RFC discussion has concluded and a proper RFC has been proposed.

core::mem::MaybeUninit on stable.

The plan is to stabilize a minimal, uncontroversial subset of the API to make this available on stable ASAP.

std::io in core / alloc .

It's not possible to move std::io::{Read,Write} into alloc or core because the API depends on OS specific bits (e.g. last_os_error ). An option may be to add a new set of Read / Write traits to core , maybe with associated error types, and then try to bridge these to std::io::{Read,Write} using blanket implementations / super traits, but this needs more research.

This bug breaks no_std builds that use build scripts unless the authors of the build dependencies are aware of the issue and actively work around it. The Cargo team is well aware of the problem. Unfortunately, it's hard to fix and the fix will likely be opt-in because it changes the current semantics.

Stabilize RFC 2282 - "Cargo profile dependencies"

This feature lets you optimize dependencies when using the dev profile; useful to keep dev binaries small enough to fit in Flash without sacrificing all debuggability. A new build profile will be added to cover the configuration of proc macros, build scripts, compiler plugins and their dependencies. The new profile solves the remaining unresolved question around RFC 2282.

Stabilize core::arch::arm

This module contains functions for instructions like wfi and nop , and SIMD instructions; stabilizing this removes the pressure for stable inline assembly ( asm! ). A member of the libs team is interested in this and will help us push it towards the finish line. A PR in this space has recently landed.

Asserts in const fn context become compiler errors.

We understood that there are still several design / implementation issues that need to be discussed before this is stabilized, but in the meantime you can use the perma-unstable -Z unleash-the-miri-inside-of-you flag to do all sort of stuff in const context.

std-aware Cargo.

@jamesmunns has written a pre-rfc for an incremental implementation of this feature based on our discussions with people from the libs and Cargo teams and the WASM WG.

Improve searching for no_std crates on crates.io.

The backend supports searching within a category (like the no_std category) but there's no UI for it right now. This and fixing a bug where searches only return items found until a exact match was found (instead of returning all relevant matches) are in the crates.io team TODO list.

Fix: infinite loops (e.g. loop {} ) are lowered to an abort instruction.

Ideally, this should be fixed in LLVM proper but it's hard to fix. It's possible to fix this in rustc but the fix is likely to regress the performance of loop s. The compiler team will follow up with two unstable flags to evaluate the (performance) impact of fixing this. The first flag applies the fix to only loop s in return position of divergent function and the second flag applies the fix to all loop s.

Math support in core

That is 0f32.sin() should "Just Work" in no_std crates. There are a few questions about how to best implement this without degrading performance of applications that link to std (we want those to use the arch optimized routines in e.g. glibc's libm instead of the generic Rust implementation) and we need a champion to do the research.

Cargo build hooks

This refers to the ability to run custom code after cargo build . We covered use cases, their requirements and discussed the trade-offs of a more general Cargo tasks (e.g. cargo $task ) mechanism vs a more targeted post-build script (e.g. post-build.rs ) mechanism. Expect more news (a (pre-)RFC) from the WASM WG on this front.

Slimmer core::fmt .

The current implementation of core::fmt uses trait objects and function pointers to make all uses of core::fmt fast to compile but this makes core::fmt impossible to inline which makes no_std programs that use formatting large in (binary) size. It might be possible to leverage std-aware Cargo to fix this: we could add a Cargo feature to core to replace the current implementation with one that's fully inlineable but as featureful as the current one -- this should produce smaller binaries.

For a bit more of detail you can check the logs and minutes from two meetings ago; they include our notes from the All Hands

Highlights

The Embedded WG has started receiving submissions for the embedded showcase! We are looking for cool embedded Rust projects with visuals (pictures or videos) that can serve as examples of what can be done in Rust.

The stm32-rs organization has emerged to collate work on STM32 crates.

Similarly, the lpc-rs organization has emerged to work on LPC microcontrollers by NXP.

Also, the nrf-rs organization has emerged to focus on the nRF family of microcontrollers by Nordic Semiconductors.

@adamgreig has released an experimental PAC (Peripheral Access Crate) alternative for STM32 microcontrollers: stm32ral that compiles in about 3 seconds. (PACs are known for compile times in the order of hundreds of seconds.)

As of nightly-2019-02-05 the embedded Rust Book is included as part of the docs shipped with the Rust toolchain! This is the online version.

The Rust compiler now has cross compilation support for 64-bit RISCV. Install the bare metal targets with rustup target (see rustup target list ).

The Rust compiler also gained compilation support for x86_64 UEFI in the form of the x86_64-unknown-uefi target.

Formatting numbers with core::fmt has become slimmer. Some users have reported binary size reductions of up to 26% (800B) in ARMv6-M binaries.

The copterust org has shared a bunch of driver crates for interfacing sensors commonly found in flight controllers (drones).

Embedded Projects

If you have an embedded project or blog post you would like to have featured in the Embedded WG Newsletter, make sure to add it to the next newsletter, we would love to show it off!

Version v0.4.1 of Real Time For the Masses (RTFM), a concurrency framework for building real time systems, has been released! This version fixes a soundness hole and includes a Russian translation of the RTFM book.

@jamwaffles has published a driver crate for the SH1106, an OLED display, and an introduction blog post for their crate.

@thejpster has released embedded-sdmmc , a pure-Rust #[no_std] SD card and FAT16/FAT32 library

@hannobraun has published two crates: ieee802154 , a partial implementation of the IEEE 802.15.4 standard, and dw1000 , an embedded-hal driver for the Decawave DW1000 wireless transceiver chip.

embedded-hal Ecosystem Crates