PX4
PX4 Architectural Overview
Flight Controller Porting Guide
NuttX Board Porting Guide
PX4 base layer
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.
PX4 base layer
adc
int px4_arch_adc_init(uint32_t base_address)
void px4_arch_adc_uninit(uint32_t base_address)
uint32_t px4_arch_adc_sample(uint32_t base_address, unsigned channel)
float px4_arch_adc_reference_v()
uint32_t px4_arch_adc_temp_sensor_mask()
uint32_t px4_arch_adc_dn_fullcount()
...
PX4
PX4-Autopilot/boards/<manufacture>/<board>/nuttx-config/nsh/defconfig
CONFIG_ARCH_BOARD_CUSTOM_DIR="../../../../boards/<manufacture>/<board>/nuttx-config"
NuttX
nuttx/boards/<arch-name>/<chip-name>/<board-name>/configs/nsh/defconfig
Sensors
The system minimally requires a gyroscope, accelerometer, magnetometer (compass) and barometer. A GPS or other positioning system is needed to enable all automatic modes, and some assisted modes. Fixed wing and VTOL-vehicles should additionally include an airspeed sensor (very highly recommended).
ボードおよびプラットフォームのコードでチップの設定がどこでおこなわれているのか探す
raspberrypi/pico
のコードを用いてボードおよびプラットフォームのコードでチップの設定を探す。
まずPX4-Autopilot/boards/raspberrypi/pico
をPX4-Autopilot/boards/mymanufacture
にコピー
ashio@mywin:~/PX4-Autopilot/boards/mymanufacture$ tree myboard/
myboard/
├── default.px4board
├── firmware.prototype
├── init
│ ├── rc.board_defaults
│ ├── rc.board_mavlink
│ └── rc.board_sensors
├── nuttx-config
│ ├── include
│ │ └── board.h
│ ├── Kconfig
│ ├── nsh
│ │ └── defconfig
│ ├── scripts
│ │ ├── flash.ld
│ │ └── script.ld
│ └── src
│ └── Make.defs
└── src
├── board_config.h
├── boot_string.c
├── CMakeLists.txt
├── i2c.cpp
├── init.c
├── led.c
├── spi.cpp
├── timer_config.cpp
└── usb.c
7 directories, 20 files
どこがPX4-Autopilot/platforms/nuttx/src/px4/rpi/rp2040
を参照するのか?
ashio@mywin:~/PX4-Autopilot/boards/mymanufacture/myboard$ find . -type f -exec grep rp2040 {} ";" -print
CONFIG_ARCH_CHIP="rp2040"
./nuttx-config/nsh/defconfig
* boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-flash.ld
./nuttx-config/scripts/script.ld
* boards/arm/rp2040/raspberrypi-pico/scripts/raspberrypi-pico-flash.ld
./nuttx-config/scripts/flash.ld
#include <rp2040_uart.h>
* Name: rp2040_boardearlyinitialize
* This function is taken directly from nuttx's rp2040_boardinitialize.c
void rp2040_boardearlyinitialize(void)
rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO, RP2040_GPIO_FUNC_UART); /* TX */
rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 1, RP2040_GPIO_FUNC_UART); /* RX */
rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 2, RP2040_GPIO_FUNC_UART); /* CTS */
rp2040_gpio_set_function(CONFIG_RP2040_UART0_GPIO + 3, RP2040_GPIO_FUNC_UART); /* RTS */
rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO, RP2040_GPIO_FUNC_UART); /* TX */
rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 1, RP2040_GPIO_FUNC_UART); /* RX */
rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 2, RP2040_GPIO_FUNC_UART); /* CTS */
rp2040_gpio_set_function(CONFIG_RP2040_UART1_GPIO + 3, RP2040_GPIO_FUNC_UART); /* RTS */
* Name: rp2040_boardinitialize
rp2040_boardinitialize(void)
rp2040_gpioconfig(27 | GPIO_FUN(RP2040_GPIO_FUNC_NULL)); /* BATT_VOLTAGE_SENS */
rp2040_gpioconfig(28 | GPIO_FUN(RP2040_GPIO_FUNC_NULL)); /* BATT_VOLTAGE_SENS */
rp2040_gpio_set_function(CONFIG_RP2040_I2C0_GPIO, RP2040_GPIO_FUNC_I2C); /* SDA */
rp2040_gpio_set_function(CONFIG_RP2040_I2C0_GPIO + 1, RP2040_GPIO_FUNC_I2C); /* SCL */
rp2040_gpio_set_pulls(CONFIG_RP2040_I2C0_GPIO, true, false); /* Pull up */
rp2040_gpio_set_pulls(CONFIG_RP2040_I2C0_GPIO + 1, true, false);
rp2040_gpio_set_function(CONFIG_RP2040_I2C1_GPIO, RP2040_GPIO_FUNC_I2C); /* SDA */
rp2040_gpio_set_function(CONFIG_RP2040_I2C1_GPIO + 1, RP2040_GPIO_FUNC_I2C); /* SCL */
rp2040_gpio_set_pulls(CONFIG_RP2040_I2C1_GPIO, true, false); /* Pull up */
rp2040_gpio_set_pulls(CONFIG_RP2040_I2C1_GPIO + 1, true, false);
rp2040_spiinitialize();
// spi1 = rp2040_spibus_initialize(CONFIG_NSH_MMCSDSPIPORTNO); // PX4_BUS_NUMBER_FROM_PX4(1)
spi2 = rp2040_spibus_initialize(PX4_BUS_NUMBER_FROM_PX4(2));
./src/init.c
* Name: rp2040_usbinitialize
__EXPORT void rp2040_usbinitialize(void)
__EXPORT void rp2040_usbsuspend(FAR struct usbdev_s *dev, bool resume)
./src/usb.c
* Name: rp2040_spiinitialize
extern void rp2040_spiinitialize(void);
* Name: rp2040_usbinitialize
extern void rp2040_usbinitialize(void);
./src/board_config.h
platforms/nuttx/src/px4
以下には各チップ毎のbase platformのコードが置かれているが、ビルドの際に参照されるどのチップのコードがあるのかの情報は./cmake/px4_impl_os.cmake
にある。
ashio@mywin:~/PX4-Autopilot/platforms/nuttx$ find . -type f \( -name "*ake*" -or -name "*onf*" \) -exec grep rpi {} ";" -print
add_subdirectory(../rpi_common/adc adc)
add_subdirectory(../rpi_common/hrt hrt)
add_subdirectory(../rpi_common/version version)
add_subdirectory(../rpi_common/board_reset board_reset)
add_subdirectory(../rpi_common/board_critmon board_critmon)
add_subdirectory(../rpi_common/spi spi)
add_subdirectory(../rpi_common/io_pins io_pins)
./src/px4/rpi/rp2040/CMakeLists.txt
set(CHIP_MANUFACTURER "rpi")
./cmake/px4_impl_os.cmake
NET_CSRCS += arp_arpin.c arp_out.c arp_format.c arp_table.c
./NuttX/nuttx/net/arp/Make.defs
./cmake/px4_impl_os.cmake
を以下の様に修正し
elseif(CONFIG_ARCH_CHIP_RP2040)
set(CHIP_MANUFACTURER "rpi_")
set(CHIP "rp2040_")
当該ディレクトリをrpi_/rp2040_
に修正してビルドをを試みると成功する。
ビルドディレクトリbuild/mymanufacture_myboard_default
でCONFIG_ARCH_CHIP_RP2040
の痕跡を調べてみるとCMakeCache.txt
で見つかる。
ashio@mywin:~/PX4-Autopilot$ grep CHIP_RP2040 build/mymanufacture_myboard_default/* 2> /dev/null
build/mymanufacture_myboard_default/CMakeCache.txt://NUTTX DEFCONFIG: CONFIG_ARCH_CHIP_RP2040
build/mymanufacture_myboard_default/CMakeCache.txt:CONFIG_ARCH_CHIP_RP2040:INTERNAL=y
改めてボードのコードでCONFIG_ARCH_CHIP_RP2040
を探してみるとboards/mymanufacture/myboard/nuttx-config/nsh/defconfig
という事がわかる。
ashio@mywin:~/PX4-Autopilot$ find boards/mymanufacture/myboard -type f -exec grep CHIP_RP2040 {} ";" -print
CONFIG_ARCH_CHIP_RP2040=y
boards/mymanufacture/myboard/nuttx-config/nsh/defconfig