embedded rust by example of riot os applications
play

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


  1. Embedded Rust, by example of RIOT-OS applications Christian M. Ams¨ uss <ca@etonomy.org> 2018-11-27

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

  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

  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

  5. Why Rust?

  6. Why not?

  7. Why Rust: My personal selection ◮ Fearless development ◮ Reusing code throughout the infrastructure

  8. no std

  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

  10. Options 1b: RTFM “Real-Time For The Masses” ◮ cortex-m-rtfm ◮ peripherals ◮ device drivers ◮ board support crate More descriptive knowledge, fewer mutexes

  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

  12. Options 3: RIOT-OS ◮ Operating system written in C ◮ Trusted processes (cooperative or preemtive) ◮ Mature network stack ◮ Large community ◮ Good hardware support

  13. Which to pick?

  14. Does it matter?

  15. Abstractions

  16. embedded-hal

  17. embeded-hal traits ◮ GPIO ◮ SPI ◮ ADC ◮ I2C ◮ UART ◮ delays ◮ . . . covers usage, not initialization

  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 , { . . . }

  19. Traits in general

  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

  21. RIOT Operating System https://riot-os.org

  22. Recap: RIOT-OS ◮ Operating system written in C ◮ Trusted processes (cooperative or preemtive) ◮ Mature network stack ◮ Large community ◮ Good hardware support

  23. riot-sys bindgen many unsafe functions and raw pointers

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

  25. Examples

  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!

  27. Questions?

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

Recommend


More recommend