Skip to content

Language

Currency

Flashing Firmware Step by Step: This Time, for a UAV

by AMOVLAB 04 Jul 2025 0 Comments

For developers who want to truly understand the principles of flight controllers and make their own flight controllers. This guide will be based on the STM32H743 development board, using the fewest steps and the most straightforward language to take you step by step through the entire process of flight controller transplantation.

What are the benefits of learning to transplant?

  • The development board has open hardware and clear structure

  • Very suitable for beginners to learn PX4 structure

  • Lay the foundation for making your own customized flight controller board in the future.

  • More suitable for scientific research or commercial self-research projects

01 Preliminary preparation

hardware: stlink*1, stm32h743 development board*1 PX4 source code version selection:PX4 official code (v1.15.4)



Understand the basic principles of flight controller

The essence of flight controller startup is the process of transferring hardware resources layer by layer. After the bootloader completes the lowest-level initialization, it hands over control to NuttX; after NuttX establishes the operating system environment, the flight controller firmware finally takes over the hardware peripherals.



02 Analysis of key migration files

Bootloader related files

bootloader script and configuration
nuttx-config/bootloader/defconfig: Configure the underlying resources that need to be called in the bootloader, such as the most basic USB driver, TIM timer driver, system console driver, etc.
bootloader.px4board: Configure which source code is compiled into the bootloader. Generally, no modification is required.

flight controller firmware core file

Hardware abstraction layer configuration/peripheral driver module

  • default.px4board: Configure the mapping of each serial port and configure which source code is compiled into the flight controller firmware.

  • board_config.h: Defines some parameter configurations of hardware peripheral interface, pin mapping, power management and initialization logic hardware.

  • bootloader_main.c: The main function of bootloader (the bootloader is dedicated to the early startup code of fmu).

  • can.c: CAN bus initialization and registration configuration driver.

  • hw_config.h: The core configuration of PX4 Bootloader interacting with hardware to ensure reliable startup and upgrade of flight controller on different hardware platforms.

  • i2c.cpp: The I2C bus management module of the PX4flight controller system realizes the I2C bus initialization configuration and internal and external classification of the device.

  • init.c: The board-level initialization entrance of the PX4 flight controller system, which is responsible for completing the early stages of NuttX startup: hardware peripheral reset and power management, basic hardware initialization, key subsystem startup, and fail-safe mechanisms.

  • led.c: LED driver module of the PX4 flight controller system, responsible for managing the initialization, control logic and status indication of the hardware onboard LED.

  • manifest.c: The hardware inventory management module of the PX4flight controller system achieves compatibility support for multiple hardware variants by dynamically matching hardware versions and component configurations.

  • mtd.cpp: The storage device management list of the flight controller system, used to define the partition structure and access method of non-volatile storage media (such as FRAM, EEPROM) on the flight controller board.

  • sdio.c: The SD card driver module of the PX4 flight controller system is responsible for managing the initialization and mounting detection of the hardware onboard SD.

  • spi.cpp: The SPI bus management module of the PX4flight controller system realizes the SPI bus initialization configuration on different versions of hardware.

  • timer_config.cpp: PX4 flight controller system timer configuration module to realize the mapping of processor pwm pins.

  • usb.c: USB initialization of PX4flight controller system.

  • rc.board_defaults: Settings of flight controller default parameters.

  • rc.board_sensors:flight controller sensor startup configuration.

  • firmware.prototype: Modify the flight controller board ID, name and flash memory size.

NuttX operating system configuration file

  • board_dma_map.h: Defines the DMA channel allocation strategy. DMA is used to provide high-speed data transfer between peripherals and memory or between memory and memory.

  • board.h: Configure clocks and pins in the NuttX operating system, io definitions of various interfaces, and modify them according to the actual definitions of the hardware.

  • nsh/defconfig: The underlying resources that need to be called in the flight controller firmware, such as command line interaction, multi-peripheral drivers, file storage, serial port drivers, SPI drivers, I2C drivers, etc.

  • script.ld: Link script used to allocate flight controller firmware memory address and size.

  • bootloader_script.ld: Link script used to allocate bootloader memory address and size.

03 Migration steps

Hardware pin planning

Since our development board chose STM32H743, we referred to the MicroAir743flight controller for pin planning, and subsequent transplantation pin definitions were based on this plan.
geek_h743pinout file: https://kdocs.cn/l/cvr7JHhjfoAm

Create migration directory

exist /PX4-Autopilot/boards Create a new geek/h743 folder in the directory, and copy the contents of the micoair/h743 file to the newly created folder. Subsequent modifications will be based on the contents of this file.

Configuration file analysis and modification

board.h: Since the external crystal oscillator of this development board is 25MHZ, which is different from MicroAir, it needs to be modified. For modification content, please refer to the source code at the end of the article.
board_dma_map.h: Serial port and spi interface DMA configuration can be turned on or off by yourself.
default.px4board: Modify the serial port mapping relationship according to your own needs, and select other compilation directions according to your needs.
firmware.prototype: Modify board_id, magic, description, summary, etc. according to your own needs.
Change all the files under src one by one and modify them as needed. Refer to the source code provided at the end of the article.

board_config.h
1. System status display
LED control:
#define GPIO_nLED_BLUE       /* PE12 */  (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN12)
Buzzer pin configuration:
#define GPIO_TONE_ALARM         GPIO_TIM2_CH1OUT_2
2. Analog signal acquisition (ADC)
Battery monitoring:
#define ADC_BATTERY_CURRENT_CHANNEL    /* PA4 */  ADC1_CH(18)
#define ADC_BATTERY_VOLTAGE_CHANNEL            /* PB1 */  ADC1_CH(5)
3. Number of PWM channels
#define DIRECT_PWM_OUTPUT_CHANNELS   6
4. Power-control pin configuration
#define GPIO_nPOWER_IN_C                /* PE15  */ (GPIO_INPUT|GPIO_PULLUP|GPIO_PORTE|GPIO_PIN15)
#define GPIO_nVDD_USB_VALID             GPIO_nPOWER_IN_C /* USB     Is Chosen */
5. USB VBUS pin configuration
#define GPIO_OTGFS_VBUS         /* PA8 */ (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_100MHz|GPIO_PORTA|GPIO_PIN8)
6. Receiver port configuration
#define RC_SERIAL_PORT          "/dev/ttyS3"
#define BOARD_SUPPORTS_RC_SERIAL_PORT_OUTPUT
7. STDIO/USB/SPI initialization and reset:
int stm32_sdio_initialize(void);
extern void stm32_spiinitialize(void);
extern void stm32_usbinitialize(void);
extern void board_peripheral_reset(int ms);

Compilation process

implement:make geek_h743_bootloader Generate bootloader firmware and store it in extras below the folder.
implement:make geek_h743_default Generate flight controller firmware and store it in build directory.

04 Functional verification

Firmware burning method

bootloader programming: Connect stlink to the development board and use STM32CubeProgrammer or ST-LINK Utility software to program firmware.



PX4 firmware burning: Use qgcground control station to program flight controller firmware.



QGCground control station connection test

After the firmware is programmed, connect to the QGCground control station and enter the QGC terminal to view the flight controller firmware version, etc.



Resource Express

Click to read the full text to get the source code: https://github.com/amovlgf/PX4-Autopilot/tree/geek\_h743\?sessionid=1496494836

If there are any mistakes, please correct me and I will continue to introduce them to you in the future.Basic peripherals(IMU/sd/baro/GPS/flow/flsah, etc.) addition and debugging, so stay tuned.

Leave a comment

All blog comments are checked prior to publishing

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Recently Viewed

Edit Option
Back In Stock Notification
Terms & Conditions
What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
this is just a warning
Login
Shopping Cart
0 items