Rust on BBC micro:bit

@swissgathu

micro:bit

features

pins layout

architecture

<device schemaVersion="1.1" xmlns:xs="..." >
  <vendor>Nordic Semiconductor</vendor>                           
  <vendorID>Nordic</vendorID>                                     
  <name>nrf51</name>                                             
  <series>nrf51</series>
  <version>522</version>                                          
  <description>nRF51 reference ..</description>
  <licenseText>...</licenseText>

  <addressUnitBits>8</addressUnitBits>                            
  <width>32</width>                                               
  <size>32</size>                                                 
  <resetValue>0x00000000</resetValue> 
  <resetMask>0xFFFFFFFF</resetMask>                        

  <cpu>
    <name>CM0</name>
    <revision>r3p1</revision>                                   
    <endian>little</endian>            
    <mpuPresent>0</mpuPresent>  
....

Rust

Brief Intro

Embedded Rust

Support

  • cross-compilation

  • build customization

Tools

  • rustup

  • cargo & xargo

  • nightly rust

Rust on the micro:bit

setup

$ rustup toolchain install nightly

nightly compiler

$ rustup override set nightly
$ cargo new `awesome-project-name`
$ arm-none-eabi-gdb

ARM Embedded Toolchain

$ arm-none-eabi-ld
$  cat .cargo/config

Cargo configuration

[target.thumbv6m-none-eabi]
runner = 'arm-none-eabi-gdb'
rustflags = [
  "-C", "link-arg=-Tlink.x",
  "-C", "linker=arm-none-eabi-ld",
  "-Z", "linker-flavor=ld",
]

[build]
target = "thumbv6m-none-eabi"
$  cat cortex-m0.json
{
    "arch": "arm",
    "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
    "executables": true,
    "os": "none",
    ...
    "linker-flavor": "gcc",
    "cpu": "cortex-m0",
    "llvm-target": "thumbv6m-none-eabi",
    "features": "+strict-align",
    "relocation-model": "static",
    "no-compiler-rt": true
}

crates

nrf51 & nrf51-hal

Peripheral access API for nRF51 microcontrollers (generated using svd2rust)

microbit

Board support crate for the BBC Micro:bit

Rust on

By Matt Gathu

Rust on

  • 961