Open5

PX4

A.しおまねきA.しおまねき

PX4 Architectural Overview
https://docs.px4.io/main/en/concept/architecture.html#px4-architectural-overview

Flight Controller Porting Guide
https://docs.px4.io/main/en/hardware/porting_guide.html

NuttX Board Porting Guide
https://docs.px4.io/main/en/hardware/porting_guide_nuttx.html

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.

https://github.com/PX4/PX4-Autopilot/tree/main/platforms/nuttx/src/px4

A.しおまねきA.しおまねき

ボードおよびプラットフォームのコードでチップの設定がどこでおこなわれているのか探す

raspberrypi/picoのコードを用いてボードおよびプラットフォームのコードでチップの設定を探す。
まずPX4-Autopilot/boards/raspberrypi/picoPX4-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

https://github.com/PX4/PX4-Autopilot/blob/main/platforms/nuttx/cmake/px4_impl_os.cmake

./cmake/px4_impl_os.cmakeを以下の様に修正し

	elseif(CONFIG_ARCH_CHIP_RP2040)
		set(CHIP_MANUFACTURER "rpi_")
		set(CHIP "rp2040_")

当該ディレクトリをrpi_/rp2040_に修正してビルドをを試みると成功する。
ビルドディレクトリbuild/mymanufacture_myboard_defaultCONFIG_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