Skip to content

These are the supporting files for the Doulos Web-seminar on the Embedded Rust Toolchain

License

Notifications You must be signed in to change notification settings

Doulos/embedded_rust_toolchain_webseminar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

1. General Environment Setup with rustup [Directory 1]
========================================

rust show

rustup update

2. The Rust Compiler
===================

rustup target list

rustup target add thumbv6m-none-eabi

rustup target add thumbv7m-none-eabi

rustup target add thumbv7em-none-eabihf

3. Cross-Compilation with cargo
===============================

cd 1

tree

tree -.

cargo build --target thumbv7m-none-eabi

ls target/thumbv7m-none-eabi/debug

cargo build --release --target thumbv7m-none-eabi

ls target/thumbv7m-none-eabi/

4. Beyond cargo build: binutils
===============================

cargo install cargo-binutils

rustup component add llvm-tools

cargo size --release --target thumbv7m-none-eabi

cargo nm --release --target thumbv7m-none-eabi

cargo objdump --release --target thumbv7m-none-eabi --bin app -- -d --no-show-raw-insn --demangle

5. Emulation
============

qemu-system-arm -M help

qemu-system-arm -cpu cortex-m3 -machine stm32vldiscovery -nographic -kernel target/thumbv7m-none-eabi/debug/app -semihosting-config enable=on,target=native

6. Flash the Device [Directory 2]
===================

cargo build

arm-none-eabi-objcopy -O binary \
      target/thumbv7m-none-eabi/debug/app \
      app.bin
      
st-flash erase
st-flash write app.bin 0x0800000

openocd \
  -f interface/stlink.cfg \
  -f target/stm32f1x.cfg \
  -c "adapter speed 4000" \
  -c "program target/thumbv7m-none-eabi/debug/app verify reset exit"
  
minicom -D /dev/ttyUSB0 (or picocom -b 115200 -d 8 -p 1 /dev/ttyUSB0)

7. Cargo runners
================

bat .cargo/config.toml
	Notice the entry: gdb-multiarch -q target/thumbv7m-none-eabi/debug/app -x openocd.gdb

bat openocd.gdb

openocd -f interface/stlink.cfg -f target/stm32f1x.cfg

Ctrl+T N

cargo run

(gdb)
break main.rs:
continue

8. Cargo generate [Directory 3]
=================

ls

cargo generate --git https://github.com/burrbull/stm32-template/
project: app
device: STM32F103C8T6
HAL: latest
RTIC: no
dfmt: no
SVD: no

cd app

#![deny(unsafe_code)]
#![no_std]
#![no_main]

use nb::block;
use panic_halt as _;
use rtt_target::{rprintln, rtt_init_print};

use cortex_m_rt::entry;
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};

#[entry]
fn main() -> ! {
    // Initialise RTT
    rtt_init_print!();
    rprintln!("Blinky application starting");

    // Get access to the core peripherals from the cortex-m crate
    let (cp, dp) = (
        cortex_m::Peripherals::take().unwrap(),
        pac::Peripherals::take().unwrap(),
    );

    let mut rcc = dp.RCC.constrain();

    // Acquire the GPIOB peripheral
    let mut gpiob = dp.GPIOB.split(&mut rcc);

    // Configure gpio C pin 13 as a push-pull output
    let mut led = gpiob.pb9.into_push_pull_output(&mut gpiob.crh);

    // Configure the syst timer to trigger an update every second
    let mut timer = Timer::syst(cp.SYST, &rcc.clocks).counter_hz();
    timer.start(1.Hz()).unwrap();

    // Set initial LED state
    led.set_high();

    // Wait for the timer to trigger an update and change the state of the LED
    loop {
        block!(timer.wait()).unwrap();
        led.toggle();
    }
}

9. Running with Cargo Embed
===========================

nvim Embed.toml
	RTT enable

bat .cargo/config.toml

cargo run

cargo add rtt-target

cargo run

About

These are the supporting files for the Doulos Web-seminar on the Embedded Rust Toolchain

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published