441 Commits
Author SHA1 Message Date
Benjamin Cabé 04ac816ab0 feat(zephyr): add Zephyr RTOS platform
Add Zephyr as a PX4 platform, so that PX4 can run on the boards and drivers Zephyr supports, and be built and tested with west and twister.

The repository is a Zephyr module (zephyr/module.yml) and a west manifest (platforms/zephyr/west.yml) pinned to Zephyr v4.5.0. An application that enables CONFIG_PX4 gets the PX4 build nested in its Zephyr build: the PX4 modules still come from a .px4board file (boards/zephyr/<board>, or boards/zephyr/generic), and uORB, parameters and the module Kconfig are generated as on the other platforms. Only the submodules this build uses are fetched. Dynamic modules are rejected until they can be built as Zephyr LLEXT extensions.

The platform layer builds on Zephyr's POSIX API, defines __PX4_POSIX like QuRT does, and reuses the POSIX parts that apply:

- hrt counts the cycles of the system timer, with a resolution of a microsecond, and runs its callouts on the kernel tick, which defaults to 100 kHz where the system timer counts that fast, in a k_timer handler in interrupt context.
- PX4 is built as on NuttX: with the -Os of Zephyr, its estimators and controllers with -O2 (MAX_CUSTOM_OPT_LEVEL), and the modules marked UNITY_BUILD as a single compilation unit. The Zephyr compile options go before the options of each target, so that MAX_CUSTOM_OPT_LEVEL overrides the optimization of Zephyr. A board with flash to spare can build it for speed with CONFIG_SPEED_OPTIMIZATIONS.
- The shell has a 4 KiB stack, as PX4 commands run on it, and leaves out the devmem, date and device commands and the wildcards, which PX4 doesn't use. The main thread, which runs the startup script, has a 4 KiB stack.
- Thread priorities stay those of NuttX, and are mapped to those of Zephyr in pthread_attr_setschedparam() and pthread_setschedparam(), which the platform's pthread.h replaces in PX4 code only, leaving the rest of the image on Zephyr's: the top 64, those of the work queues, one to one, and the others below them. Scaled down instead, the offsets of PX4 put the commander above the controllers and the estimator. New thread attributes get explicit scheduling, as Zephyr threads otherwise inherit the priority of the thread that creates them.
- A Zephyr thread runs on the stack of its attributes. Tasks keep their attributes until they are joined, and the platform's pthread.h also replaces pthread_attr_destroy() in PX4 code, to keep the stack of a thread that still runs on it, and to free it once the thread has exited: PX4 destroys the attributes right after creating the work queues, the MAVLink receiver, the log writer and the commander worker thread.
- The common code of PX4 handles where Zephyr differs from the other POSIX platforms, under __PX4_ZEPHYR: tasks and work queues use SCHED_RR, as SCHED_FIFO threads are cooperative on Zephyr, and the work queue priorities are counted from the PX4 SCHED_PRIORITY_MAX; px4_sem_t is a k_sem and the work queue lock masks the interrupts, as on NuttX, since hrt callouts schedule work items from interrupt context; the uORB node lock (ATOMIC_ENTER) masks them too, as on NuttX, since a k_sem has no priority inheritance: a low priority thread preempted while it copies a topic would block the higher priority threads that use it; the work queue threads are started with px4_task_spawn_cmd(), as in the NuttX protected build, so that their attributes are kept; 64-bit atomics, which are not lock-free on Cortex-M, mask the interrupts as on NuttX, with the plain perf counters of the other embedded targets; and PX4_STACK_OVERHEAD comes from Kconfig instead of the 24 KiB of Linux.
- A few headers wrap the Zephyr libc: the Zephyr struct device clashes with PX4's namespace device in C++, so PX4 C++ files see it as struct zephyr_device and the Zephyr drivers are used from C files, and _IO, F_OK and dprintf() are missing.
- The builtin commands and the board's init/rc.px4 lines are compiled into a table. The startup script runs from the application's main(), and the "px4" shell command runs any builtin and returns its exit code. A task that is joined keeps running: it is listed, and px4_task_delete() still stops it. Task ids carry a generation: a task that exits before it is joined is released by the next spawn and keeps its exit code until px4_task_join(), and its id never names the task that reuses its slot.
- The version library reports Zephyr and its kernel version.

platforms/zephyr/app is the reference application, run in QEMU with:

    west build -b mps2/an386 PX4-Autopilot/platforms/zephyr/app -t run

or "make zephyr_qemu". "make zephyr" builds it for ZEPHYR_BOARD, and "make zephyr_tests" runs twister. The Zephyr boards are left out of the PX4 config targets and of the CI build matrix, as they are built with west.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-11-30 11:57:50 -08:00
Balduin 624d384ac7 fix(px4_log): keep the newline on truncated colored console lines
The color reset and newline were written with a size that excluded the
byte buf reserves for the terminating NUL, so snprintf dropped the
newline whenever a line hit the length limit and the next log line was
printed on the same line.

Assisted-by: Claude:claude-opus-5-5
2026-11-30 11:30:26 -08:00
Volkan cce131fc60 feat(boards): add Syro V6X flight controller (#29784)
* feat(boards/syro): add Syro FMUv6X

STM32H7 flight controller based on the FMUv6X reference design, with its
own board ID.

Sensors: two ICM-45686 and a BMI088 IMU, two BMP581 barometers, and a
BMM350 compass. The external compass on GPS1 is started as an IST8310,
and the common magnetometer drivers are built in for other GPS modules.
The baseboard carries a PX4IO co-processor and Ethernet.

Flight-tested as a quadcopter on auto missions; logs are linked in the
pull request.

Assisted-by: Claude
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* feat(boards/syro): identify the Syro baseboard by base ID 0x110

The Syro baseboard's version divider reads 7, so PX4 takes the base ID
from the base EEPROM. Add base ID 0x110 to the base manifest with the
standard FMUv6X base configuration (PX4IO, CAN2, second power module,
Ethernet), so these are enabled on the Syro base.

Build mft_cfg so the IDs can be written to each board during production:
mft_cfg set hwver -i 0x110 and mft_cfg set hwrev -i 0x10.

Assisted-by: Claude
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* docs(boards/syro): add Syro V6X flight controller page

The board support guide requires a docs page for a new flight
controller, with the pinout and a block diagram. Add one for the
Syro V6X and list it in the sidebar and with the
manufacturer-supported boards.

The page documents what the firmware target defines: the serial
port mapping, I2C buses and their reserved addresses (0x46 on I2C2,
0x51 on I2C3), power module inputs, PWM output groups and DShot
support, Ethernet, the TELEM2-only bootloader, and the hardware
IDs written with mft_cfg in production.

Assisted-by: Claude
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* fix(boards/syro): regulate the IMU heater on IMU1 and enable it by default

The heater sits next to IMU1, IMU2, BARO1 and the internal mag. With
HEATER1_SENS_ID left at 0 the heater auto-selects IMU0, which is outside
the heated area, so it never reaches its 55 C target and runs at 100 %.
In flight logs IMU0 stayed at 26-30 C while IMU1, IMU2, BARO1 and the
internal mag reached 65-76 C.

Regulate on IMU1 (ICM-45686 on SPI2, device ID 3407890), which is fixed by
the board design, and enable thermal control since the heater is fitted.

Assisted-by: Claude
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* refactor(boards/syro): remove the unused MS5611 driver

No MS5611 is fitted and the board startup script never starts the driver.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* docs(boards/syro): add pinouts, port drawings and block diagram

Fill in the connector list, the pin tables, the power input range and the store link, and add the Syro V6X to the release notes.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* docs(boards/syro): align the tables in the Syro V6X page

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>

* docs(boards/syro): say which sensors the heater warms

The heater sits on the IMU board, so the ICM-45686 on SPI1 and the BMP581 on I2C2 stay unheated.

Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Volkan Bozdogan <vlknbzdn@gmail.com>
Signed-off-by: Hamish Willee <hamishwillee@gmail.com>
2026-11-26 19:15:50 +11:00
alexcekay aeb3b5377c feat(commander): let boards override the avionics 5V limits
The avionics power check used fixed 4.7V and 5.4V limits for every
board, while the valid range depends on what the 5V rail supplies.
A board can now set BOARD_AVIONICS_5V_MIN_V and BOARD_AVIONICS_5V_MAX_V;
the defaults keep the current limits.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: alexcekay <alexander@auterion.com>
2026-11-25 18:43:29 +01:00
alexcekay 14a7e79a23 feat(esc_battery): let boards set an open circuit voltage
ESCs can stay powered without a battery, e.g. when VBAT is back-fed from
USB, and then report a low voltage that is flagged as a low battery.
A board can now set BOARD_ESC_BATTERY_OPEN_CIRCUIT_V so that such a
reading counts as no battery connected. The default of 0V keeps the
current behavior.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: alexcekay <alexander@auterion.com>
2026-11-25 18:43:29 +01:00
Jacob Dahl ccd9eae185 refactor(platform): load DEFINE_PARAMETERS members from a table (#29554)
* fix(cmake): link the functional gtest libraries as a group

px4_platform, parameters and uorb_msgs all reference uORB, but uORB is
listed before them, so a test only linked when something earlier
happened to pull in px4_log.o. Inlined param_get() type checks did that
for any test using DEFINE_PARAMETERS; without them PerformanceModel and
StickYaw failed with undefined orb_advertise and orb_publish.

Assisted-by: Claude:claude-opus-5-5

* refactor(platform): load DEFINE_PARAMETERS members from a table

Every parameter cost a param_get_mark_used() call in its class
constructor and a param_get() call in updateParamsImpl(), about 12 bytes
each, for roughly 2000 parameters. Each Param now takes one
pointer-sized slot, so the members a DEFINE_PARAMETERS list declares
form an array. A ParamTable member declared right after them holds the
handles and loads them all with one call, in the constructor and on
update. External parameters keep a pointer instead of a reference so
the loader can follow it.

Assisted-by: Claude:claude-opus-5-5

* refactor(platform): use param_t for parameter table entries

Each entry is a parameter handle with the storage kind in its top bits,
so it takes the handle's type.

Assisted-by: Claude:claude-opus-5-5

* refactor(platform): keep each Param at its natural size

Padding every Param to a pointer-sized slot doubled float and int32
members on 64-bit targets and grew ParamBool from 1 to 4 bytes. The
macro now passes the first parameter's address to the table, and the
loader steps through the members at each kind's own size and alignment.
A table placed before the parameters would instead load through the
external parameters before their pointers are set.

Assisted-by: Claude:claude-opus-5-5

* refactor(platform): drop the parameter table end marker

APPLY_ALL leaves a comma after every entry, so the template argument
list needed a closing element, which every class then stored in its
entry array. The entries are now a static array of the class, whose
braced initializer accepts the trailing comma.

Assisted-by: Claude:claude-opus-5-5

* refactor(platform): check the parameter layout at compile time

The language leaves padding between members to the compiler, so the
table loader relies on the ABI placing each member at the next address
its alignment allows. Each class's updateParamsImpl() now checks every
parameter's offsetof against where the loader steps, so a compiler that
pads differently fails the build instead of loading into the wrong
members.

Assisted-by: Claude:claude-opus-5-5

* docs(platform): describe how DEFINE_PARAMETERS loads parameters

The table loader walks the members of a class from the first parameter's
address, which is not obvious from the macros or the loader alone. A
block above the macros now states the flash cost it removes, what the
macro adds to a class, how the loader steps, and which static_asserts
guard the layout it relies on.

The namespace comment said a Param does not depend on the macro. That
stopped being true when the constructors stopped loading.

Assisted-by: Claude:claude-fable-5-2

* docs(platform): drop the flash figure from the parameter table comment

A measured saving for one board goes stale as parameters are added. The
comment now states what the table replaces the per-parameter calls with.

Assisted-by: Claude:claude-fable-5-2

* fix(platform): build the parameter layout check on GCC before 9

GCC 7 and 8 ignore _Pragma diagnostics inside a macro expansion, so the
offsetof warning in the DEFINE_PARAMETERS layout check stays an error on
the VOXL 2 toolchain. Those compilers now build with
-Wno-invalid-offsetof. The static_assert still runs there.

Assisted-by: Claude:claude-opus-5-5
2026-11-24 17:04:42 -07:00
Ramon Roche 170dfbbfe8 build(px4io): build IO firmware from source, drop committed binaries
Boards with a px4io took the IO firmware from a binary committed under
boards/<vendor>/io-v2/extras/. It had to be regenerated by hand with
"make px4io_update" whenever px4iofirmware, lib/rc, the IO board or
NuttX changed, and a CI job failed until it was.

Build it from source instead. A target with CONFIG_BOARD_IO set now
builds that IO target as part of its own build and puts the result in
its ROMFS. NuttX builds inside its source tree, so the IO build gets its
own copy of the NuttX sources in build/px4io/<BOARD_IO>/, shared by
every target built in the checkout. The IO build runs on every build of
the embedding target, so an IO source change reaches the ROMFS without
a clean.

PX4_NUTTX_TREE_DIR points a NuttX build at such a copy, and the
hardcoded platforms/nuttx/NuttX/{nuttx,apps} paths now go through
NUTTX_DIR and NUTTX_APPS_DIR.

Remove the two committed binaries, the px4io_update and check_px4io
make targets, and the CI job that compared them.

Assisted-by: Claude:claude-fable-5-2
2026-11-23 14:49:27 -08:00
Anil Kircaliali 5db5c623a1 fix(logger): use selected device_id to choose sensor in fifo logging (#29751)
* fix(logger): use selected device_id to choose sensor in fifo logging

* fix(logger): keep logger_topics.txt fifo instances and skip profile fifo without a matching selected imu

* docs(logger): describe fifo logging of the selected imu
2026-11-23 14:31:17 +01:00
Jacob Dahl 91a4c21ca8 refactor(drivers): share the start/stop/status dispatch of I2C/SPI drivers (#29556)
90 driver main functions repeated the same three strcmp() checks and
calls. I2CSPIDriver<T>::module_main() does it once; drivers with extra
verbs keep their own dispatch.

Assisted-by: Claude:claude-opus-5-5
2026-11-10 15:58:59 -07:00
Peter van der PerkandAndre Heinemans 676b485702 feat(platform): add the NXP i.MX9 and i.MX95 NuttX platform layer
Add the PX4 arch layer for the i.MX9 family: ADC, HRT on LPTMR with
LPIT deadlines, TPM io timers, pin interrupts, LPSPI with chip selects
for all eight instances, critmon on the DWT cycle counter, a tone alarm
on a TPM channel, version reporting with the 128-bit ECID read from the
Fuse Status Block as the UUID, the board reset entry point, plus the
i.MX95 chip include set, the chip mapping in px4_impl_os.cmake and the
PX4_SOC_ARCH_ID_IMX95 id. DShot uses the shared NXP FlexIO driver with
the i.MX9 FlexIO base, offsets, IRQ, clock root and pad hooks.

Not implemented yet: reset of the M7 through the System Manager, LED
PWM and PWM input capture.

i.MX9 timer configs name their timers Timer::TPMn and mark DShot
capable ones with initIOTimerDshot(), so teach
output_groups_from_timer_config.py both forms.

Co-authored-by: Andre Heinemans <andre.heinemans@nxp.com>
2026-11-06 07:32:53 -08:00
Peter van der PerkandAndre Heinemans 224e046072 fix(work_queue): Extend I2C/SPI instances to support i.MX95
Co-authored-by: Andre Heinemans <andre.heinemans@nxp.com>
2026-11-06 07:32:53 -08:00
Jacob Dahl 9b2074abc3 refactor(platform): give PX4_INFO, PX4_WARN and PX4_ERR one entry point per level (#29552)
About 1700 call sites loaded the log level as the first argument of
px4_log_modulename(). Per-level functions drop that load and leave one
more register for the format arguments.

Assisted-by: Claude:claude-opus-5-5
2026-10-31 13:35:27 -06:00
Jacob Dahl 65b89bff03 refactor(platform): compile out module help text on NO_HELP boards (#29550)
CONSTRAINED_FLASH_NO_HELP only emptied the PRINT_MODULE_USAGE_* bodies,
so every call site and its strings stayed in flash. Make the helpers
no-op inlines there, as PRINT_MODULE_DESCRIPTION already is on NuttX;
only the usage line with the docs link is still printed.

Assisted-by: Claude:claude-opus-5-5
2026-10-31 13:27:45 -06:00
Jacob DahlandBalduin 5196d31507 refactor(uORB): share the SubscriptionMultiArray initialisation to save flash (#29547)
The constructor loop that assigns and subscribes every instance was
expanded into each of the ~55 SubscriptionMultiArray members in the
firmware. Move it into a non-template function in Subscription.cpp,
called with the array, its size and the topic.

px4_fmu-v6x_default: 1918712 -> 1917160 bytes of text, -1552 B.

Assisted-by: Claude:claude-fable-5-1

Co-authored-by: Balduin <balduin@auterion.com>
2026-10-31 11:57:26 -06:00
Jacob DahlandBalduin 5535d849a2 refactor(platform): out-line the ModuleParams constructor to save flash (#29545)
The constructor was defined in the header, so every one of the ~150
module and library classes deriving from ModuleParams expanded it into
its own constructor: the ListNode and child-list initialisation plus
the setParent() call, repeated per class.

Moving the body next to setParent() in module_params.cpp leaves a single
call at each site. px4_fmu-v6x_default: 1934288 -> 1932520 bytes of
text, -1768 B.

Assisted-by: Claude:claude-fable-5-1

Co-authored-by: Balduin <balduin@auterion.com>
2026-10-31 11:43:01 -06:00
Jacob DahlandBalduin 1ed0e63ca5 refactor(platform): out-line the I2CSPIDriverBase constructor to save flash (#29544)
The constructor was defined in the header, so each of the ~75 I2C/SPI
drivers expanded the ScheduledWorkItem and I2CSPIInstance initialisation
into its own constructor.

Moving the body to i2c_spi_buses.cpp leaves one call per driver.
px4_fmu-v6x_default: 1932520 -> 1930616 bytes of text, -1904 B.

Assisted-by: Claude:claude-fable-5-1

Co-authored-by: Balduin <balduin@auterion.com>
2026-10-31 11:42:43 -06:00
Jacob DahlandBalduin 9c1e218b1f refactor(platform): out-line ModuleParams::updateParams() to save flash (#29543)
The base implementation, which walks the child list and then calls
updateParamsImpl(), was defined in the class body. Every module that
calls updateParams() on a parameter update therefore inlined the list
walk. Define it in module_params.cpp next to setParent().

px4_fmu-v6x_default: 1917160 -> 1915056 bytes of text, -2104 B.

Assisted-by: Claude:claude-fable-5-1

Co-authored-by: Balduin <balduin@auterion.com>
2026-10-31 11:42:34 -06:00
Andrew Brahim 9f29d50f92 fix(vectornav): Lower scheduler priority (#28934)
* fix(vectornav): limit init based on retries, set max thread prio

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

* fix(vnav): set lower priority than max

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

* chore(vnav): remove unused variable

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

* fix(vnav): set scheduler priority definition in tasks header, base off of PX4_WQ_HP_BASE

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>

---------

Signed-off-by: dirksavage88 <dirksavage88@gmail.com>
2026-10-30 15:34:54 +01:00
Jacob Dahl ade867b1a5 fix(uORB): unregister callback subscriptions before the subclass is destroyed (#29515)
A publisher calls call() under the node lock until the subscription is
unregistered. SubscriptionBlocking, SubscriptionCallbackWorkItem and
the MCP CallbackHandler left that to ~SubscriptionCallback(), which runs
after the subclass is gone, so a publication during destruction aborted
with "pure virtual method called". SubscriptionBlocking could also signal
its already destroyed condition variable. SITL mag calibration in SIH hit
this on almost every side.

The new functional test aborts on both subscription types within about
a second without the fix.

Assisted-by: Claude:claude-opus-5-5
2026-10-29 18:15:15 -06:00
Benjamin Cabé cd2b157682 perf(uORB): skip subscription lookups until a device node is added (#29249)
While a topic has no device node, every Subscription::update(), copy(),
updated() and advertised() repeats the device node lookup and fails
again. Polling modules touch many optional topics on every loop: in a
SITL flight about 8% of all instructions, and about a quarter of each
MAVLink thread, were such failed lookups.

Device nodes are never removed, so a lookup that failed cannot succeed
before a node is added. Count the nodes added in DeviceMaster and only
retry the lookup once that count has changed. Protected builds, where
user space has no cheap access to it, keep retrying every time.

Assisted-by: Claude:claude-opus-5-5

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-24 07:06:39 -08:00
Afonso Oliveira af77d02acf Revert "fix(px4_work_queue): link px4_layer for the task functions it uses"
This reverts commit d92a0c6b3. In protected builds px4_work_queue is also
linked into the kernel image, where px4_layer's user-side objects collide
with the kernel ones (px4_fmu-v5_protected). The Erbium target no longer
needs the link dependency, since its modules pull in px4_task_spawn_cmd()
and px4_task_join() before px4_work_queue is linked.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
2026-10-23 22:42:28 +02:00
Afonso Oliveira d7e71f6931 feat(nuttx): add AIFoundry Erbium chip support
Erbium is a RISC-V RV64IMFC chip whose NuttX port is in PX4/NuttX. Add
the PX4 platform layer for it: HRT, board reset, critmon time base and
board identity, the riscv-none-elf toolchain file and the rv64imfc
compiler flags, which include -mno-fdiv because the ET-Minion core has
no hardware for FDIV.S and FSQRT.S.

The HRT reads the machine timer and runs its callouts in a task, since
the NuttX RISC-V trap path does not save the FP registers that callouts
may use.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
2026-10-23 22:42:28 +02:00
Afonso Oliveira aa1724fa0c fix(px4_mtd): forward-declare the NuttX structs used in prototypes
px4_at24c_initialize() takes a struct i2c_master_s pointer. Without a
declaration in scope the struct is local to the prototype, which is an
error with -Werror on a target that does not include the NuttX I2C
headers before px4_mtd.h.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
2026-10-23 22:42:28 +02:00
Afonso Oliveira 9e2711ae1a fix(px4_work_queue): link px4_layer for the task functions it uses
WorkQueueManager starts and joins its thread with px4_task_spawn_cmd()
and px4_task_join() from px4_layer, but px4_work_queue did not declare
that dependency. Targets with many modules pull those objects in before
px4_work_queue is linked; a target with only a few system commands
fails to link.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Afonso Oliveira <afonso.oliveira707@gmail.com>
2026-10-23 22:42:28 +02:00
Lourens Naude c283d61ef3 perf(uORB): skip the queue offset division for single-slot topics
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude d4a86b5d43 perf(uORB): publish through the node directly from the typed wrappers
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude 5abef6d065 perf(uORB): match nodes by ORB_ID instead of strcmp
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude 537b82d380 perf(uORB): check the exists bitset before allocating in advertise()
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude 9d65ba66ae perf(uORB): skip poll_notify() on publish without poll waiters
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude 427bf69cdd perf(uORB): load _last_update in callbacks only when an interval is set
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Lourens Naude 2a9be29e3c perf(uORB): check for new data before reading the clock in updated()
Assisted-by: Claude:claude-fable-5-1
2026-10-22 08:26:26 +02:00
Michael Rogov Papernov 3fe7acc19d refactor(events): move the message-less send() out of line
events::send(id, log_levels, message) was an inline function, so every
module using it got either a private clone or the body inlined at each
call site. The message is never part of the sent event: it only feeds
the build-time event generator and the optional console print.

Keep a thin inline wrapper so the compiler still drops the unused
message string, and build the event in one out-of-line function that
takes the two log levels as scalars to keep the call sites small. This
saves 1760 bytes of FLASH on px4_fmu-v6x and 1184 bytes on px4_fmu-v2.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Michael Rogov Papernov <michael@membrowse.com>
2026-10-20 16:45:03 +02:00
Jacob Dahl 8c5f4e0788 fix(px4_work_queue): don't touch a WorkItem after its Run() returns (#29278)
Modules that stop through ModuleBase::exit_and_cleanup() delete themselves
inside Run(), and since 9b62a1701d WorkQueue::Run() then clears
_run_in_progress in the freed object. ASAN aborts SITL on
`battery_simulator stop` and the stop of most other work queue modules.

Track the in-flight item in the WorkQueue instead, which lives until its
own Run() exits on the worker thread.

Assisted-by: Claude:claude-opus-5-5
2026-10-19 12:37:19 +13:00
e146fe4cc6 fix(uorb): keep shared topics advertised on publisher teardown (#29176)
* fix(dataman_client): keep request topic advertised on client teardown

* fix(uorb): keep shared topics advertised on publisher teardown

Single-instance publications share one advertised flag, so destroying one
publisher must not hide updates from the others.

Keep automatic unadvertising in PublicationMultiBase and remove the
DatamanClient workaround. Cover surviving publishers and instance reuse,
and reset retained input samples between test cases.

Tested: make tests (215/215), make format.
Signed-off-by: jonas <jonas.perolini@rigi.tech>
Assisted-by: Codex

* docs(uorb): correct unadvertise comments and document teardown

The unadvertise comment claimed it has no effect on single-instance
topics, which is how one publisher's teardown came to hide the others.
State what clearing the shared flag does, and document that only
PublicationMulti releases its instance on destruction.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonas.perolini@rigi.tech>

* test(uorb): keep test cases independent of retained samples

A destroyed single-instance publication now leaves its last sample
visible, so ManualControlTest, test_prec_takeoff and mixer_module_tests
passed only in declaration order and failed under --gtest_shuffle.
Reset with an inert sample where one exists, otherwise unadvertise the
test's own publications, and drop module outputs left over from a
previous case.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: jonas <jonas.perolini@rigi.tech>

* fix(boards): drop the PublicationBase destructor from the ITCM lists

The destructor is now trivial and no longer emitted, so itcm_check.py
fails on the missing section.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>

---------

Signed-off-by: jonas <jonas.perolini@rigi.tech>
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Co-authored-by: jonas <jonas.perolini@rigi.tech>
Co-authored-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-10-14 16:53:20 -06:00
Benjamin Cabé 9a1429ae90 fix(platforms): sleep with nanosleep() in px4_usleep() (#29218)
* fix(platforms/common): sleep with nanosleep() in px4_usleep()

Outside of the SITL lockstep build, px4_usleep() was usleep(). POSIX only requires usleep() to accept less than 1000000 microseconds and lets it fail with EINVAL from there; POSIX.1-2001 marked it obsolescent and POSIX.1-2008 removed it in favour of nanosleep(). glibc, NuttX and macOS sleep for longer anyway, but other implementations return EINVAL at once, and as no caller checks the result, the sleep would silently not happen. More than twenty call sites ask for a second or more, such as uorb top, mavlink, the ESC calibration or voxl2_io, and some durations are computed at run time, such as the one-second idle period of the POSIX HRT thread.

Outside of the lockstep build, px4_usleep() is now a px4_platform function that converts the microseconds to the timespec of nanosleep(), so the call sites keep passing microseconds of any duration. It is not inline: expanding the conversion at every call site grew px4_fmu-v6xrt_default by 4 kB of flash. QURT has no nanosleep(), which PX4 only stubs there, but its usleep() accepts a second or more, so px4_usleep() remains usleep() there. system_usleep() remains usleep(), for the wall-clock sleeps that bypass the lockstep scheduler.

A signal still ends the sleep early, with -1 and EINTR, rather than restarting it for the remaining time: on POSIX, the HRT and work queue threads sleep in px4_usleep(), and hrt_work_queue() and work_queue() wake them with SIGCONT, so a restarted sleep would delay hrt_call_*() callouts by up to a second. On NuttX, no PX4 code signals its tasks, and px4_task_delete() does not depend on the sleep returning: without cancellation points, which no board enables, task_delete() terminates the task wherever it is.

Failures are now -1 with errno, where the usleep() of NuttX returned the error number. No call site checks the result, so none changes. The sleep test now also sleeps for 1.2 s.

Assisted-by: Claude:opus-5.5

* perf(boards): keep the sleep path in ITCM on i.MX RT boards

The ITCM lists of these boards hold the sleep path of NuttX: usleep(), clock_nanosleep() and nxsig_nanosleep(). px4_usleep() now enters it through its own function and nanosleep(), which take the place of usleep(), so the path stays in ITCM. usleep() remains linked for the code that still calls it directly, such as the start-up code of the boards and NSH.

Assisted-by: Claude:opus-5.5

* fix(drivers): sleep for a second or more with px4_usleep()

bmi088_i2c, microstrain, frsky_telemetry and the bit rate detection of the kinetis, stm32 and stm32h7 UAVCAN drivers asked usleep() for a second or more, which POSIX doesn't require it to accept. The usleep() of NuttX accepts it, but px4_usleep() now does on every platform.

Assisted-by: Claude:opus-5.5
2026-10-14 10:36:30 -06:00
Benjamin Cabé 3fc3b141d7 feat(platforms/common): GUIDs of boards that override the UUID
Boards that override their UUID, such as SITL and the Linux boards, only had the functions that format the GUID, while DroneCAN and Cyphal send the GUID itself to the other nodes, so these drivers couldn't be linked for them. board_get_mfguid() and board_get_px4_guid() now give the bytes that the formatting functions print.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-12 12:45:09 +02:00
Peter van der Perk c2fb94dd95 feat(imxrt): report the boot flash part name in the MCU version
The fmu-v6xrt boards can be fitted with either of two octal flash parts, and
nothing told the user which one is on the board. The identity is already
known: the bootloader stage reads the JEDEC ID to pick a config, and the app
stage recognises the config from the installed read sequence, so no extra
flash access is needed to report it.

Keep the part name behind a weak board_get_flash_type_name() and append it to
the chip tag when the board provides one, so `ver mcu` and the logged chip
name read e.g. "i.MX RT1170 rA0 IS25WX512M". Boards that do not implement it
are unaffected and their tag is unchanged.

Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
2026-10-05 11:23:10 +02:00
Jacob DahlandBalduin 0e9d8f6bea refactor(platform): share I2C/SPI driver startup failure handling (#28786)
Each default driver instantiation emits the same allocation and initialization failure handling. Share that code outside the template while keeping init() resolved on the concrete driver. Allocation failures are now logged under SPI_I2C.

Extracted from Balduin (mbjd) in PX4/PX4-Autopilot#27816, commit 8a2391730f8fd9e1bf8f1b112ac4353904647ade.

Assisted-by: Codex

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Co-authored-by: Balduin <balduin@auterion.com>
2026-09-21 22:50:23 -06:00
Julian Oes cc976e150a feat(posix): separate the filesystem root from the storage directory (#28582)
On NuttX these are two things: / is the filesystem root, and /fs/microsd is the
SD card mounted under it. MAVLink FTP serves the root and confines writes to the
SD card, so the read-only ROMFS at /etc is visible but cannot be written.

On POSIX they were the same directory. PX4_ROOTFSDIR and PX4_STORAGEDIR both
resolved to CONFIG_BOARD_ROOT_PATH, which on SITL is ".", so the working
directory was simultaneously the FTP root and the only writable area. The
consequences were that the ROMFS symlink sat inside the FTP root, and that
_validatePathIsWritable() had nothing meaningful to check against and so was
compiled out on POSIX entirely, leaving no write restriction at all.

Give POSIX the same split. CONFIG_BOARD_ROOT_PATH keeps its meaning as the
storage directory, and a new CONFIG_BOARD_FS_ROOT_PATH names the root FTP
serves, defaulting to the storage path so every existing board is unchanged.
SITL sets the root to "." and storage to "./fs", which mirrors NuttX: logs,
parameters, dataman and eeprom move under ./fs, and etc/ stays in the root as
read-only data.

With storage distinct from the root, the write restriction now applies on every
platform rather than NuttX only, and no longer compares against a hardcoded
prefix length that was wrong for any board not using /fs/microsd.

Assisted-by: Claude:claude-opus-5[1m]

Signed-off-by: Julian Oes <julian@oes.ch>
2026-09-08 17:01:55 -06:00
Jacob Dahl 39eae27610 fix(uavcan): apply UAVCAN_BITRATE on FlexCAN again, size uavcan/TTY work queues for NuttX 12 (#28509)
* fix(uavcan): apply UAVCAN_BITRATE on FlexCAN again

58dfff0de7 turned the SIOCSCANBITRATE path off for i.MX RT, S32K and Kinetis,
which is every board in the tree that builds SocketCAN, so UAVCAN_BITRATE
stopped doing anything at all. It was written before db6f7ec304, and the crash
it works around is that commit's bug: the driver reports bit/s on NuttX 12 and
the caller still divided by 1000, so a 1 Mbit/s board asked its controller for
1000 bit/s on every boot.

Benched on an ARK FMU-v6XRT with the gate removed: 1 Mbit/s -> 500 kbit/s ->
1 Mbit/s round-trips with both DroneCAN nodes coming back OPERAT, buses
error-active, no fault. Requesting a rate the controller cannot reach is also
survivable now -- it is reported and the configured rate is kept, where before
a negative return from here made CanDriver::init() give up and DroneCAN never
started.

The %u for a uint32_t is fixed as well; nothing compiled this branch while the
gate was in place.

* fix(work_queue): size the uavcan and TTY work queues for NuttX 12

NuttX 12.12 costs a few hundred bytes of stack on the paths that go through
the file layer, and that is more than these two defaults left spare. Measured
against the same PX4 tree on 10.3.0:

  wq:uavcan  2860/3728 -> 3184/3736  (ARK FMU-v6X, two DroneCAN GNSS nodes)
  wq:ttyS4   1088/1704 -> 1432/1712  (ARK FMU-v6XRT, crsf_rc)

load_mon reports wq:ttyS4 low on stack with 280 bytes left, and wq:uavcan sits
at 85 % of its own. 4096 and 2048 restore the margin the 10.3.0 figures had.
2026-09-03 12:31:07 -07:00
Jacob Dahl c9f5442402 feat(sensors): classify sensors independently of bus topology (#28352)
* feat(sensors): decouple sensor internal/external classification from the bus

A sensor's internal/external classification was derived from its bus
(px4_i2c_bus_external / px4_spi_bus_external), but a bus is a wire: one bus
routinely serves both chips soldered on the FC and a pinned-out connector, and
any onboard sensor on such a shared bus was classified external. That hands an
onboard mag an operator-settable rotation instead of the board rotation, feeds
an onboard baro's self-heated die temperature into air density as if it were
ambient, and inverts the 75/50 default priority. FMU-v6C and AirBrainH743
worked around it with hand-rolled device_id whitelists behind
BOARD_OVERRIDE_I2C_DEVICE_EXTERNAL; FMU-v6XRT's second onboard baro was simply
misclassified.

Classify the device instead of the bus: drivers publish is_external in
sensor_accel/gyro/mag/baro, derived from the device id by default and
overridden by the new -O start flag ("onboard") for onboard sensors that share
a bus with an external connector. -I/-X stay pure bus probe filters.

The question "is this sensor external" had four answers. It now has one, with
a single override point:

  -O -> I2CSPIDriverConfig::external -> Device::set_external() and the
        PX4* wrappers -> is_external in the sensor topic

px4_i2c_device_external() was px4_i2c_bus_external() with a device id decode in
front, and calibration::DeviceExternal() forwarded to device_is_external();
both are gone. Device::external() stops being a bus query: it is non-virtual,
defaults to device_is_external(), and takes the declared value through
set_external(), so the five I2C/SPI overrides that used to answer it from the
bus are deleted and cannot diverge again. device::I2C and device::SPI set it
from the config, so every driver built on the bus framework follows -O without
doing anything. px4_i2c_bus_external() and px4_spi_bus_external() survive as
what they honestly are - bus predicates - reachable only through the fallback.

-O is opt-in per driver (BusCLIArguments::support_onboard), the same way -k is:
a flag that every driver advertised but only a handful honoured would be a
silent no-op on the rest. This also drops the special case for the mcp23009 and
mcp23017 GPIO expanders, which use -O for their output state and simply do not
opt in.

sensor_gyro_fifo carries is_external too. VehicleAngularVelocity prefers the
FIFO topic for any IMU that publishes one, so without it the rate controller
would take its rotation from the bus while VehicleIMU took it from the topic -
the same chip, two classifications.

The BOARD_OVERRIDE_I2C_DEVICE_EXTERNAL hook is removed along with both board
implementations, replaced by -O on the affected rc.board_sensors lines.
FMU-v5x, MR-CANHUBK3, KakuteF7, NXT-Dual and MicoAir H743-Lite each start an
onboard barometer on an external bus and get the flag as well.

Assisted-by: Claude:claude-fable-5, Claude:claude-opus-5[1m]
Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>

* feat(sensors): treat shared buses as first-class topology

A boolean internal/external flag cannot describe a bus that carries both
hard-mounted chips and a connector. -O was an opt-in override for that
case, so most drivers silently ignored it and classification still
followed the bus.

Declare Internal / External / Shared on the bus, probe External and
Shared, and classify each sensor from -I/-s vs -X/-S.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>

* fix(ci): drop stale ITCM symbols and clang-tidy errors

ITCM lists still named calibration::DeviceExternal and
px4_spi_bus_external after both were removed. The host test stubs
forwarded varargs in a way the analyzer rejected, and stripped I2C
headers kept extra trailing newlines.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>

* fix(sensors): inline device_is_external into the header

Reaching it through drivers__device pulled the kernel-only library into
the userspace image of a protected build; giving it a library of its own
put an archive referencing px4_i2c_buses/px4_spi_buses after the board
library that defines them. Inlining sidesteps both.

* fix(sensors): compile tcbp001ta and probe canhubk3 GPS mag

tcbp001ta is not an I2CSPIDriver, so config.external does not exist; it
only ever starts on internal SPI. -X on canhubk3 I2C2 never ran because
that bus is Internal.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>

---------

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-08-28 21:14:13 -06:00
Jacob DahlandBalduin c092f80f38 refactor(drv_hrt): out-line hrt_elapsed_time to save flash (#28443)
hrt_elapsed_time() was a static inline expanding to ~15 bytes at each
of its ~450 call sites (call to hrt_absolute_time plus 64-bit compare
and subtract). Move the definition into px4_platform so each call site
is a single branch. px4iofirmware does not link px4_platform, so it
compiles the new source directly.

Saves 3592 bytes of flash on px4_fmu-v6x_default.

Co-authored-by: Balduin <balduin@auterion.com>
2026-08-28 18:40:25 -06:00
Jacob DahlandBalduin 26c5ef2076 refactor(px4_work_queue): out-line ScheduledWorkItem ctor and ScheduleNow (#28440)
* refactor(px4_work_queue): out-line ScheduledWorkItem constructor to save flash

The header-inline constructor zero-initialises the hrt_call member at
every derived work-item constructor across ~150 classes. Move the
definition (verbatim) into ScheduledWorkItem.cpp next to the
destructor; the derived constructors already pay a call into the base
constructor chain, so this only removes the duplicated inline stores.

Saves 1376 B of .text on px4_fmu-v6x_default.

Signed-off-by: Balduin <balduin@auterion.com>

* refactor(px4_work_queue): out-line WorkItem::ScheduleNow to save flash

The body was inlined at ~240 call sites; a plain call is smaller at
every one of them.

Saves 672 B FLASH on px4_fmu-v6x_default.

Signed-off-by: Balduin <balduin@auterion.com>

---------

Signed-off-by: Balduin <balduin@auterion.com>
Co-authored-by: Balduin <balduin@auterion.com>
2026-08-28 18:31:57 -06:00
Jacob DahlandBalduin 255d9c602b refactor(platform): out-line BusCLIArguments constructor to save flash (#28441)
The constructor is inlined into every I2C/SPI driver's command-line
entry point, and with it the ~15 default member initializers and the
32-byte _options zero-fill, costing ~50-70 B per driver. Move the
definition (verbatim) into i2c_spi_buses.cpp, which already holds the
rest of the CLI parsing code. Purely cold-path (driver start/CLI).

Saves 2456 B of .text on px4_fmu-v6x_default.

Signed-off-by: Balduin <balduin@auterion.com>
Co-authored-by: Balduin <balduin@auterion.com>
2026-08-28 18:26:09 -06:00
Jacob DahlandBalduin 122b2666ec refactor(parameters): merge Param<> constructor calls to save flash (#28320)
Every Param<> constructor inlines param_set_used(handle()) followed by
param_get(handle(), &_val), materialising the handle constant twice at
each of the ~2000 instantiation sites. Fold both into a single
out-of-line param_get_mark_used() so each constructor emits one call.

The failsafe_web build stubs the param API itself, so it gets a matching
stub. The smaller constructors let the compiler fully inline the
defaulted FlightTaskDescend constructor on the ITCM boards, so its entry
is dropped from their linker scripts.

Saves 7232 B of .text on px4_fmu-v6x_default.


Assisted-by: Claude:claude-fable-5

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Co-authored-by: Balduin <balduin@auterion.com>
2026-08-21 10:35:38 -06:00
Jacob DahlandBalduin 6c53460f2e refactor(platform): out-line ModuleParams setParent and destructor to save flash (#28321)
Both were defined inline in the header, so the List add/remove bodies
were duplicated into the constructor and destructor of every one of the
150+ ModuleParams-derived classes. Construction and destruction are cold
paths; a call is smaller at each site.

Two consumers reach ModuleParams without px4_platform on the link line
and now need the definitions explicitly: health_and_arming_checks (the
functional-ModeManagement test only pulls it in transitively through
modules__commander, after px4_platform) and the failsafe_web emscripten
build, which compiles module_params.cpp directly.

The smaller constructors let the compiler fully inline the defaulted
FlightTaskDescend constructor on the ITCM boards, so its entry is
dropped from their linker scripts.

Saves 3968 B of .text on px4_fmu-v6x_default.


Assisted-by: Claude:claude-fable-5

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
Co-authored-by: Balduin <balduin@auterion.com>
2026-08-21 10:34:09 -06:00
Marin DandHamish Willee ae663d374e feat(driver/dlvr): add support for dlvr airspeed-sensors (#26363)
* add: driver for dlvr - airspeed family (continuous sampling only)

* unify: INH_TO_PA

---------

Signed-off-by: Marin Doetterer <marin@auterion.com>
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
2026-08-21 11:28:04 +02:00
Jacob Dahl db3b630dde fix(manifest): return the matching PAB manifest entry (#28315)
board_query_manifest walked the list for mft[ndx].id == id then
returned &mft[id]. On a sparse list that is the wrong row, and for
PX4_MFT_T100_ETH (id 7) it is out of bounds.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-08-20 19:48:57 -06:00
alexcekay f7e7815e63 feat(ver): add command to compare population option 2026-08-20 11:34:01 +02:00
Balduin aba458bee3 refactor(platform): constant-initialise static descriptor tables to save flash
Make px4::atomic's value constructor and ModuleBase::Descriptor
constexpr so the ~40 per-module 'desc' statics are constant-initialised
instead of each emitting static-init code, and apply the same to the
mixer_module FunctionProvider table.

Signed-off-by: Balduin <balduin@auterion.com>
2026-08-06 13:41:07 +02:00