These instructions guide you though the process of uploading code to the flight computer. If you are not using the mission computer, this is all you need to do to get flying.
Before you begin, determine whether you want to use the PX4 USB Bootloader, or whether you prefer to use a JTAG programmer such as the Black Magic Probe. Instructions for both cases are below. Note that for the Pixhawk the casing has to be cut away, and a JTAG header soldered on in order to use the probe.
The PX4 project has a USB bootloader for the Pixhawk and distributes loaders for Windows, Mac, and Linux. The PX4 bootloader is flashed to the Pixhawk at the factory. This is the easiest method of uploading new programs to the Pixhawk and does not require hardware aside from a USB cable. By default, SMACCMPilot binaries are built to be compatible with the PX4 bootloader.
For more detail, see the PX4 Project wiki page on the bootloader.
Ordinarily, you will not have to worry about flashing the bootloader, since it comes flashed from the factory and SMACCMPilot project binaries should not overwrite it unless configured to and loaded via JTAG. However, if you have overwritten the bootloader, it is easy to replace.
If you wish to build your own PX4 bootloader from sources, clone and build the PX4 project Bootloader repository.
Like other PX4 project repositories, the Bootloader expects to find a built clone of the libopencm3 repository in the same parent directory.
The PX4 bootloader uses a special
.px4 format for program binaries. The SMACCMPilot build system will build
image.px4 binaries alongside ordinary ELF binaries (named simply
image). Note that
image.px4 will be linked to sit after the PX4 bootloader in flash, whereas
image will be linked to sit at the beginning of flash.
The bootloader is active for the first five seconds after the Pixhawk is powered on. When active, the bootloader will rapidly flash the red LED only. The uploader must initiate communication with the Pixhawk while the bootloader is active. Because of this five second time limit, we have had problems trying to use the bootloader from within a virtual machine.
If there is no program flashed to the Pixhawk, bootloader will stay active for as long as the board is powered on. The SMACCMPilot application will not rapidly flash the red LED in normal operation.
For Linux and Mac users, the easiest way to upload SMACCMPilot applications to the Pixhawk is via the
px4_upload.py script. This script was authored by the PX4 development team and is redistributed under the terms of their license.
px_upload.py script requires Python 2.7 or greater and the pyserial package.
The upload script accepts a comma-separated list of serial ports where the bootloader may be present. Since resetting the Pixhawk to activate the bootloader will make a new USB serial port connection, it is sometimes helpful to give several serial ports as an argument. For example, on Linux, you may give the list:
To use the upload script from the command line, do the following:
cd smaccmpilot-build/smaccmpilot-stm32f4/src/smaccm-flight/platform-fmu24/standalone_flight_echronos UPLOAD_PORT=<serial-device> make upload
NOTE: Linux users don’t have to specify the UPLOAD_PORT, it is by default set to 3D-Robotics USB.
Once the uploader has recognized a valid PX4 firmware file, it will give the message:
Loaded firmware for 9,0, waiting for the bootloader...
At this point, reset your Pixhawk board to enter the bootloader. You can do this by pushing the reset button on the side of the board, or if there is no other power source, unplugging and replugging the USB cable.
When the uploader recognizes the Pixhawk bootloader, it will output the following sequence:
Found board 9,0 bootloader rev 3 on /dev/ttyACM0 erase... program... verify... done, rebooting.
The first time you upload a program, the erase step may take quite some time as the bootloader erases the entire flash memory. Subsequent erases should be faster, because the bootloader will only erase pages which have been written to.
You can load your SMACCMPilot binary onto hardware with the instructions found on the Black Magic Probe page.