Skip to content

Conversation

henrykotze
Copy link
Contributor

@henrykotze henrykotze commented May 20, 2025

Support for ESP32 Sponsored by AutonoSky

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

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

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

  • UART
    GPS driver works as well as mavlink communication

  • Parameters
    Able to save and read parameters using SPIFlash

  • 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) fixed
    - nsh console over mavlink - the terminal hangs when logging in over wifi: fixed
    - A minimal nuttx patch required. Will attach here.: fixed
    - I had to adjust the stack size for multiple modules : for now i removed any modules from the board config which required stacksize increase, to minimize the intrusion of this PR
  • 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 henrykotze force-pushed the autonosky/esp32-support branch from eb00f4b to be8f8c5 Compare May 26, 2025 05:52
@henrykotze
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@hamishwillee
Copy link
Contributor

@henrykotze
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@henrykotze henrykotze force-pushed the autonosky/esp32-support branch from bcdcd4d to f9ed910 Compare June 3, 2025 04:45
@henrykotze henrykotze changed the title [WIP] ESP32 Support Sponsored by AutonoSky ESP32 Support Sponsored by AutonoSky Jun 3, 2025
@acassis
Copy link

acassis commented Jun 5, 2025

@davids5 is the CI broken?

@acassis
Copy link

acassis commented Jun 5, 2025

ping @mrpollo

@henrykotze
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@hamishwillee
Copy link
Contributor

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.

@mrpollo
Copy link
Contributor

mrpollo commented Jun 11, 2025

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
Copy link
Contributor

mrpollo commented Jun 11, 2025

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?

@DronecodeBot
Copy link

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

@henrykotze
Copy link
Contributor Author

Thanks @mrpollo, I have capacity to work on any feedback as needed. 👍 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
Copy link
Contributor Author

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

image

@henrykotze
Copy link
Contributor Author

@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?

@mrpollo
Copy link
Contributor

mrpollo commented Jul 17, 2025

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?

@henrykotze
Copy link
Contributor Author

@mrpollo
Yes that sound perfect to me. 👍

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.

@mrpollo
Copy link
Contributor

mrpollo commented Jul 18, 2025

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

@henrykotze
Copy link
Contributor Author

henrykotze commented Jul 22, 2025

@mrpollo ready to take this further.

PR in PX4 Nuttx is up(PX4/NuttX#342), so once that is in, the runners will compile successfully

@henrykotze henrykotze force-pushed the autonosky/esp32-support branch from 5a93cb3 to 7958676 Compare August 15, 2025 12:20
@henrykotze
Copy link
Contributor Author

henrykotze commented Aug 15, 2025

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

@henrykotze henrykotze force-pushed the autonosky/esp32-support branch 2 times, most recently from 4e62139 to 1a7ad11 Compare August 15, 2025 13:46
mrpollo
mrpollo previously approved these changes Aug 15, 2025
nsh console running on USB
param module running
working with i2c and common drivers
provided implementation for drv_pwm_output.h
i2cdetect working as expected with no device
mavlink started succesfully
mounts sd card and logger runs
logger to file succesfully
pwm_servo implemented without using Nuttx lib
pwm_out outputs expected waveforms
- however currently if the frequency is higher than what the pwm_out
driver runs, there will be aliasing, based on how the registers gets
resets
wifi softap working
- Seeing wifi hotspot
- cant connect due to wrong password
- problems with adjusting ssid and password
wifi ssid and password being set accordinglu
connected to wifi hotspot with dhpcd
- made some changes to nuttx to only build for SoftAP mode, however this
was effectivelyy removing the ifdef for STATION mode. Should investigate
the coexist option again
added ifdef to not use timer 0 when wifi enabled
- reverted esp32 rt_timer to make use of timer 0 by default

fix setting incorrect bit in hrt timer register

- hrt running as expected, but on startup the pwm_out driver starts up
at about 200Hz and then rises over a minute or so 250Hz. Not sure if
this was present previously, and could be due to Wifi running at time
priority on timer 0

pull xtensa compilers in setup.ubuntu.sh
revert logger stacksize and cmake argument
esp32 chip revision and PX4 UUID implemented

spi board reset implemented, formatting checked

devkit acts on startup as a wifi bridge for comms

- the most usefull setting for the general developer when buying a esp32 devkit
- testing Mavlink shell using ./Tools/mavlink_shell.py
- todo: Test mavlink messages being forward

improve wifi telemetry by increasing prio

- Remove power save mode on wifi
- increased daemon thread schedule priority to 50

compiles without Nuttx changes

- updated compiler settings to match those of nuttx on px4 side

add espressif_esp32 to excluded boards

ci: allow docker to find xtensa compilers
@mrpollo mrpollo merged commit 8b58c01 into PX4:main Aug 19, 2025
71 checks passed
@henrykotze henrykotze deleted the autonosky/esp32-support branch August 20, 2025 03:38
@hamishwillee
Copy link
Contributor

@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".

@henrykotze
Copy link
Contributor Author

@hamishwillee
Agreed, I will get on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants