Embedded Rust, by example of RIOT-OS applications Christian M. Ams - - PowerPoint PPT Presentation

embedded rust by example of riot os applications
SMART_READER_LITE
LIVE PREVIEW

Embedded Rust, by example of RIOT-OS applications Christian M. Ams - - PowerPoint PPT Presentation

Embedded Rust, by example of RIOT-OS applications Christian M. Ams uss <ca@etonomy.org> 2018-11-27 Embedded Devices 10kB 1MB ROM 1kB 100kB RAM Typical hardware: ARM Cortex-M3, eg. STM32 Embedded Devices


slide-1
SLIDE 1

Embedded Rust, by example of RIOT-OS applications

Christian M. Ams¨ uss <ca@etonomy.org> 2018-11-27

slide-2
SLIDE 2

Embedded Devices

◮ 10kB – 1MB ROM ◮ 1kB – 100kB RAM ◮ Typical hardware: ARM Cortex-M3, eg. STM32

slide-3
SLIDE 3

Embedded Devices

◮ allocation: static or on stack ◮ Someone needs to initialize the RAM ◮ CPU specific linker scripts ◮ Software shipped via hardware debugger or using a bootloader

slide-4
SLIDE 4

Embedded Devices: On-board peripherals

◮ Clock(s) ◮ UARTs (eg. console) ◮ GPIO pins (eg. LEDs, buttons) ◮ SPI (eg. to access SD cards) need to be set up, need drivers / file systems

slide-5
SLIDE 5

Why Rust?

slide-6
SLIDE 6

Why not?

slide-7
SLIDE 7

Why Rust: My personal selection

◮ Fearless development ◮ Reusing code throughout the infrastructure

slide-8
SLIDE 8

no std

slide-9
SLIDE 9

Options 1a: Bare metal

◮ cortex-m-rt ◮ peripherals wrapped from svd2rust (eg. stm32f30x) ◮ device drivers (eg. stm32f30x-hal) ◮ board support crate (eg. f3) See f3 crate for examples

slide-10
SLIDE 10

Options 1b: RTFM

“Real-Time For The Masses” ◮ cortex-m-rtfm ◮ peripherals ◮ device drivers ◮ board support crate More descriptive knowledge, fewer mutexes

slide-11
SLIDE 11

Options 2: Full Rust operating system

Tock ◮ Operating system written in Rust ◮ Trusted (cooperative) and untrusted (preemtive) processes ◮ Network stack is WIP ◮ Limited hardware support

slide-12
SLIDE 12

Options 3: RIOT-OS

◮ Operating system written in C ◮ Trusted processes (cooperative or preemtive) ◮ Mature network stack ◮ Large community ◮ Good hardware support

slide-13
SLIDE 13

Which to pick?

slide-14
SLIDE 14

Does it matter?

slide-15
SLIDE 15

Abstractions

slide-16
SLIDE 16

embedded-hal

slide-17
SLIDE 17

embeded-hal traits

◮ GPIO ◮ SPI ◮ ADC ◮ I2C ◮ UART ◮ delays ◮ . . . covers usage, not initialization

slide-18
SLIDE 18

embedded-hal driver example: ENC28J60

impl<E , SPI , NCS, INT , RESET> Enc28j60 <... > where SPI : s p i : : Transfer <u8 , Error=E> + . . . , NCS: OutputPin , INT : I n t P i n + InputPin , RESET: ResetPin , { . . . }

slide-19
SLIDE 19

Traits in general

slide-20
SLIDE 20

Emulating a different network stack

impl <’a> j n e t : : Resize f o r &’a mut r i o t s y s : : Pktsnip<Writable > { fn truncate (&mut s e l f , l e n : u16 ) { s e l f . r e a l l o c d a t a ( l e n as u s i z e ) . unwrap ( ) ; } } Translation at build time; no runtime overhead if concepts align

slide-21
SLIDE 21

RIOT Operating System

https://riot-os.org

slide-22
SLIDE 22

Recap: RIOT-OS

◮ Operating system written in C ◮ Trusted processes (cooperative or preemtive) ◮ Mature network stack ◮ Large community ◮ Good hardware support

slide-23
SLIDE 23

riot-sys bindgen many unsafe functions and raw pointers

slide-24
SLIDE 24

riot-wrappers safe wrappers Mutext, RwLock: like in std::sync embedded-hal implementations

slide-25
SLIDE 25

Examples

slide-26
SLIDE 26

Recap

◮ What are embedded devices? ◮ Bare metal development is possible ◮ Choice of operating systems ◮ embedded-hal & co (Embedded Rust WG) ◮ RIOT Operating System ◮ riot-sys and riot-wrappers ◮ Go try it!

slide-27
SLIDE 27

Questions?

slide-28
SLIDE 28

Thanks for your attention Slides and more links on http://christian.amsuess.com/presentations/2018/embedded-rust-riot/