- Set up the Development Environment
- Install DFU Tools
- Set Up the Project
- Configure the Build System
- Write the Program
- Build the Project
- Prepare for Flashing
- Flash the Program
- Verify and Debug
- Download and install Rust from https://www.rust-lang.org/tools/install
- Follow the installation prompts, ensuring Rust is added to your system PATH
- Download and install Rust Rover IDE from the JetBrains website
- Open Rust Rover IDE and ensure it recognizes your Rust installation
- Go to https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
- Download the installer for your operating system
- Run the installer, ensuring "Add path to environment variable" is checked
- Open a new command prompt and verify the installation by running:
arm-none-eabi-gcc --version
-
Here's a step-by-step process to download and install this version:
Download the file:
Go to the dfu-util download page (http://dfu-util.sourceforge.net/releases/) Click on "dfu-util-0.11-binaries.tar.xz" to download it
Extract the archive:
You'll need a program that can handle .tar.xz files. 7-Zip is a good free option if you don't already have one. Install 7-Zip if you don't have it (from https://www.7-zip.org/) Right-click on the downloaded .tar.xz file and choose "7-Zip > Extract Here" You may need to extract twice, once for the .tar and once for the resulting folder
Locate the Windows binaries:
In the extracted folder, navigate to the Windows subfolder You should see files like dfu-util.exe, dfu-suffix.exe, etc.
Move the binaries:
Create a new folder in a convenient location, e.g., C:\dfu-util Copy all the .exe files from the extracted folder to this new folder
Add to PATH:
Follow the steps I provided earlier to add C:\dfu-util (or wherever you placed the files) to your system PATH
Verify the installation:
Open a new Command Prompt Type dfu-util --version and press Enter You should see the version information for dfu-util
-
For macOS:
brew install dfu-util
-
For Linux:
sudo apt-get install dfu-util
- Visit https://www.st.com/en/development-tools/stsw-link009.html
- Download the driver package
- Extract the downloaded file and run the installer
- Follow the prompts to complete the installation
- Open Rust Rover IDE
- Go to File > New Project
- Select "Rust" and then "Binary (application)"
- Name your project (e.g., "matek_wing_f405_project") and choose a location
- Click "Create" to generate the project
- Open the Cargo.toml file in your project root
- Replace its contents with:
[package]
name = "matek_wing_f405_project"
version = "0.1.0"
edition = "2021"
[dependencies]
cortex-m = "0.7.7"
cortex-m-rt = "0.7.3"
panic-halt = "0.2.0"
stm32f4xx-hal = { version = "0.15.0", features = ["stm32f405", "rt"] }
[[bin]]
name = "matek_wing_f405_project"
test = false
bench = false
[profile.release]
codegen-units = 1
debug = true
lto = true
- Create a new file named
.cargo/config.toml
in your project root with the following content:
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
rustflags = [
"-C", "link-arg=-Tlink.x",
]
[build]
target = "thumbv7em-none-eabihf"
- Open a terminal in Rust Rover (View > Tool Windows > Terminal)
- Run the following command:
rustup target add thumbv7em-none-eabihf
Replace the contents of src/main.rs with the following program that uses UART to send messages:
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f4xx_hal::{pac, prelude::*, serial::config::Config};
use core::fmt::Write;
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.sysclk(168.MHz()).freeze();
let gpioa = dp.GPIOA.split();
// Setup UART on pins A9 (TX) and A10 (RX)
let tx = gpioa.pa9.into_alternate();
let rx = gpioa.pa10.into_alternate();
let mut serial = dp.USART1.serial(
(tx, rx),
Config::default().baudrate(115200.bps()),
&clocks
).unwrap();
let mut counter = 0;
loop {
writeln!(serial, "Hello, Matek Wing F405 WTE! Count: {}", counter).unwrap();
counter += 1;
cortex_m::asm::delay(168_000_000); // Delay for approximately 1 second at 168MHz
}
}
In the Rust Rover terminal, run:
cargo build --release
After building your project, generate a binary file:
arm-none-eabi-objcopy -O binary target/thumbv7em-none-eabihf/release/matek_wing_f405_project matek_wing_f405_project.bin
Connect the board directly to your computer using a USB cable. Use the USB port on the board labeled "USB" or "BOOT".
- Disconnect the USB cable from the board
- Press and hold the BOOT button on the board
- While holding the BOOT button, reconnect the USB cable
- Release the BOOT button
In a terminal, run:
dfu-util -l
You should see a device listed with "STM32 BOOTLOADER" or similar.
Run the following command:
dfu-util -a 0 -s 0x08000000:leave -D matek_wing_f405_project.bin
This command uploads your binary to the correct address and tells the board to start running the new program after flashing.
-
Connect a USB-to-UART converter to your computer and the Matek Wing F405 WTE board:
- Connect GND of the converter to a GND pin on the board
- Connect the RX of the converter to the TX pin (PA9) on the board
- Connect the TX of the converter to the RX pin (PA10) on the board
-
Open a serial terminal program (like PuTTY, screen, or Arduino IDE's Serial Monitor) on your computer.
-
Configure the serial connection with the following settings:
- Baud rate: 115200
- Data bits: 8
- Stop bits: 1
- Parity: None
- Flow control: None
-
You should see "Hello, Matek Wing F405 WTE! Count: X" messages appearing every second, with X incrementing each time.
-
Install OpenOCD:
- Windows: Download from http://openocd.org/ and add to PATH
- macOS:
brew install openocd
- Linux:
sudo apt-get install openocd
-
Create an OpenOCD configuration file named
openocd.cfg
in your project root:
source [find interface/stlink.cfg]
source [find target/stm32f4x.cfg]
- Start OpenOCD in a terminal:
openocd
- In another terminal, start GDB:
arm-none-eabi-gdb target/thumbv7em-none-eabihf/release/matek_wing_f405_project
- In the GDB prompt, connect to OpenOCD:
target remote :3333
- Use GDB commands to set breakpoints, step through code, and inspect variables
Remember to modify your code in Rust Rover, rebuild, and reflash as needed during the development process. This guide provides a complete setup for developing, flashing, and testing custom firmware on the Matek Wing F405 WTE board using Rust and DFU mode.