Hello PX4 community,
I just acquired a MacBook Pro with M4 Apple silicon (Sequoia 15.5) and wanted to document how to compile the older version of PX4 for Nuttx based hardware, namely v1.12. The newer version v1.15 also compiles fine with this setup.
Notes
Note: I’m not able to compile posix SITL, nor Gazebo for now. I’ll update the post if progress is made.
Spoiler alert: to compile an older version version of the code, we need older tools.
Three Major Tools
There are three major tools we need to install: python, arm-none-eabi-gcc compiler, and cmake. And the newest versions did not allow me to compile PX4 v1.12. On my old machine that compiled fine, I had
- python 3.6.15
- arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
- cmake 3.31.2
Step by step
If we jump straight to the documentation for PX4 v1.12 MacOS Development Environment, there is a couple of relevant info and a couple of outdated info.
- Open the Terminal using Rosetta: yes we need to do that. (Bummer, I was not able to duplicate the Terminal). Verify this by typing
archin the Terminal which should returni386. Keep the terminal with Rosetta for this entire tutorial and whenever you will compile PX4 from the Terminal. - Homebrew Installation: yes, we’ll need that.
/bin/bash -c “$(curl -fsSL ``https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh``)” - Enable more open files: yes, let’s do that.
open ~/.zshenvand add at the end of the fileulimit -S -n 2048. (Add an empty line at the end of the file). Then save and close. Then typesource ~/.zshenvto apply the changes.- Enforce Python Version: let’s do it so the next step doesn’t crash, although we don’t need that.
open ~/.zshrc- Add
alias pip3=/usr/bin/pip3at the end of the file. Then add an empty line. Save and close the file. source ~/.zshrc
- Enforce Python Version: let’s do it so the next step doesn’t crash, although we don’t need that.
- Common Tools, installing
px4-devfrom Homebrew… This one will install the newest version of the tools which is not what we want. However, it might also install tools that we need. Some tips from the PX4 dev team would be appreciated.- I personally did install everything using
brew tap PX4/px4andbrew install px4-dev, then ended up removing cmake and arm-none-eabi-gcc. brew uninstall arm-none-eabi-gccbrew uninstall cmake
- I personally did install everything using
Python
- Instead of the Python installation, we will follow this tutorial on How to install multiple Python on your Mac. My machine came with Python 3.9.6 which is needed by other apps. So I don’t want to delete it. I also want to install the older version as 3.9.6 does not allow me to compile PX4 v1.12. Here is a little recap if ever the link becomes broken.
brew install pyenvpyenv install --list, from the list we hopefully see 3.6.15.pyenv install 3.6.15pyenv global 3.6.15, to make it global. As I understand, PX4 cannot be compiled in virtual environment, so we need to set it globally.- Let’s try
python --versionwhich in my case did not return 3.6.15. A little conversation with my favorite AI friend fixed it by adding these 3 lines to zshopen ~/.zshrc(similar to step 3.)export PYENV_ROOT=“$HOME/.pyenv”
export PATH=“$PYENV_ROOT/shims:$PATH”
eval “$(pyenv init --path)”- Another
source ~/.zshrcto apply the changes andpython --versionnow returnsPython 3.6.15. Hourrah! Let’s take a deep breath…
- To install the python packages, we can use what is proposed in the documentation, with
python3 -m pip install --user, I just added a little twist to ensure empy version 3.3.4 otherwise you might run into theRAW_OPT error, see this post. So the full command ispython3 -m pip install --user pyserial empy==3.3.4 toml numpy pandas jinja2 pyyaml pyros-genmsg packaging
ARM compiler
- Then, I installed arm-none-eabi-gcc 9-2020-q2-update, I downloaded the .pkg Mac OS X 64-bit Package (Signed and notarized). Then double-click and install. Super! But the location was not added to the PATH. I looked for it with the command
sudo find / -name "gcc-arm-none-eabi" -type d 2>/dev/nulland it turned out is was simply installed under Applications, so I added this line to ~/.zshrc:export PATH=“/Applications/ARM/bin:$PATH”arm-none-eabi-gcc --versionnow returnsarm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)
CMake
- Last but not least, we need to install CMake. Actually, I couldn’t find a way to download an older version from Homebrew. Big problem ==> big solution: I recompiled CMake from source using this tutorial (for CMake 3.12, but we want 3.31.2).
- Go to the CMake archives, then select
cmake-3.31.2.tar.gzto download it. Then extract it once downloaded. - Then open a Terminal pointing to the extracted folder, and select the prefix
./configure --prefix=/usr. In my case, I configured the prefix as./configure --prefix=/Users/romainchiappinelli. This made more sense on my machine. Check what your directory look like, by typpingpwdin the Terminal for instance. The prefix configuration can take a while. make -j16, this also can take a bit of time.- Then,
make install, which might also take its time. - Finally, type
cmake --version… if it is not found, look for it in the prefix path you specified and add it to the~/.zshrc(again). For me it looks likeexport PATH=“$PATH:/Users/romainchiappinelli/cmake/bin” - Finally,
cmake --versionreturnscmake version 3.31.2
- Go to the CMake archives, then select
Finally, PX4 compilation
- Grand finale, go to your PX4 v1.12 folder, run
git submodule update --init --recursivefollowed bymake px4_fmu-v5and the compilation succeeded for me!
