Issue with building a minimal firmware for custom board

Hi,

I’m new to ardupilot and I’m sorry if I’m posting in the wrong category. I’m currently trying to build a minimal firmware board for the STM32f103 in AP_Periph. I’ve configured my new board and now I’m trying to run ./waf AP_Periph however I’m running into an error which says the following:

../../libraries/AP_HAL_ChibiOS/GPIO.cpp: In function 'void __static_initialization_and_destruction_0(int, int)':
../../libraries/AP_HAL_ChibiOS/GPIO.cpp:54:3: error: statement has no effect [-Werror=unused-value]
   54 | } _gpio_tab[] = HAL_GPIO_PINS;
      |   ^~~~~~~~~
compilation terminated due to -Wfatal-errors.
cc1plus: some warnings being treated as errors

I’ve looked through GPIO.cpp and some other files but I can’t figure out why this error is occuring or how to fix it. Any help fixing this problem would be much appreciated, thank you.

I’m facing the same issue trying to build bootloaders in Copter-4.3.7 (c8506ed478). ./Tools/scripts/build_bootloaders.py CubeOrange fail with the same error. It seems that this me be just a warning, but ArduPilot treats warning as errors.

Yeah I found that it’s just a warning treated as an error too. I tried to run with --disable-Werror but it seemed to create new Werrors in different files and the compilation was still terminated.

Ultimately I got things working by building via the docker image. This was still weird to me, however, as I was running a new native Ubuntu 22.04 image and had run through the dev environment setup maticulously.

Hi Ian,

It’s good to hear you got around this issue. Since it worked for you, I’ve been trying to build via the docker image too, following this site: ArduPilot and Docker Part 1.
I’m getting stuck when I run

 docker build . -t ardupilot.

It throws up an error that says the following:

Tools/environment_install/install-prereqs-ubuntu.sh: line 334: /home/ardupilot/.ardupilot_env: Permission denied

Did you run into this problem too, and if so, do you know how to fix it? I’m currently working in a clone of the Ardupilot github and I’m wondering if I need instead need to fork the ardupilot github into my own github, then clone it so I have permissions.

Regards,
Daniel

You should not need to fork ardupilot necessarily. The code on your machine in either case would not have different permission per say, you just cannot push any changes to git unless you own the repo (aka you forked it).

While building with docker I had no such issue unfortunately. You may benefit from checking out a stable/older version of ardupilot (eg git checkout -b origin/Copter-4.3 then git submodule update --init --recursive).

Unless your username is ardupilot, it looks like you cloned into the /home folder rather than a user folder, probably as root. That’s not recommended.

Try the following commands, substituting your username for username.

sudo mv /home/ardupilot /home/username
sudo chown -R username:username /home/username/ardupilot

And then stop using sudo to do anything else build related.

1 Like

Hi Yuri,
I’m not sure I entirely understand. I’m currently cloned into the root folder in ubuntu using WSL. Here ardupilot is just the name of the directory that was created when I cloned the github repo into my root directory. Using WSL I can’t go below root into my ubuntu as far as I can tell.

Hi Ian,
Thanks for your reply. I will try that when I get the chance.

Indeed, you cloned into a directory that is not a user directory. That’s my entire point.

It doesn’t need to go “lower.” It ought to be within a user home directory with that user’s permissions, which is what the commands I gave you will do.

While checking out a branch and updating the submodules is a proper step, I expect that will fail also because you have a permission issue to resolve, per my first reply.

I agree here. One should probably clone ardupilot into, for example, /home/yourusername/ardupilot or maybe even /home/yourusername/Documents/ardupilot. If you cloned it into /home/ardupilot it is not in your user’s home directory and thus might have problems with permissions.

Hi Yuri,

The commands you sent to run don’t work and I get the following error message when I run the first one.

mv: cannot stat '/home/ardupilot': No such file or directory

I think I’ve figured out that my user directory is called root, because when I just type ‘users’ in the command line it responds with root. Is this a problem? I’ve tried running the following command and it seemed to work.

sudo chown -R root:root ardupilot

After running that I tried building the docker again and it still said permission denied.
I’m sorry if I’m not understanding. I’m very new to Linux and WSL.

Okay, I figured out how to create a new user in WSL, so now I’ve got a new user named daniel. I cloned the ardupilot repo into Ubuntu/home/daniel. Now I’ve tried to build the docker and get permission denied. Then I tried

sudo chown -R daniel:daniel /home/daniel/ardupilot

And then tried to build the docker again, but still had permissions denied.

Are you logged in as daniel when attempting to build?

Previously I wasn’t no. I just tried logging in as daniel and then building the docker again and I got a new error message.

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post “http://%2Fvar%2Frun%2Fdocker.sock/v1.24/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=ardupilot&target=&ulimits=null&version=1”: dial unix /var/run/docker.sock: connect: permission denied

This is very different from the previous error message saying permission denied since this one popped up immediately when I ran the build command, whereas the other one would only say permission denied after a few minutes of running the build.

Well, you changed the owner of all your files to root. So…surprise…

Delete the entire cloned directory and start over. Do everything as the daniel username, and only use sudo if you actually know what you’re doing.

Hi Yuri, sorry for the late response. I deleted my entire cloned directory and started over from scratch, doing everything as the daniel username. I get this issue again.

Tools/environment_install/install-prereqs-ubuntu.sh: line 326: /home/ardupilot/.ardupilot_env: Permission denied

Somehow you ended up right back where you started. It appears you have cloned once again into a non-user directory to which you have no permissions.

I created the user daniel using sudo adduser daniel. I then logged into daniel using su - daniel. From here I cloned into home/daniel.

Because you encountered that specific error, you almost certainly did not clone properly into the directory you think you did.

I never use a docker environment to build ArduPilot, but I just did so successfully. Here is the list of commands I ran under my username, yuri:

First, make sure we are who we think we are by running whoami - it should look like this:

yuri@wsl2-host:~$ whoami
yuri

If it looks like this (with root in the results), you need to log in as your username (daniel). Do not proceed as root!

root@wsl2-host:/home/yuri# whoami
root

Once logged in as yuri (or daniel, in your case), the following commands should build a Copter binary for the Cube Orange using the latest master (development) branch:

cd ~
mkdir ardupilot-docker-env
cd ardupilot-docker-env
git clone https://github.com/ArduPilot/ardupilot.git
cd ardupilot
docker build . -t ardupilot
docker run -u "$(id -u):$(id -g)" -it -v `pwd`:/ardupilot ardupilot:latest bash
Tools/gittools/submodule-sync.sh
./waf configure --board CubeOrange
./waf copter

The following output confirms we have a binary in the correct directory:

ardupilot@be0568eca358:/ardupilot$ ls build/CubeOrange/bin/
arducopter  arducopter.abin  arducopter.apj  arducopter.bin

After exiting, to re-enter the docker environment and create another build, you need only to run the following:

cd ~/ardupilot-docker-env/ardupilot
docker run -u "$(id -u):$(id -g)" -it -v `pwd`:/ardupilot ardupilot:latest bash

At the resulting bash prompt, issue the appropriate waf commands to configure and build. It is prudent to use the submodule-sync tool again if you fetch the latest master. ./waf clean may also be your friend when starting a new build.