an epic struggle between life and technology

Reconfiguring serial ports under ArduPilot – Getting UART1 working on the PX4MiniAio

I recently picked up some PX4MiniAIO boards (available from RTF Quads and the myairbot) – one of the many “mini pixhawk” variants that are sprouting up. I wanted this board because I want a mini form factor but also want multiple serial ports. Little did I know that the way they wired the board their “UART1” port is actually hooked to the Pixhawk’s serial console, which outputs only the OS console with the default build. This post follows my hacking around to make that serial port usable for telemetry again.

A Pixhawk “compatible” piece of hardware in a 35x35mm package:

Sadly out of the box the “UART1” port on this pilot only spits out the NuttX console – I need telemetry! Otherwise the board works great, just don’t plug USB and power into it at once or it will burn out (ouch!)

After digging into this for a while I have realized how hacked together ArduPilot is on top of the PX4/NuttX software. Ardupilot was originally an Arduino sketch, but when they moved to the STM32 based Pixhawk platform, they wrote a Hardware Abstraction Layer (HAL) which allowed their old Arduino sketch to run on top of the PX4 projects middleware (which runs the NuttX OS). Due to this hackery, the PX4 project’s NuttX configs are used, but many of the config files you think are being used for the build actually aren’t.

First off, pull down the ardupilot repo using git. I pulled the repo “github.com:diydrones/ardupilot.git” and used the Copter-3.3 branch. You’ll need to be able to rebuild the sources and have all the tools installed to do so. Pick your OS from this documentation site on building the code.

We need to disable the default NuttX Serial console which stops the APM software from using that port. Just like regular PX4, these instructions apply. Edit the file:
modules/PX4Firmware/nuttx-configs/px4fmu-v1/nsh/defconfig (for PX4MINIAIO)
edit -v2 if you are trying to do this for standard Pixhawk or other boards

One of the things that I discovered is that build dependencies are tricky since there are multiple sub-builds going on here. “make clean” is not enough. If you modify the PX4Firmware or NuttX configs, you need to delete the PX4Firmware/Archives/*.export files in order to really get the OS files rebuilt. This took me a fair amount of time to figure out!

Once this is complete, the serial console will be dead on UART1. Now you need to get Ardupilot to use the port. In the file “libraries/AP_HAL_PX4/HAL_PX4_Class.cpp”, change the following lines:
#define UARTD_DEFAULT_DEVICE "/dev/ttyS1"
#define UARTE_DEFAULT_DEVICE "/dev/ttyS0"

This will map ttyS1 and ttyS0 to default ports under APM. The UART1 port will now show up in APM as “SERIAL4”.