This example showcases how the tb6612fng crate for the SparkFun Motor Driver - Dual TB6612FNG (1A) can be used on an STM32F4 chip. It uses RTIC (Real-Time Interrupt-driven Concurrency) underneath.
The example logs messages using defmt
.
The example has been tested on a ST Nucleo-F401RE development board but should work on any STM32F4xx family microcontroller as long as the controller is connected on the following pins (or the code adapted accordingly):
AI1
onPB5
AI2
onPB4
PWMA
onPB10
Don't forget to pull the STBY
pin high, otherwise nothing will happen!
Furthermore, the example uses a button connected on PC13
which is e.g. present on the mentioned board.
The example continuously cycles through all speeds from full backwards to full forward (in 1% steps) and the button can be used to stop (coast, first press), actively brake (second press) and drive again (third press).
- Optional: ensure that the rust toolchain is up-to-date:
rustup update
- Install
probe-rs
:cargo install probe-rs --features cli
- Install
flip-link
:cargo install flip-link
- Note:
flip-link
is not strictly necessary for this example (it doesn't need stack protection), however it can be considered best practices to include it.
- Note:
- Install the cross-compile target:
rustup target add thumbv7em-none-eabihf
- Optional: install the LLVM tools:
rustup component add llvm-tools-preview
- Install the STLink drivers
- Connect the board via USB
- Run
cargo run
(the correct chip & target is already defined inCargo.toml
and.cargo/config
) - Enjoy your running program :)