Commit Graph
1286 Commits
Author SHA1 Message Date
Benjamin Cabé 33109cd71d fix(top): stop when the input can't be polled (#29227) 2026-10-16 15:43:00 +02: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é cfef6b0bac fix(tune_control): play the note given with -f
tune_control play -f <frequency> -d <duration> fills a custom tune, tune ID 0, with the note, but then replaced the tune ID 0 with 1, the startup tune, so the tone alarm played the startup tune instead of the note. The startup tune is now the default only when neither a tune nor a frequency is given.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-14 12:09:58 +02:00
Jacob Dahl de52c98eff feat(cannode): bootloader update from the app and combined flash image (#28293)
* feat(bl_update): pet the watchdog during erase and program

CAN nodes start the IWDG in the bootloader, and nothing else pets it
while bl_update holds the scheduler lock.

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

* feat(nuttx): emit canbootloader to board extras and build bootloader+app image

canbootloader builds now write extras/<vendor>_<board>_bootloader.bin
like FMU bootloader builds do, which plugs CAN nodes into the existing
ROMFS / rc.board_bootloader_upgrade / jlink wiring. CAN node app builds
with that file also emit <config>_with_bootloader.bin (bootloader padded
to the app's ELF load address, followed by the CRC'd image) so a bare
board is flashed in one SWD step instead of two.

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

* feat(cannode): run rc.board_bootloader_upgrade at startup

The hook was only wired into the FMU rcS, so SYS_BL_UPDATE did nothing
on CAN nodes even with bl_update built in.

* feat(ark): enable bootloader update on CAN nodes

Ships the CAN bootloader in the app ROMFS so a node can rewrite it via
SYS_BL_UPDATE without SWD.

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

* docs(dronecan): bootloader update and combined image for CAN nodes

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

* build(ark): rebuild CAN node bootloaders from current main

The committed binaries predated the F412 chip-selection and linker fixes
and the NuttX 12.12 upgrade, so they no longer matched the source.

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

* feat(uavcannode): update the bootloader as soon as SYS_BL_UPDATE is set

Same approach as AP_Periph. Running the update on the next boot needed
two reboots and reported nothing over CAN: it ran before uavcannode
started, and the boot script printed "done" even when bl_update failed.
The node now flashes while running, skips an identical bootloader, and
the result reaches the flight controller through the existing log
message forwarding. A value left set from before boot is cleared rather
than acted on.

The flash routine moves into a library so uavcannode can call it.

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

* docs(dronecan): note that the combined CAN node image resets parameters

Found on the bench: the padding between bootloader and app covers the
parameter sectors, so every SWD flash of the combined image erases them.

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

* fix(nuttx): limit CAN bootloader extras and combined image to STM32

Every canbootloader build wrote its binary to the board's extras, so a
later nxp_ucans32k146 default or cyphal configure picked it up and failed
in prepend_bootloader.py: the S32K application loads at 0x6000, below
the 0x08000000 base the script and bl_update assume. CI only passed
because the canbootloader was built after both had configured.

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

* fix(bl_update): pad the image before erasing and warn on every flash failure

The STM32F4 up_progmem_write() returns -EINVAL for an odd byte count,
which was only found out after sector 0 had been erased. An erase or
program failure also leaves the board without a bootloader, but only a
verify failure told the user to retry before rebooting.

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

* fix(romfs): pack rc.board_bootloader_upgrade only where rcS runs it

CAN nodes with bl_update carried the script in their ROMFS although the
cannode rcS never sources it: uavcannode flashes the bootloader itself.

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

* refactor(bl_update): move the flash routine to src/lib

The library lived under systemcmds, which is configured after drivers,
so uavcannode could only link it through a forward reference. The
watchdog is now selected by chip because the platform targets do not
exist yet when src/lib is configured.

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

* docs(dronecan): the CAN bootloader is written to extras on STM32 only

Assisted-by: Claude:claude-fable-5-1
2026-10-06 15:42:33 -06:00
XiaoYang Chen 46a77d8ad1 fix oob bug in tests file2 module (#28586) 2026-09-28 10:09:20 -06:00
XiaoYang Chen c865dc9fde fix null pointer write in sd_stress (#28795) 2026-09-28 10:08:56 -06:00
Julian Oes c8a6cc3656 fix(tinybson): reject a negative document length (#28607)
The BSON document length is the first four bytes of the document and is signed.
bson_decoder_init_buf() checked it against the buffer size, but the check only
ran when the value was positive, so a negative length skipped it and decoding
proceeded with no bound. bson_decoder_init_file() did not check the length at
all.

Reject a negative length in both, and add a regression test, since the existing
BSON test only covers a round trip of data it encoded itself.

Reported by @lihnucs.

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

Signed-off-by: Julian Oes <julian@oes.ch>
2026-09-22 10:14:08 +12:00
Saibernard 5062588bff chore(tests): apply the review follow-ups from #28516 (#28651)
Shorten the cmake, cdev and gps_blending comments, drop the unreachable
snprintf clamp in test_uart_send and simplify the pure pursuit bearing
assertions to the absolute value with a 1e-6 tolerance, which covers both
sides of the +-pi cut. Cosmetic, no behaviour change.

Assisted-by: Claude:claude-fable-5

Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
2026-09-09 20:01:03 -06:00
SaibernardandFarhang 0d2c7058b3 fix(tests): build and run the unit test suite on macOS (#28516)
* fix(tests): use snprintf in test_uart_send

The macOS SDK marks sprintf deprecated, and PX4 builds with -Werror
-Wfatal-errors, so this is a hard build failure on macOS before any
test binary is produced:

  test_uart_send.c:83:7: fatal error: 'sprintf' is deprecated

The return value is used as the write() length and snprintf() returns
the length it would have written rather than what fit, so clamp it to
the buffer.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* fix(navigator): give publish_global_pos a float altitude parameter

The test helper declared its altitude parameter double, but it assigns
to vehicle_global_position_s.alt, which is float32, and all eight call
sites pass a float. Every call therefore promoted a float to double and
converted it straight back, which Apple Clang reports as
-Wdouble-promotion and -Werror turns into a build failure.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* fix(tests): use a double NaN for double latitude and longitude fields

The NAN macro is a float, so using it for a double lat/lon field is an
implicit float to double promotion. Apple Clang reports it under
-Wdouble-promotion and -Werror makes it fatal, so these tests could not
be compiled on macOS. Same class of fix as 25596.

Only genuinely double-typed fields are changed: altitude and the other
float members deliberately keep the plain NAN.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* fix(cmake): link the functional gtest stubs with -force_load on macOS

px4_add_functional_gtest() pulls in the daemon app-map stubs with GNU
ld's --whole-archive. Apple's ld64 has no such option and rejects the
link outright:

  ld: unknown options: --whole-archive --no-whole-archive

so every functional gtest failed to link on macOS. ld64 spells the same
thing -force_load <archive>.

test_stubs stays in the link library list on that path: a $<TARGET_FILE:>
inside a link flag does not make the executable depend on the archive, so
editing a stub would rebuild libtest_stubs.a without relinking the tests
that use it.

This affects the 40 px4_add_functional_gtest definitions across the tree.
Non-Apple platforms keep the existing flags unchanged.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* fix(cdev): take the px4_poll deadline from the semaphore's clock

macOS has no pthread_condattr_setclock(), so px4_sem_init() leaves the
condition variable behind px4_sem_t on its default CLOCK_REALTIME, while
px4_poll() built its absolute deadline from CLOCK_MONOTONIC.

On Darwin CLOCK_MONOTONIC counts from boot and CLOCK_REALTIME is the
epoch, so the deadline lands decades in the past: measured on one
machine the two clocks were about 56 years apart. pthread_cond_timedwait()
therefore returned ETIMEDOUT immediately and every px4_poll() with a
positive timeout returned without waiting. The teardown pass then
overwrote the result, so callers just saw px4_poll() == 0.

Take the deadline from CLOCK_REALTIME on Darwin builds without the
lockstep scheduler, which is the clock the wait actually uses. Lockstep
builds provide their own consistent simulated time and are untouched, as
are all other platforms; px4_poll() is the only POSIX caller of
px4_sem_timedwait().

Fixes the uORB poll timeouts in functional-test_mission_route_cache and
sitl-uorb_tests on macOS.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* test(pure_pursuit): compare bearings across the +-pi branch cut

Two cases asserted an exact -M_PI_F. The bearing there is 180 degrees,
which wrap_pi()'s [-pi, pi) range can legitimately represent as either
end, and on macOS the arithmetic lands 2 ULP below +pi. PX4 also builds
with -fno-signed-zeros, so the sign of an atan2f() result at the cut is
not portable in the first place.

Compare the wrapped difference instead, which treats +pi and -pi as the
same bearing, and give it a tolerance that survives the subtraction.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

* fix(gps_blending): accumulate the blended timestamp without truncating

Each weighted timestamp was cast to uint64_t before being added, so
every contributing receiver's term lost its fractional microsecond and
the blended timestamp came out low by up to one microsecond per
receiver. The normalised weights are floats, so their rounding error
biased the result further: two receivers reporting an identical
timestamp did not blend back to that timestamp.

Accumulate in double, divide by the accumulated weight, and round once.
The truncation is platform independent; gps_blending_test caught it on
macOS only because the float weights round differently there.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>

---------

Signed-off-by: Saibernard Yogendran <bernie97@seas.upenn.edu>
Co-authored-by: Farhang <46557204+farhangnaderi@users.noreply.github.com>
2026-09-08 22:25:45 -06:00
Claudio Chies e87918ea2b fix(failure_injection): keep failure names in sync with FailureInjection.msg (#28376)
unitName()/typeName() lacked the FAILURE_UNIT_DATALINK_*/FAILURE_UNIT_BUS_* units, so `failure can off` was announced as unit "unknown". FailureInjection.msg and VehicleCommand.msg also disagreed on FAILURE_TYPE_DRIFT (MAVLink FAILURE_TYPE 8).

Name every unit and type, add FAILURE_TYPE_DRIFT to both messages and the `failure` console command, and add a test that fails whenever a message constant has no name.
2026-09-07 09:16:38 -06:00
XiaoYang Chen fec216e9d7 fix oor bug in netman module (#28483) 2026-09-04 08:59:32 -06:00
Marin Doetterer 66f197b6ea fix(nshterm): went out of stack
fix(mavlink_shell): no echo of commands
2026-09-03 12:31:07 -07:00
Peter van der Perkandmarinauterion da60109091 fix(systemcmds/nshterm): echo input and consume enter
Enable ICANON and ECHO, and map CR to NL (ICRNL) so the nshterm console
echoes typed characters and processes the enter key.

Co-authored-by: marinauterion <224611774+marinauterion@users.noreply.github.com>
Signed-off-by: Peter van der Perk <peter.vanderperk@nxp.com>
2026-09-03 12:31:07 -07:00
Peter van der PerkandVille Juven 2ad35a4e73 feat(platforms): upgrade NuttX to 12.12.0
bootloader: update main prototype for NuttX 12.12.0

platforms/nuttx: Add wrapper for queue.h

For some reason the queue.h header was moved, add this wrapper so
posix and nuttx builds can both still use #include <queue.h>

Fix print_load to be compatible with upstream NuttX

Also Change tg_filelist -> tg_fdlist as per new NuttX

Co-authored-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2026-09-03 12:31:07 -07:00
XiaoYang Chenandgodess 7222a2cf82 fix the bug in sd_bench module (#28472)
Co-authored-by: godess <cxy2648680758@icloud.com>
2026-08-31 14:43:20 -06:00
Claudio Chies 6bfe60507d feat(failure_injection): add CAN bus failure injection (#28140) 2026-08-25 10:33:52 +02:00
Jacob Dahl 07463f4750 fix(i2c_launcher): default battery index from the -t argument (#28329)
The ctor tested uninitialized _batt_index instead of the parameter, so
`start -b 1` with no -t stored -1 and INA226 rejected it after the 1-3
index check. instances[] was indexed by 1-based bus number but sized as
the bus count, so bus == N wrote one past the end.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-08-24 12:56:21 -06:00
55bb872df1 feat(failure_injection): add ADS-B traffic failure injection and battery severity levels (#27950)
* feat(failure_injection): add ADS-B traffic-avoidance failure injection

Wire up FAILURE_UNIT_SYSTEM_TRAFFIC_AVOIDANCE (107) for the MAVLink-based
traffic avoidance path:

- OFF suppresses and STUCK freezes the incoming transponder_report, applied
  both at the MAVLink ADS-B ingestion (handle_message_adsb_vehicle) and at
  the navigator consumer (check_traffic), so it works for real ADS-B over
  MAVLink, simulated ADS-B and the fake_traffic command.
- OFF additionally marks the ADS-B/FLARM heartbeat unhealthy so the traffic
  avoidance system health check fails, using a message-less process()
  overload.
- Add the unit to the capability catalogue (OK/OFF/STUCK), the failure
  console command, the RC-switch unit selector and the docs.

The matching MAVLink FAILURE_UNIT enum entry lives in the mavlink submodule
(common.xml) and is handled by a separate PR; the uORB mirrors in
VehicleCommand.msg and FailureInjection.msg are included here.

* feat(failure_injection): enhance battery failure injection with severity levels

* feat(failure_injection): improve battery failure handling with dynamic threshold parameters

* refactor(failure_injection): remove traffic avoidance example from documentation

* docs(docs): subedit

* feat(failure_injection): add variance setting for distance sensor and integrate rangefinder in simulator

* feat(docs): add failure injection to release notes

* docs(docs): Add sim_mavlink back to heading

* fix(failure_injection): update default battery failure injection severity to Emergency

* docs(docs): get away from footnotes

* feat(failure_injection): enhance battery failure injection handling and update traffic unit support

* feat(failure_injection): add traffic avoidance handling tests and configurations

* [AUTO COMMIT] update EKF change indication

See .github/workflows/checks.yml for more details

* Apply suggestion from @hamishwillee

* feat(failure_injection): update failure types and handling for traffic avoidance and ESC telemetry

* fix(typo)

* [AUTO COMMIT] update EKF change indication

See .github/workflows/checks.yml for more details

* fix(docs): clarify notes on GPS and airspeed handling in failure injection documentation

---------

Co-authored-by: Claudio Chies <chiesc@chies.com>
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
2026-08-21 14:23:06 +02:00
alexcekay f7e7815e63 feat(ver): add command to compare population option 2026-08-20 11:34:01 +02:00
Jonas Peroliniandjonas 4b30b2b615 feat(navigator): Implement a full mission route cache (#27707)
* feat(navigator): cache complete mission route data

* refactor(navigator): pack mission requests into a single struct

* rework(navigator): set pending to false instead of full struct reset

* refactor(navigator): remove missionExceedsCacheLimit

* chore(navigator): clean comments

* perf(navigator): syncMissionItem do not fully restart if not needed

* refactor(navigator): better naming and remove unreachable retry

* refactor(navigator): comments

* refactor(navigator): do not restart from scratch on single read failure, restart from failure

* refactor(navigator): use navigator poll to load mission cache and move full mission cache into its own class

* perf(mission-cache): add perf counter for the full mission load

* fix(navigator): keep route cache in sync with DO_JUMP counters

* feat(navigator): add min rate for full navigator update

* docs(docs): add docs for mission route cache

* docs(docs): revert change to auto-generated file

---------

Co-authored-by: jonas <jonspero@me.com>
2026-08-13 16:54:56 +02:00
Balduin 5cb6fe5f9d feat(param): add bitset and bitclear commands
Currently we can only set such parameters to specific values, but we
cannot toggle on and off individual bits programmatically.

This allows us to modify only some bits of a param, while leaving others
the same. This is essential for parameters which:
 - are an int32 bitset
 - have some bits which should persist
 - have some bits which should take on a specified value

Motivating example here is EKF2_SENS_EN. With this we can replace the
current
    param set EKF2_GPS_CTRL 0  # Disable GPS Aiding on every boot
in airframes that expect spoofing by
    param bitclear EKF2_SENS_EN 3

This accomodates for the change in parameter semantics from
https://github.com/PX4/PX4-Autopilot/pull/26739 - see
src/modules/ekf2/EKF/common.h:

struct FusionSensor {
	bool enabled{false};   // runtime toggleable via MAVLink
	bool available{false}; // CTRL-param != disabled-value (functions as factory-setting)
	bool intended() const { return enabled && available; }
};

and the one we want to disable on every boot to escape spoofing is
enabled, not available.
2026-08-06 09:36:32 +02:00
Gennaro GuidoneandMatthias Grob e816025c3d feat(failure_injection): add ESC failure unit (off/wrong) with correct MAVLink semantics (#28088)
* feat(failure_injection): add process_esc() telemetry helper

Add a shared helper that applies the active FAILURE_UNIT_SYSTEM_ESC (106)
failures to an esc_status before it is published, matched per ESC by
esc_report.actuator_function: Off reports the ESC offline (clears its
esc_online_flags bit) so it reads as "completely non-responsive"; Wrong keeps
the ESC online but reports consistently wrong values. Mirrors process_battery();
a no-op stub keeps builds without the failure injection manager zero-cost.
Unit tested here.

* feat(failure_injection): inject ESC failures at the esc_status producers

Call process_esc() where esc_status is produced (UAVCAN ESC driver and SIH) so
injected ESC failures reach every consumer. Wire the ESC unit end to end: add
the "esc" key to the failure CLI and mark FAILURE_UNIT_SYSTEM_ESC as supporting
Off and Wrong. Regroup MOTOR to Off-only (actuation): its stuck/wrong were
never implemented, so stop advertising them.

* refactor(failure_detector): drop the misplaced ESC telemetry injection masks

FailureInjector mapped FAILURE_UNIT_SYSTEM_MOTOR Stuck/Wrong to ESC-telemetry
masks consumed by manipulateEscStatus() -- on the wrong MAVLink unit (telemetry
belongs to FAILURE_UNIT_SYSTEM_ESC) and dead code: manipulateEscStatus() has had
no callers since the ESC checks moved into escCheck. The equivalent behaviour
now lives on the ESC unit in process_esc (Wrong directly; the old zero+offline
"Stuck" as esc off). Remove the masks and the dead method; the motor-stop (Off)
path ControlAllocator consumes is unchanged.

* refactor(failure_injection): do the copy for the amneded esc_status in the process_esc() function

This results in a clearer interface with less lines to call and the same overhead of copying once.

* fix(failure_injection): add esc telemetry failure support for all simulation interfaces

* fix(failure_injection): zero a disconnected ESCs telemetry

It's not entirely realistic because the value would go stale in a real disconnect but better than just flagging it offline but still reporting new telemetry.

---------

Co-authored-by: Matthias Grob <maetugr@gmail.com>
2026-07-31 15:50:49 +02:00
Claudio ChiesandClaudio Chies d63f30c612 feat(failure_injection): Enable failure-injection on hardware, and through RC-switch (#27832)
* feat(failure_injection): integrate failure injection support across sensor drivers

* feat(failure_injection): enhance failure injection with RC switch support and instance bitmasking

feat(failure_injection): add disabled failure injection manager and system command support for v5x and v6x boards

* feat(failure_injection): add battery failure injection

Add a value-mutating apply-site for FAILURE_UNIT_SYSTEM_BATTERY. On an
injected OFF the outgoing battery_status is reported as a depleted pack
(zero remaining, emergency warning) so the low-battery failsafe triggers.

The apply-site lives in the shared Battery library, covering the analog
ADC, INA power monitors, ESC battery and SITL in one place, plus the
UAVCAN battery driver which publishes battery_status directly. The
previous SITL-only hack in BatterySimulator is removed in favour of this
shared path so simulation and hardware behave identically.

* fix(failure_injection): change parameter types from int32 to enum

* refactor(failure_injection): disable failure injection manager and system commands across multiple boards

* feat(failure_injection): enhance failure injection with timestamp handling and message-less support

* refactor(failure_injection): simplify has_timestamp_sample implementation and remove unused includes

* refactor(failure_injection):move conditional compilation into helper libary

* refactor(failure_injection): update CMakeLists to include failure_injection dependency across multiple drivers

---------

Co-authored-by: Claudio Chies <chiesc@chies.com>
2026-07-15 07:56:13 -07:00
Julian Oes bffa69a554 test(microbench): add perf_counter microbenchmark
Times perf_count and perf_begin/perf_end in tight loops with hrt, plus a
plain non-atomic counter loop as reference, to quantify the overhead of
the atomic perf_counter change. Run with: microbench microbench_perf
2026-07-02 08:42:49 -07:00
f937bd5818 refactor(failure_injection): centralize MAV_CMD_INJECT_FAILURE behind a manager module (#27572)
* feat(failure_injection): add failure_injection topic and helper library

* feat(failure_injection): add failure injection manager module

* refactor(commander): route motor failure injection through the manager

* refactor(simulation): route sensor sim failure injection through the manager

* refactor(simulation): route SimulatorMavlink failure injection through the manager

* feat(failure_injection): start the manager in the SITL startup

* docs(failure_injection): document per-simulator failure support

* feat(failure_injection): enhance failure injection management and configuration

* fix(rebase): baro failure injectionb

* refactor(failure_injection): simplify FailureInjectionManager and FailureTable implementations

* refactor(failure_injection): replace Subscriber with Config in various modules and add update method

* update(uorb): FailureInjection.msg to docs standard

* docs(docs): subedit

* fix(failure_injection): correct comment formatting in FailureInjection.msg

* feat(failure_injection): add failure injection manager support across multiple boards and modules

* feat(mavlink): implement failure injection functionality

---------

Co-authored-by: Claudio Chies <chiesc@chies.com>
Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
2026-06-30 15:33:39 +02:00
alexcekay 246484e91b feat(mtd): allow bulk erase 2026-06-24 15:32:44 +02:00
alexcekay 6f1f7035a5 feat(mtd): add NOR FLASH support 2026-06-24 15:32:44 +02:00
Jukka LaitinenandJukka Laitinen 3042f906ab feat(uORB): Add an own type, orb_sub_t, for subscription handles (#27457)
* platforms/common/uORB/uORB.h: Add definition for orb_sub_t and handle check functions

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>

* uORB: Change subscriber id:s from int to orb_sub_t

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>

* uxrce_dds_client: Change polling of transport device from px4_poll to poll

Use posix poll directly, there is no need to use px4_poll unless uORBs are
being polled.

The one used here is a normal filesystem/device poll, so we can use normal "poll",
this is the common pattern in the codebase.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>

* Fix linking for protected build

This fixes errors for memalign not linking on some configurations.
Memalign exists in nuttx kernel-side mm library and it may fail in configurations
where kernel and userspace are separated. This has no effect on other than
"CONFIG_BUILD_PROTECTED" or "CONFIG_BUILD_KERNEL" NuttX builds.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>

---------

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
Co-authored-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2026-06-23 09:13:51 -06:00
jonas 13e74de617 fix(test): testAsyncAbortAndReissue ensure stale reply is cleared 2026-06-16 07:56:40 +02:00
jonas 5fd7fed8d8 feat(dataman): handle zero-size cache and clear pending responses on new request 2026-06-16 07:56:40 +02:00
Jacob Dahl 88951f01e9 fix(parameters): self-initialize blank parameter storage at boot (#27623)
Flashing PX4 over another firmware (e.g. ArduPilot on an ARK FPV) or
first-booting a board with blank parameter storage played the error tune
on every boot: the param layer treated a blank store as corruption, and
the rcS recovery persisted with a file cp that is a no-op on
FLASH_BASED_PARAMS boards, so the store never became valid.

- param_import()/param_load() return 1 ("not yet stored") for a blank
  source - empty file, zeroed FRAM, or erased flash - on both the file
  and flash backends; a store that holds data but no valid entry (torn
  write, bit-rot, foreign data) is still reported as corrupt (-EILSEQ).
  The file backend detects a zero-length file via fstat (NuttX FAT
  cannot read() a 0-byte file: no cluster chain returns an error, not
  EOF) and otherwise inspects the leading BSON document length; the
  flash backend scans the whole store
- new 'param load-or-init <backup>' command: loads from the default
  storage; a blank store is seeded from the SD backup (or firmware
  defaults) and persisted so the next boot loads normally. A corrupt
  store, a backup that exists but cannot be opened or imported, or a
  result that cannot be persisted returns failure. The three-way
  loaded/blank/corrupt logic lives in C because nsh $? is a binary
  success flag. A failed backup seed does not reset to defaults, which
  preserves parameters loaded earlier in boot (e.g. factory calibration
  from /fs/mtd_caldata)
- rcS uses 'param load-or-init' instead of 'param import', and the
  corrupt-store recovery persists via 'param save' (works on
  flash-backed boards) only when the backup actually imported, so a
  corrupt backup keeps alerting the operator on the next boot
- commander ParamLoadDefault treats blank storage (1) as success and
  warns the GCS that parameters were reset to defaults, instead of
  reporting "Error loading settings"
- parameter_flashfs_init() in flashfs.c no longer reports a successful
  erase byte count as a failure (parity with flashfs32.c)

Tested with new blankImport and corruptImport cases in 'tests
parameters' (empty/zeroed/erased sources import as "not yet stored",
garbage fails to import); the CustomDefaults test now restores the
firmware default so the suite is repeatable within one boot.

The STM32H7 flash-erase DCACHE invalidate fix this depends on
(PX4/NuttX#381) is already in main's NuttX submodule.

Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
2026-06-12 14:06:10 +12:00
Elisa Ferrara ff4c0d7e4d test(microbench): add gravity() benchmark
Add an on-target microbenchmark for LatLonAlt::Wgs84::gravity(), the
Somigliana latitude-dependent gravity used by EKF2 (APX4-4273), to
bound its CPU cost on the flight controller.

Measured ~0.45 us/call on fmu-v6s (STM32H7). The value is cached and
only recomputed when latitude moves >1 deg, so the steady-state EKF
cost is unchanged.

Enabled on the fmu-v6s performance-test board. Run with:
  nsh> microbench microbench_gravity

APX4-4273
2026-06-09 14:38:34 +02:00
Julian Oes b48ec2dd68 feat(params): add board-level read-only parameter support (#26522)
Integrators can declare read-only parameters in a per-board YAML file:
readonly_params.yaml.

There are two ways to define the read-only params:
- "block": default writable, explicitly list params to be locked
- "allow": default readonly, explicitly list params to be writable

Enforcement is activated by `param lock` in rcS after all startup
scripts have run, so board defaults and airframe scripts can still set
params during init.

The feedback via MAVLink uses the new
MAV_PARAM_ERROR_READ_ONLY as part of the PARAM_ERROR message.
2026-04-27 09:06:43 +12:00
Julian Oes 174a6aab6f feat(mklittlefs): add command to format littlefs filesystems
Add an NSH command to format a device with littlefs, analogous to
mkfatfs for FAT filesystems. The command unmounts the mount point,
then remounts with forceformat to format and mount in one step.

Enable the command on boards that use littlefs as primary storage
(airbrainh743 and kakuteh7v2), and document it in the airbrainh743
flight controller page as a recovery procedure for a corrupted
flash filesystem.

Usage: mklittlefs /dev/mtd0 /fs/flash
2026-04-23 10:30:14 +12:00
Eric Katzfey 4917b17116 feat(voxl2): Added i2cdetect system command to voxl2-slpi build. Needed to implement the required i2c API for it.
Also, changed the printf into PX4_INFO so the output can be seen for Qurt platforms.
2026-04-08 08:52:25 -07:00
Nick c592af7e8e fix(parameters): show board_rot in show-for-airframe (#26989) 2026-04-07 11:48:52 -08:00
Niklas Hauser 9e0cd2fcf3 Fix mtd command for very small partition sizes of just 32B 2026-04-07 13:42:12 +02:00
Jacob Dahl 55ab880823 refactor(systemcmds/tests): convert params.c to module.yaml
Convert 1 parameter file(s) from legacy C format to YAML
module configuration.
2026-03-19 23:46:16 -08:00
Jacob Dahl ce3e62841f module_base: remove CRTP template pattern to reduce flash bloat (#26476)
* module_base: claude rewrite to remove CRTP bloat

* module_base: apply to all drivers/modules

* format

* fix build errors

* fix missing syntax

* remove reference to module.h in files that need module_base.h

* remove old ModuleBase<T>

* add module_base.cpp to px4_protected_layers.cmake

* fix IridiumSBD can_stop()

* fix IridiumSBD.cpp

* clang-tidy: downcast static cast

* get_instance() template accessor, revert clang-tidy global

* rename module_base.h to module.h

* revert changes in zenoh/Kconfig.topics
2026-02-19 15:17:17 +13:00
Ramon Roche d196d37ef2 clang-tidy: auto-exclude submodules and third-party code
Automatically generate the clang-tidy exclusion list from .gitmodules
so new submodules are excluded without manual intervention.

Changes:
- Makefile: Generate CLANG_TIDY_SUBMODULES from .gitmodules paths
- Makefile: Add CLANG_TIDY_EXCLUDE_EXTRA for manual exclusions:
  - src/systemcmds/tests (test code, looser style allowed)
  - src/examples (educational code, not production)
  - src/modules/gyro_fft/CMSIS_5 (vendored ARM DSP library)
- Delete src/systemcmds/tests/.clang-tidy (stale since 2019)
- Delete src/modules/gyro_fft/CMSIS_5/.clang-tidy (redundant)

Rationale: Submodules and vendored code should be linted in their
upstream repositories, not here. This reduces noise and focuses
clang-tidy on code that PX4 maintainers actually edit.

Contributors adding vendored (non-submodule) third-party code should
add their path to CLANG_TIDY_EXCLUDE_EXTRA in the Makefile.

Signed-off-by: Ramon Roche <mrpollo@gmail.com>
2026-02-12 21:20:27 -08:00
Matthias Grob cefa41f85c failure command: fix array bound seg fault with e.g. failure motor -i 1 2025-09-30 11:23:09 +02:00
Beat Küng 8370ae1701 test_dataman: remove invalid item tests
They caused ASAN failures. And since the dm_item_t is an enum, I don't
think it needs a test.
2025-07-11 10:39:28 +02:00
Peter van der Perk 65c180852f i2c_launcher: Dehardcode battery index 2025-05-22 12:09:05 -07:00
Alexander LerachandIgor-Misic 2356cb973f Performance & testing targets
* Added minimal configs for performance testing

* Rename recovery to performance

* added mfg_cfg

* fix params & don't inherit from default

* rename performance -> performance-test

---------

Co-authored-by: Igor-Misic <igy1000mb@gmail.com>
2025-02-24 16:02:46 +01:00
Silvan a1ff1d8372 tests: remove test_bezier
Signed-off-by: Silvan <silvan@auterion.com>
2025-02-18 14:33:16 +01:00
Julian Oes 091974e6c5 listener: only clear screen with multiple messages (#24019)
* listener: only clear screen with multiple messages

* listener: fully clear before printing again

Otherwise, we end up seeing artifacts from the previous print.
2024-12-11 10:00:36 +13:00
Julian Oes 746e26bf9e listener: clear screen on multiple output
I suggest to clear the screen when using the listener with -n.
This way the updates don't just scroll by which isn't legible but
instead stay in place and update, similar to the top command.
2024-11-21 11:56:23 -05:00
Matthias Grob c199a284f5 Fix output of param show -q XXX on NuttX shell (#23793)
* param: add a newline for the output of param show -q

Otherwise the output doesn't get flushed and doesn't show.

* param: remove deprecated PARAM_PRINT for QURT

We're not carrying platform defines in applications.
2024-11-04 19:30:21 -09:00
BazookaJoe1900 4d83badba1 fix files tags on the header comments (#23564) 2024-09-19 09:25:18 +03:00
Niklas Hauser ecfdbd2e60 littlefs: needs more stack when used 2024-08-19 11:05:50 -04:00