# TinFOC: a Rust-y Field-Oriented Control crate for STM32 MCUs A crate that provides an [FOC](https://www.st.com/en/applications/industrial-motor-control/3-phase-field-oriented-control-foc.html) motor controller using STM32 Cortex microcontrollers. ## Dependencies The MCU I'm using is the [STM32F302R8](https://www.st.com/en/microcontrollers-microprocessors/stm32f302r8.html), and I'm using the [X-Nucleo IHM07M1](https://www.st.com/en/ecosystems/x-nucleo-ihm07m1.html) BLDC motor controller shield board that provides the actual power to the motor. This requires the `thumbv7em-none-eabihf` Rust target: ``` console 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: ``` console sudo apt install openocd gdb-multiarch ``` ## Running on hardware Assuming you've plugged your board into your computer via USB: 1. build TinFOC with `cargo build` 2. connect to the board with `openocd &` 3. start gdb: `gdb-multiarch -q target/thumbv7em-none-eabihf/debug/tinfoc` 4. inside gdb, attach to openocd: `target remote :3333` 5. 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.