PX4-Autopilot icon indicating copy to clipboard operation
PX4-Autopilot copied to clipboard

ESP32 Support Sponsored by AutonoSky

Open henrykotze opened this issue 7 months ago • 15 comments

Support for ESP32 Sponsored by AutonoSky

  • [x] PWM Tested I have tested the PWM outputs using Digital Logic Analyser. They perform as expected, if the Timer frequency is below 250Hz.

  • [x] Logger Tested I have hooked up a SPI based SD card, and have logged succesfullly

  • [x] I2C Tested airspeed sensors communicated over I2c i2cdetect works as expected

  • [x] UART GPS driver works as well as mavlink communication

  • [x] Parameters Able to save and read parameters using SPIFlash

  • [x] Wifi Wifi is working in a minimal state. Able to see wifi hotspot, and able to connect, and send mavlink over Wifi, but there are some setup to get this working. This is on a different branch, currently being worked on. Will push this onto this branch as well.

Known bugs:

  • htop causes segmentation fault. Haven't had time to inspect this
  • the pinout defined in the menuconfig needs to match those being setup in the board directory. (This isn't really a bug, but more unnecessary setup which I haven't had time to clean up)
  • nsh console over mavlink - the terminal hangs when logging in over wifi
  • A minimal nuttx patch required. Will attach here.
  • I had to adjust the stack size for multiple modules
  • We had to use a specific version of esptool and xtensa compilers: Using esptool v4.7.0 xtensa-esp-elf-gcc (crosstool-NG esp-13.2.0_20240530) 13.2.0

There might be additional bugs, which I can think of now, but just wanted to get this WIP out so long.

make espressif_esp32
esptool.py --chip esp32 -p /dev/ttyUSB0 -b 921600 --before=default_reset --after=hard_reset write_flash --flash_mode "qio" --flash_freq "80m" --flash_size "detect" 0x1000 ./boards/espressif/esp32/boot/bootloader.bin 0x8000 ./boards/espressif/esp32/boot/partition-table.bin 0x10000 ./build/espressif_esp32_default/espressif_esp32_default.bin 

git apply the following patch in the nuttx directory: esp32-wifi-support.txt

henrykotze avatar May 20 '25 14:05 henrykotze

Wifi should be working now: Should be able to see the hotspot: px4-esp32 and the password is: "px4-esp32"

on the nsh-console you should be able to see the network device by the command: ifconfig

start the dhcpd server by: dhcpd_start which will then give your computer an IP

image

  • Access the nsh-console via usb with baudrate 115200 screen /dev/ttyUSB0 115200

henrykotze avatar May 26 '25 15:05 henrykotze

Something which I would like to get working is able to connect to the hotspot and login into the nsh-console via mavlink.

henrykotze avatar May 26 '25 15:05 henrykotze

Does this impact the docs at all? https://docs.px4.io/main/en/telemetry/esp32_wifi_module.html#esp32-wifi-module

hamishwillee avatar May 28 '25 00:05 hamishwillee

Hi Hamish,

This doesn't affect ESP-based boards used solely for Mavlink telemetry over WiFi (e.g., DroneBridge ESP).

If the PR is merged, we could add a note to clarify for new developers that flashing PX4 on an ESP32 dev board isn't meant to replace DroneBridge, but provide more functionality like controlling a subsystems on a drone. (make use of GPIOs, PWM, ect)

The intent of this PR is to enable PX4 on an ESP32 acting as a controller for a subsystem on a drone, where you would like to make use of the wireless connectivity to connect to an another device(phone). Or using the ESP32 as a microcontroller for testing equipment, where you can enable "PX4 testing modules" over Wifi which enable you to be far away from possible dangerous testing equipment.

I hope this provide some clarity.

henrykotze avatar May 28 '25 09:05 henrykotze

To connect to esp32 nsh console over mavlink;

once logged in over USB into nsh console

logger stop
mavlink stop-all
dhcpd_start wlan0
mavlink start -u 14550 -o 14550 -m 0 -r 1000 -x -p -s -x

Then you connect to the Wifi Hotspot px4-esp32, and then we can connect over the WiFi using the the command: ./Tools/mavlink_shell.py 10.0.0.255:14550

However the Shell opens and then just hangs, not responding, but I can still navigate on the nsh console via USB image

henrykotze avatar May 28 '25 12:05 henrykotze

Manage to login into the nsh-console via mavlink over Wifi image

henrykotze avatar May 30 '25 12:05 henrykotze

@davids5 is the CI broken?

acassis avatar Jun 05 '25 21:06 acassis

ping @mrpollo

acassis avatar Jun 05 '25 21:06 acassis

Thanks @acassis for bringing attention to the PR.

I think the CI is broken due to not having the xtensa compilers in its path -> I think the docker image needs to be updated with the xtensa compilers to build it successfully.. I have added it to setup.sh script in the setup folder.

However, I will need to make another PR on the nuttx side for it to compile succesfully -> will do this once the CI starts compiling esp related code.

henrykotze avatar Jun 06 '25 04:06 henrykotze

Got the ESP32 to work in the same fashion as the ESP Dronebridge image

henrykotze avatar Jun 06 '25 07:06 henrykotze

I hope this provide some clarity.

Thanks @henrykotze Yes it does. I think you'd probably provide a completely different document - this is no longer a Telemetry module in this context. Not sure where though - but probably in https://docs.px4.io/main/en/hardware/drone_parts.html

When this goes in create a doc anywhere you like and apply the Documentation label and I'll look at it and find a home.

hamishwillee avatar Jun 11 '25 00:06 hamishwillee

FMUv5X

   FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +8  +0.0%      +8    .text
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  -0.0%      -5  [ = ]       0    .debug_line
   +40%      +2  [ = ]       0    [Unmapped]
  -0.0%      -7  [ = ]       0    [section .debug_line]
  -0.1%      -8  [ = ]       0    [Unmapped]
  +0.0%     +48  +0.0%      +8    TOTAL

FMUv6X

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  -0.0%      -5  [ = ]       0    .debug_line
   +67%      +2  [ = ]       0    [Unmapped]
  -0.0%      -7  [ = ]       0    [section .debug_line]
  +0.0%     +48  [ = ]       0    TOTAL

mrpollo avatar Jun 11 '25 15:06 mrpollo

Hey @henrykotze we love this contribution and want to help you get this merged as soon as possible, the only thing we gotta be careful with is the build tooling, we should make sure it's platform specific and doesn't leak into the build tooling for the overall system otherwise its going to become a maintenance burden on everyone.

@dagar can you please comment on the proposed build changes in this PR?

mrpollo avatar Jun 11 '25 15:06 mrpollo

This pull request has been mentioned on Discussion Forum for PX4, Pixhawk, QGroundControl, MAVSDK, MAVLink. There might be relevant details there:

https://discuss.px4.io/t/px4-dev-call-june-11-2025-team-sync-and-community-q-a/45976/1

DronecodeBot avatar Jun 11 '25 16:06 DronecodeBot

Thanks @mrpollo, I have capacity to work on any feedback as needed. :+1: I totally agree that the build process should remain unaffected for other architectures. I will start inspecting the bloaty report and getting zero changes.

henrykotze avatar Jun 12 '25 05:06 henrykotze

Using the mac address as UUID and chip revision is now implemented

image

henrykotze avatar Jul 01 '25 06:07 henrykotze

@mrpollo I assume i will need to add the Xtensa Compilers to PX4-Containers (https://github.com/PX4/PX4-containers/tree/master) for the Workflow's to start compiling the esp32 board.

Can you point me in the right direction to start adding it in?

henrykotze avatar Jul 04 '25 06:07 henrykotze

Hey @henrykotze, the container image we're using for building is now hosted in this repository. It's the px4-dev image, which can be built on demand. It picks up dependencies from ubuntu.sh (so you are already covered).

The issue here is that this becomes a chicken-and-egg problem, where we need to have the container updated so that the target is built in CI. Here's my proposal:

  • Disable the build target from this PR (add to the list here)
  • We merge once CI is passing with this build target disabled
  • I create a new px4-dev container on demand and publish.
  • We submit a PR that enables the build target (removes from the exclude list) and updates the container for this workflow

What do you think?

mrpollo avatar Jul 17 '25 16:07 mrpollo

@mrpollo Yes that sound perfect to me. :+1:

The one blocking issue I see, is that I will need to create a PR to PX4 Nuttx. I will then start getting that PR ready, alongside your first bullet point. Once these are ready I will ping you again.

henrykotze avatar Jul 18 '25 06:07 henrykotze

That sounds great; just let me know when you're ready, and I'll help you cross the finish line.

mrpollo avatar Jul 18 '25 16:07 mrpollo

@mrpollo ready to take this further.

~~PR in PX4 Nuttx is up(https://github.com/PX4/NuttX/pull/342), so once that is in, the runners will compile successfully~~

henrykotze avatar Jul 22 '25 14:07 henrykotze

@mrpollo Now it compiles without any changes on PX4 Nuttx.

henrykotze avatar Aug 15 '25 12:08 henrykotze

@henrykotze Congrats on getting this in.

Reminder that docs would be great so that people can discover this feature and know how to use it. As I understand it, this is a way to run PX4 on ESP32. Therefore I think what is needed is a flight controller page like https://docs.px4.io/main/en/flight_controller/beaglebone_blue.html or https://docs.px4.io/main/en/flight_controller/holybro_pix32_v5.html , probably under "Experimental Autopilots".

hamishwillee avatar Sep 11 '25 07:09 hamishwillee

@hamishwillee Agreed, I will get on this.

henrykotze avatar Sep 11 '25 08:09 henrykotze