.cargo | ||
src | ||
.gitignore | ||
build.rs | ||
Cargo.toml | ||
memory.x | ||
openocd.cfg | ||
openocd.gdb | ||
README.md |
TinFOC: a Rust-y Field-Oriented Control crate for STM32 MCUs
A crate that provides an FOC motor controller using STM32 Cortex microcontrollers.
Dependencies
The MCU I'm using is the STM32F302R8, and I'm using the [X-Nuclean IHM07M1] BLDC motor controller shield board that provides the actual power to the motor.
This requires the thumbv7em-none-eabihf
Rust target:
rustup target add thumbv7em-none-eabihf
In order to connect to the microcontroller with a debugger (say, to load the program) on Ubuntu linux, you'll need to:
sudo apt install openocd gdb-multiarch
Running on hardware
Assuming you've plugged your board into your computer via USB:
- build TinFOC with
cargo build
- connect to the board with
openocd &
- start gdb:
gdb-multiarch -q target/thumbv7em-none-eabihf/debug/tinfoc
- inside gdb, attach to openocd:
target remote :3333
- inside gdb, load the program into the MCU's flash:
load
Assuming that was successful, you can then enter continue
in the gdb console, which will run the
program on the hardware; you should see the LD2
LED start blinking green, on and off, every 2
seconds. If you disconnect the board from power and then reconnect, it will automatically run the
program.
There are no doubt other ways to flash the board, and I'll update here when I adjust my flow; I'm a newb when it comes to this stuff.