Skip to content

Conversation

peterbarker
Copy link
Contributor

Tested on a VM with esp32buzz.dat. The single line moved has effect (I added #errors to the code to make sure).

Modeled on similar patches made for the Linux HAL.

@tpwrules
Copy link
Contributor

tpwrules commented Aug 7, 2025

Could you try your hand at the esp32s3m5stampfly? That one I own and can flight test.

@peterbarker
Copy link
Contributor Author

Could you try your hand at the esp32s3m5stampfly? That one I own and can flight test.

Yes indeed. Bare in mind I was really only looking to move very minor things into here, so don't expect everything to move over!

I'm hoping the builds are repeatable in esp32-land. I don't suppose you know if they are? That would make the process of moving everything into the hwdef.dat files much cleaner/faster...

@peterbarker peterbarker changed the title Add and use esp32_hwdef.py to allow cration of hwdef.h from hwdef.dat Add and use esp32_hwdef.py to allow creation of hwdef.h from hwdef.dat Aug 8, 2025
@peterbarker
Copy link
Contributor Author

Could you try your hand at the esp32s3m5stampfly? That one I own and can flight test.

I've pushed a branch moves a single define over. Seems to work:

vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ ./Tools/scripts/extract_features.py /tmp/tmp75i6smwf/out-branch-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf --nm=xtensa-esp32-elf-nm | grep AIR
!AP_AIRSPEED_ANALOG_ENABLED
!AP_AIRSPEED_ASP5033_ENABLED
!AP_AIRSPEED_AUAV_ENABLED
!AP_AIRSPEED_DLVR_ENABLED
!AP_AIRSPEED_DRONECAN_ENABLED
!AP_AIRSPEED_ENABLED
!AP_AIRSPEED_MS4525_ENABLED
!AP_AIRSPEED_MS5525_ENABLED
!AP_AIRSPEED_MSP_ENABLED
!AP_AIRSPEED_NMEA_ENABLED
!AP_AIRSPEED_SDP3X_ENABLED
!AP_PERIPH_AIRSPEED_ENABLED
vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ 

A bunch of stuff isn't working (size_compare_branches.py) which I'll probably want working before moving a bunch of stuff over.

... something changed, however:

vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ cksum ./Tools/scripts/extract_features.py /tmp/tmp75i6smwf/out-*-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf
2593568385 28606 ./Tools/scripts/extract_features.py
1159079373 35391844 /tmp/tmp75i6smwf/out-branch-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf
1111509765 35397696 /tmp/tmp75i6smwf/out-master-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf
vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ ./Tools/scripts/extract_features.py /tmp/tmp75i6smwf/out-branch-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf --nm=xtensa-esp32-elf-nm >/tmp/new
vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ ./Tools/scripts/extract_features.py /tmp/tmp75i6smwf/out-master-esp32s3m5stampfly/esp32s3m5stampfly/esp-idf_build/ardupilot.elf --nm=xtensa-esp32-elf-nm >/tmp/old
divagrant@vagrant:/vagrant(pr/esp32-hwdef)$ diff -u /tmp/old /tmp/new
vagrant@vagrant:/vagrant(pr/esp32-hwdef)$ 

... probably need to make sure that board was built with the s3 compiler. Hmmm.

@tpwrules
Copy link
Contributor

tpwrules commented Aug 9, 2025

I am reasonably sure the whole env.py thing can go entirely. waf already handles that. It always bugged me that it wasn't a Python file and that's what my partial investigation concluded.

Concretely I wouldn't suggest putting in the effort to factor it out.

@peterbarker
Copy link
Contributor Author

I am reasonably sure the whole env.py thing can go entirely. waf already handles that. It always bugged me that it wasn't a Python file and that's what my partial investigation concluded.

Concretely I wouldn't suggest putting in the effort to factor it out.

I'd be very happy to rebase on top of a patch in master that removes it :-)

... in the meantime, it seriously irked me I was making a third copy of that method :-)

@peterbarker
Copy link
Contributor Author

@tpwrules any testing as yet?

@@ -137,6 +137,8 @@ def add_hwdefs_from_hwdef_dir(self, hwdef_dir):
board.toolchain = 'arm-linux-gnueabihf'
elif "ChibiOS" in hwdef_dir:
board.toolchain = 'arm-none-eabi'
elif "ESP32" in hwdef_dir:
board.toolchain = 'xtensa-esp32-elf'
Copy link
Contributor

@tpwrules tpwrules Aug 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? It is wrong for esp32s3. But the build works for it anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is a default value for which toolchain to use for the things in that hwdef dir. The vast majority of our Linux boards use arm-linux-gnueabihf, so you can see that default in there. However, several boards override with TOOLCHAIN entry in their hwdefs - navigator64 is an example of that. Moving the toolchain requirement out of the waf stuff and into the hwdefs is definitely something to look forward to - we'll probably want something close to the ChibiOS hwdef's MCU line or something as an abstraction instead of specifying TOOLCHAIN in the hwdef... but we'll see.

This entry isn't used for compilation, only for working out which nm to run, for example.

@tpwrules
Copy link
Contributor

Thanks for the patience. This does indeed build and fly on the Stamp Fly. I just tried a clean tree, did not try to change options or break anything.

I will come back and attack env.py later, I looked back at my notes and it was more complicated than I had remembered. So factoring it out is fine for now.

@peterbarker
Copy link
Contributor Author

@tpwrules are you happy enough with this to approve it? It's a foot in the door, at least.

@davidbuzz
Copy link
Contributor

davidbuzz commented Aug 21, 2025

just be aware that 9 months ago, as part of this mega-esp32- pr that never got merged I implemented a full version of this, mixed-in with the rest of the PR: #28514 . If I was doing it, I'd be pulling as many of the relevant bits from that PR as I could and/or perhaps just rebasing it and reducing the number of things it touches ... but i'm not, so this probably a step in the right direction for master.
that old mega PR has important things - its got a classic/s3 split, its got ap_periph on esp32s3 , its got hwdef.dat implemented enough to build targets with it ( while concurrently supporting the old-style build on a board-by-board basis, its got esp CAN drivers that at one point in the past worked , it also added --esp32 as a flag for configure_all.py please do get as much inspiration from there as u can/like.

@davidbuzz davidbuzz self-assigned this Aug 21, 2025
@davidbuzz davidbuzz removed their request for review August 21, 2025 00:02
@davidbuzz
Copy link
Contributor

I'm just an interested watcher from this point, dont wait for me to respond or anything.

@peterbarker
Copy link
Contributor Author

just be aware that 9 months ago, as part of this mega-esp32- pr that never got merged I implemented a full version of this, mixed-in with the rest of the PR: #28514 . If I was doing it, I'd be pulling as many of the relevant bits from that PR as I

I did look at pulling that stuff in. Unfortunately a lot has happened since then, notably factoring chibios_hwdef.py into a new hwdef.py. That allows this PR to have a pretty minimal extra footprint in terms of Python code to maintain, whereas the mega-PR was just chibios_hwdef.py copied sideways.

I can't commit to grabbing stuff in from the mega-PR - this is already some pretty epic yak-shaving as I'm trying to fix clang analysis warnings by removing ownptr, and the build system is making that problematic, this linux_hwdef.py and now esp32_hwdef.py.

Copy link
Contributor

@tpwrules tpwrules left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable enough. I disagree with the toolchain selection for esp32s3 in one case but haven't dug in to see what it breaks if anything; maybe the nm is compatible.

I have also not had a chance to look through the mega PR branch though I do agree it would be nice to take lessons from.

@peterbarker peterbarker merged commit cf9cce3 into ArduPilot:master Aug 22, 2025
117 of 119 checks passed
@peterbarker peterbarker deleted the pr/esp32-hwdef branch August 22, 2025 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

3 participants