yusefkarim / stm32f4-playground

Learning embedded systems with an STM32F4 and Rust!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Learning embedded systems with an STM32F4 and Rust!

This repository is primarily for learning and trying random things. You may find basic code for learning embedded at the register level in without_hal. Eventually, there will be more interesting things using a hardware abstraction library (HAL) in with_hal.

Development Board

Getting started:

These are the high-level steps and requirements you need to run the examples in this repo. Please see app-template for more detail.

Install Cargo related tooling:

cargo install flip-link
cargo install probe-run
cargo install cargo-binutils              # Optional
rustup component add llvm-tools-preview   # Optional

Setup udev rules:

# 1. Create and edit new udev rule file
sudo vim /etc/udev/rules.d/70-st-link.rules

# 2. Add the following four lines
# STM32F3DISCOVERY rev A/B - ST-LINK/V2
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", TAG+="uaccess"
# STM32F3DISCOVERY rev C+ - ST-LINK/V2-1
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", TAG+="uaccess"

# 3. Reload and retrigger your rules
udevadm control --reload
udevadm trigger

Uploading code:

cargo run --bin ${TARGET}
# Or using shortcut (defined in .cargo/config.toml):
cargo rb ${TARGET}

Resources:

Miscellaneous Commands

# Flash a program with OpenOCD, replace ${TARGET_BIN} with your binary
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c "program ${TARGET_BIN} reset exit 0x08000000"
# Create a raw binary from an ELF, replace ${TARGET_ELF} with your compiled Rust code
# ${TARGET_BIN} can be named whatever you like
cargo objcopy --bin ${TARGET_ELF} -- -O binary ${TARGET_BIN}
# Use OpenOCD to erase all flash memory on target board
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c "init; reset halt; stm32f4x mass_erase 0; exit"
# Use semi-hosting to see debug output, requires STlink debugger
openocd -f interface/stlink-v2.cfg -f target/stm32f4x.cfg -c "init; arm semihosting enable"
# Attach to running OpenOCD server via GDB
arm-none-eabi-gdb -q ${TARGET_ELF} -ex "target remote localhost:3333"

About

Learning embedded systems with an STM32F4 and Rust!


Languages

Language:Rust 99.3%Language:RPC 0.7%