Commit Graph
715 Commits
Author SHA1 Message Date
Peter BarkerandClaude Opus 5 12cf96348b hwdef: test alternative-function labels with one startswith
Three places looped over af_labels asking whether a label named an
alternative function, and none of them used the entry which matched.
str.startswith() takes a tuple of prefixes and does the whole test at
once, so ask it that way instead; two of the three are in
get_alt_function(), which is called for every pin line.

Processing all 443 ChibiOS hwdefs goes from 0.335s to 0.325s.  The
parse state of all 490 boards is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 19:24:04 +10:00
Peter BarkerandClaude Opus 5 df68c8cf0a hwdef: compile valid_type's peripheral-number regexes
valid_type() still ran nine uncompiled re.match() calls for every pin
line, cross-checking the peripheral number in a pin's type against the
one in its label.  Compile them once as class members.

Processing all 443 ChibiOS hwdefs goes from 0.35s to 0.32s.  The parse
state of all 490 boards is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 19:24:04 +10:00
Peter BarkerandClaude Opus 5 274aa0f44c hwdef: stop splitting each hwdef line three times
Every line was split into words three times over: once by
process_file() to see whether it was an include line, once by the
HAL-specific process_line(), and once again by the base
process_line() the HAL-specific one delegates to.

Have process_line() take the words the caller has already split out,
and only split in process_file() for lines which could be an include.
That takes the number of splits done to process all 443 ChibiOS hwdefs
from 140374 to 56389, and the time from 0.40s to 0.35s.

The parse state of all 490 boards, and the hwdef.h, ldscript.ld and
hw.dat generated for a sample of 14 boards and their bootloaders, are
unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 19:24:04 +10:00
Peter BarkerandClaude Opus 5 c5ce5fd3f6 hwdef: compile the pin-type regex once, cache MCU modules
valid_type() rebuilt an 18-entry list of patterns and ran up to 18
uncompiled re.match() calls for every pin line in every hwdef.  Compile
the alternation once as a class member instead.

get_mcu_lib() called importlib.import_module() every time, which is
also once per pin line; remember the module we found.

Together these take processing all 443 ChibiOS hwdefs from 0.45s to
0.40s.  The parse state of all 490 boards is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 19:24:04 +10:00
Peter BarkerandClaude Opus 5 842aa07984 hwdef: avoid shlex when splitting simple hwdef lines
shlex is a character-at-a-time lexer written in Python, and it
dominated the cost of processing hwdefs: 65% of the time spent parsing
all 443 ChibiOS hwdefs was inside shlex.split().

Almost no hwdef line needs it.  A line containing none of shlex's
special characters, whose whitespace is only spaces and tabs, is split
identically by str.split(); 99.1% of the lines the parser sees qualify.
Take that path when it applies and fall back to shlex otherwise.

Processing all 443 ChibiOS hwdefs goes from 1.39s to 0.45s.  The parse
state of all 490 boards, and the hwdef.h, ldscript.ld and hw.dat
generated for a sample of 13 boards and their bootloaders, are
unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-07 19:24:04 +10:00
Peter BarkerandClaude Sonnet 4.6 df1706cf8d AP_HAL_ChibiOS: remove ALLOW_ARM_NO_COMPASS from betaflight conversion script
ALLOW_ARM_NO_COMPASS has not had the stated effect since Nov 2019; remove it from
the template output of the betaflight hwdef conversion script.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-08-05 11:54:44 +10:00
Huibean 5e4815bb09 AP_HAL_ChibiOS: Fix missing CAN3 2026-07-21 09:23:15 +10:00
Andy Piper abffee1520 AP_HAL_ChibiOS: support I2Cv4 single DMA channel
The ChibiOS I2Cv4 LLD (used on STM32G0/G4/C0/U0/U3/H5/L4+) uses a
single DMA channel per I2C peripheral, shared between TX and RX,
configured via STM32_I2C_I2Cx_DMA_CHANNEL. The previous code
emitted the separate STM32_I2C_I2Cx_RX/TX_DMA_STREAM defines used
by I2Cv2/I2Cv3, which no longer satisfy the I2Cv4 driver.

Detect I2Cv4 MCUs from CHIBIOS_PLATFORM_MK, allocate a single DMA
channel per I2C peripheral in dma_resolver.py (no _RX/_TX split),
and generate HAL_I2Cn_CONFIG entries that feed the single channel
into the shared DMA slot with SHARED_DMA_NONE as the partner.

Also replace the unconditional STM32_I2C_USE_I2Cn TRUE lines in
stm32g4_mcuconf.h with #ifndef-guarded defaults to FALSE, so
boards only enable the I2C peripherals their hwdef actually uses.
Without this, the I2Cv4 driver demanded DMA channels for every
I2C peripheral on every G4 board regardless of pin usage.
2026-05-22 16:46:21 +10:00
Andrew TridgellandClaude Opus 4.7 dc540c2a51 AP_HAL: hwdef: move ROMFS parsing into base class
The ROMFS / ROMFS_WILDCARD / ROMFS_DIRECTORY hwdef keywords were
previously only understood by the ChibiOS hwdef parser, which has
duplicated implementations of romfs_add / romfs_wildcard / romfs_add_dir
and a write_ROMFS step that publishes env_vars['ROMFS_FILES']. Lift
all of that into the base HWDef class so any HAL with a hwdef parser
(SITL, future HALs) gets ROMFS handling for free.

  - Base hwdef.py owns self.romfs, the romfs_*() methods, the
    ROMFS / ROMFS_WILDCARD / ROMFS_DIRECTORY process_line cases,
    the undef ROMFS handler, and write_ROMFS(); base run() calls
    write_ROMFS() at the end so subclasses that don't override run()
    publish ROMFS automatically.
  - ChibiOS keeps a thin romfs_add_dir() override solely for its
    bootloader-build no-op guard; everything else is inherited.

No behaviour change for ChibiOS boards.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 17:08:34 +10:00
Peter Barker 16267741ad AP_HAL_ChibiOS: prevent normal boards from using AP_PERIPH_* defines 2026-05-06 17:48:58 +10:00
Norihiko Itou f849f36b40 hwdef: add ADC2 and ADC3 map to scripts of STM32H755xx 2026-04-14 09:40:21 +10:00
Christian Clauss cc4f8d6ee2 AP_HAL_ChibiOS: Use dict.item() to get both keys and values 2026-03-25 20:06:49 +11:00
Peter Barker 60e8ddf5ed AP_HAL_ChibiOS: add and use AP_BARO_CALIBRATION_ENABLED 2026-03-17 12:50:13 +13:00
Christian Clauss 70b9e3b4d7 AP_HAL_ChibiOS: Add default ruff rules 2026-03-16 11:20:18 +11:00
Peter Barker fcb19e3b63 AP_HAL_ChibiOS: correct Python import lines for ruff correctness 2026-03-14 20:08:01 +11:00
Iampete1 e27e9ad8b9 ChibiOS: default AP_SERVO_TELEM_ENABLED to 0 on periph 2026-02-18 23:16:53 +11:00
Randy Mackay e7223ecaaa AP_HAL_ChibiOS: battery_bms disabled by default 2026-01-08 10:23:59 +09:00
Huibean 8a902fe7eb AP_HAL_ChibiOS:active VM-L431-SRV-Hub-4CHP for servo VCC current monitor 2025-12-09 10:30:00 +11:00
Norihiko Itou bc9cadd126 hwdef: modify RAM map to scripts of STM32H755xx for Ethernet 2025-12-08 09:38:46 +00:00
Andrew Tridgell bee76fc36e HAL_ChibiOS: disable AP_Filesystem_FATFS in bootloader
not needed
2025-11-26 21:31:31 +00:00
Peter Barker 38e93e44f3 AP_HAL_ChibiOS: fix Python warning about unexpected escape sequences
... i.e. mark a regex string as a regex string
2025-11-26 20:44:35 +11:00
Peter Barker a510631a15 AP_HAL_ChibiOS: add STM32H753xx.py 2025-11-04 09:47:58 +11:00
Peter Barker dcc7c12fff AP_HAL_ChibiOS: fix instances of flake8 B006 error
e.g.:

./Tools/autotest/vehicle_test_suite.py:8607:89: B006 Do not use mutable data structures for argument defaults.  They are created during function definition time. All calls to the function reuse this one instance of that data structure, persisting changes between them.
2025-10-28 20:19:01 -05:00
Peter Barker fb8dc7eb2d AP_HAL_ChibiOS: rename HAL_PROBE_EXTERNAL_I2C_COMPASSES to AP_COMPASS_PROBING_ENABLED
... and force it to have a value, not just be defined
2025-10-27 18:24:18 -05:00
Thomas Watson 3cf2888747 AP_HAL_ChibiOS: keep better track of processed_defaults.parm
Don't get its path unless we are about to generate it to avoid an
inaccurate list of generated files. Do this by keeping track of the path
in a variable instead of checking for the result on the filesystem.

This is somewhat strange and mixed in with the romfs file and
AP_Param.cpp, to disentangle later...
2025-10-20 22:31:44 +11:00
Thomas Watson 973cc7eb6e AP_HAL_ChibiOS: keep track of hwdef.py generated files
This will allow waf to avoid cleaning them and avoid unnecessary
regenerations.

Some slight changes to centralize the use of the output directory are
also performed.
2025-10-20 22:31:44 +11:00
Andy Piper 6e86351aeb AP_HAL_ChibiOS: add support for idle-hook based true CPU load
allow idle stats to be turned off
2025-10-16 06:20:54 +11:00
Thomas Watson d04903ad18 AP_HAL_ChibiOS: don't generate no-longer-used env.py 2025-10-06 08:02:36 +11:00
Thomas Watson f47c443c06 AP_HAL_ChibiOS: fix hwdef processor default parameter path source
Read from the passed in variable instead of the global args object. By
default the variable is set to the args object's contents so there is no
change in behavior.

Note that much of this logic is fishy and/or wrong; that is preserved
and left to be fixed another day.
2025-10-06 08:02:36 +11:00
Peter Barker c57d98ea6d AP_HAL_ChibiOS: add define so user can omit AP_Vehicle bindings 2025-10-01 18:05:38 +10:00
Peter Barker f622ede250 AP_HAL_ChibiOS: remove bad defines of DISABLE_SERIAL_ESC_COMM 2025-09-21 22:35:32 -05:00
Peter Barker 700ca1607d AP_HAL_ChibiOS: remove unused define HAL_NO_GPIO_IRQ
... and make sure it does't come back.

I can't find where we ever actually used this, it's not been used for many years
2025-09-21 22:35:32 -05:00
Peter Barker d0af7e56d1 AP_HAL_ChibiOS: add stale defines checking
keeps these out of the main codebase which is nice, but also means we can catch these at configure-time rather than build time, which means CI will catch them
2025-09-21 22:35:32 -05:00
Peter Barker 95f40f8f6d AP_HAL_ChibiOS: stop defining HAL_USE_EXT and HAL_NO_CCM
these aren't used anywhere in the codebase
2025-09-19 06:43:09 +10:00
Iampete1 4eb90cc652 AP_HAL_ChibiOS: periph: check for existing define for serial protocols 2025-09-18 16:17:07 +10:00
Peter Barker c52891c06b AP_HAL_ChibiOS: break out a write_device_table method 2025-09-03 11:54:13 +01:00
Peter Barker ece5cec062 AP_HAL_ChibiOS: add and use AP_SIM_VICON_ENABLED
this doesn't compile on sim-on-hardware when debugging is enabled (stack frame too large)
2025-07-29 10:12:11 +10:00
Thomas Watson d0b7387752 AP_HAL_ChibiOS: disable GPIO interrupt callbacks in bootloader build
Saves several hundred bytes by not including unused ISRs.
2025-07-29 10:09:21 +10:00
Shiv Tyagi cd81a40d28 AP_HAL_ChibiOS: add HAL_EFI_ENABLED as a dependency of AP_PERIPH_EFI_ENABLED 2025-07-24 12:21:31 +10:00
Peter Barker 3708936c62 global: correct shebang lines to refernce python3
also remove the odd encoding line which is not required in Py3
2025-07-22 10:45:57 +10:00
Shiv Tyagi c3747f0eba AP_HAL_ChibiOS: add HAL_PROXIMITY_ENABLED as a dependency of AP_PERIPH_PROXIMITY_ENABLED 2025-07-19 11:45:35 +10:00
Shiv Tyagi 261f9ed9b2 AP_HAL_ChibiOS: add AP_PERIPH_RTC_ENABLED as a dependency of AP_PERIPH_BATTERY_TAG_ENABLED 2025-07-17 08:32:14 +10:00
Shiv Tyagi c191cc14db AP_HAL_ChibiOS: add AP_RELAY_ENABLED as a dependency of AP_PERIPH_RELAY_ENABLED 2025-07-11 14:51:36 -07:00
Shiv Tyagi 545fb09c1c AP_HAL_ChibiOS: add HAL_MSP_ENABLED as a dependency of AP_PERIPH_MSP_ENABLED 2025-07-08 23:07:23 +10:00
Shiv Tyagi da095c7312 AP_HAL_Chibios: enable AP_TEMPERATURE_SENSOR_ENABLED based on AP_PERIPH_DEVICE_TEMPERATURE_ENABLED 2025-07-05 21:34:38 -05:00
Peter Barker d225ee987d hwdef: turn off Sum backend on AP_Periph
default is to not have that many backends...
2025-07-03 09:12:20 +10:00
Peter Barker 5315491cc3 AP_HAL_ChibiOS: tidy remaining AP_SIM_ defines 2025-07-02 17:27:59 +10:00
Shiv Tyagi c8ccdbb972 Tools: remove AP_PERIPH_AHRS_ENABLED 2025-06-27 09:28:16 +10:00
Andy Piper e2b710eb55 AP_HAL_ChibiOS: always provide default IMU in betaflight conversion 2025-06-24 17:05:03 +01:00
Christian Clauss 662c8f9ed7 hwdef: Add # flake8: noqa linter directive 2025-06-20 20:30:15 +10:00