Cloning Flight Controllers
To scale production from a single prototype to multiple identical aircraft, we must eliminate the time-consuming and error-prone process of manually calibrating and tuning each flight controller. This guide outlines the definitive, low-level process for creating a Golden Master image from a perfectly tuned flight controller and flashing it as a perfect clone onto new boards.
This ensures that every aircraft produced is a 1:1 replica of the master prototype, capturing not just the firmware, but also all parameters, sensor calibrations (IMU, compass, etc.), and RC setups.
Technical Concept: The "Golden Master"
The flash memory of a flight controller contains two distinct types of data:
- Firmware: The compiled ArduPilot code (
.apjor.hexfile). - User Data: A dedicated memory region that stores all parameters and calibrations.
By using a hardware debugger (ST-Link) and OpenOCD, we can bypass high-level protocols like MAVLink and perform a Raw Memory Dump. This captures the entire 2MB flash (on H743 chips) into a single binary file. Flashing this single file onto an identical board guarantees a bit-for-bit clone.
1. Prerequisites
Before beginning, you must install the necessary communication and debugging tools.
# Update your package list
sudo apt-get update
# Install OpenOCD (The communication bridge)
sudo apt-get install openocd
# Install the ARM toolchain (Required for GDB debugging)
sudo apt-get install gcc-arm-none-eabi gdb-arm-none-eabi
2. Locate Your "Drivers" (Script Discovery)
OpenOCD uses pre-written scripts to understand how to talk to your specific programmer and chip. You don't need to write these; they are installed with OpenOCD.
2.1 Find the Programmer Script
For most flight controllers, we use the ST-Link v2. Find its script:
find /usr/share/openocd/scripts -name "stlink.cfg"
2.2 Find the Chip Script
For the MicoAir 743, we are looking for the STM32H7 target script:
find /usr/share/openocd/scripts -name "stm32h7x.cfg"
3. Forcing Connection (DFU Mode)
Flight controllers running ArduPilot often "lock" the debug pins as soon as they boot to protect the CPU or reuse pins for peripherals. To ensure a stable connection, you must prevent ArduPilot from starting by booting into DFU Mode.
- Unplug the USB and ST-Link from the board.
- Press and HOLD the physical BOOT button on the flight controller.
- While holding the button, plug in the USB cable to your computer.
- Wait 1 second and release the button.
- The board is now in a "Paused" state and ready for a debugger connection.
4. Understanding the Memory Map
To clone a board without guessing, you need the Start Address and the Size.
4.1 The Start Address: 0x08000000
On virtually every STM32 microcontroller, the internal flash memory is hard-wired to start at the address 0x08000000. This is where the Bootloader lives. By starting here, we capture the entire system.
4.2 The Size: How much to read?
You must determine the flash size of your specific chip.
- H743VI: 2MB (2048 KB) -> Hex:
0x200000 - F405RG: 1MB (1024 KB) -> Hex:
0x100000
5. Phase A: Creating the "Golden Master"
Connect your fully tuned and calibrated master aircraft to the ST-Link. We will perform a "Raw Memory Dump."
# Template: dump_image [filename] [start_address] [size]
# This command pulls the full 2MB from the starting address.
openocd -f interface/stlink.cfg -f target/stm32h7x.cfg \
-c "init; halt; dump_image golden_master.bin 0x08000000 0x200000; exit"
6. Phase B: Flashing the Clone
Connect the new, blank flight controller (also in DFU mode). We use the program command which handles erasing, writing, and verification.
CRITICAL NOTE FOR H743: The standard OpenOCD scripts often fail to see the second 1MB bank automatically. You must manually define it in the command line:
# Manual Bank Definition: 0x08100000 is the 1MB offset for Bank 1.
openocd \
-f interface/stlink.cfg \
-f target/stm32h7x.cfg \
-c "flash bank bank1 stm32h7x 0x08100000 0x100000 0 0 stm32h7x.cpu0" \
-c "init; program golden_master.bin verify reset exit 0x08000000"
Once the command finishes with "Verified OK", the new board is a perfect bit-for-bit clone of your master prototype.