为了将基于 Nuttx 的 PX4 移植到新的硬件平台上，Nuttx 必须支持该硬件平台。 NuttX 项目中维护着一个出色的 移植指南 (opens new window) 可以帮助你实现将 Nuttx 移植到一个新的计算平台上。
The following guide assumes you are using an already supported hardware target or have ported NuttX (including the PX4 base layer (opens new window)) already.
The configuration files for all boards, including linker scripts and other required settings, are located under /boards (opens new window) in a vendor- and board-specific directory (i.e. boards/VENDOR/MODEL/)).
The following example uses FMUv5 as it is a recent reference configuration for NuttX based flight controllers:
make px4_fmu-v5_defaultfrom the PX4-Autopilot directory will build the FMUv5 config
- The base FMUv5 configuration files are located in: /boards/px4/fmu-v5 (opens new window).
- Board specific header (NuttX pins and clock configuration): /boards/px4/fmu-v5/nuttx-config/include/board.h (opens new window).
- Board specific header (PX4 configuration): /boards/px4/fmu-v5/src/board_config.h (opens new window).
- NuttX OS config (created with NuttX menuconfig): /boards/px4/fmu-v5/nuttx-config/nsh/defconfig (opens new window).
- Build configuration: boards/px4/fmu-v5/default.px4board (opens new window).
# NuttX Menuconfig Setup
To modify the NuttX OS configuration, you can use menuconfig (opens new window) using the PX4 shortcuts:
make px4_fmu-v5_default menuconfig make px4_fmu-v5_default qconfig
The following steps are not required if using the px4-dev-nuttx (opens new window) docker container or have installed to macOS using our normal instructions (as these include
Run the following commands from any directory:
git clone https://bitbucket.org/nuttx/tools.git cd tools/kconfig-frontends sudo apt install gperf ./configure --enable-mconf --disable-nconf --disable-gconf --enable-qconf --prefix=/usr make sudo make install
--prefix=/usr determines the specific installation location (which must be in the
PATH environment variable). The
--enable-qconf options will enable the
qconfig options respectively.
qconfig you may need to install additional Qt dependencies.
First you will need a bootloader, which depends on the hardware target:
- STM32H7: the bootloader is based on NuttX, and is included in the PX4 Firmware. See here (opens new window) for an example.
- For all other targets, https://github.com/PX4/Bootloader is used. See here (opens new window) for an example how to add a new target. Then checkout the building and flashing instructions.
# Firmware Porting Steps
- Make sure you have a working development setup and installed the NuttX menuconfig tool (see above).
- Download the source code and make sure you can build an existing target:
git clone --recursive https://github.com/PX4/PX4-Autopilot.git cd PX4-Autopilot make px4_fmu-v5
- Find an existing target that uses the same (or a closely related) CPU type and copy it. For example for STM32F7:Change manufacturer to the manufacturer name and my-target-v1 to your board name.
mkdir boards/manufacturer cp -r boards/px4/fmu-v5 boards/manufacturer/my-target-v1
Next you need to go through all files under boards/manufacturer/my-target-v1 and update them according to your board.
- firmware.prototype: update the board ID and name
- default.px4board: update the VENDOR and MODEL to match the directory names (my-target-v1). Configure the serial ports.
- Configure NuttX (defconfig) via
make manufacturer_my-target-v1 menuconfig: Adjust the CPU and chip, configure the peripherals (UART's, SPI, I2C, ADC).
- nuttx-config/include/board.h: Configure the NuttX pins. For all peripherals with multiple pin options, NuttX needs to know the pin. They are defined in the chip-specific pinmap header file, for example stm32f74xx75xx_pinmap.h (opens new window).
- src: go through all files under src and update them as needed, in particular board_config.h.
- init/rc.board_sensors: start the sensors that are attached to the board.