Skip to content
David edited this page Nov 4, 2019 · 5 revisions

Elle0 booting Steps:

Set up the build toolchain and build firmware

  1. Clone the ardupilot repository (available on github)
  2. Download ChibiStudio.
  3. Add necessary components of ChibiStudio to path, as described by the documentation of ChibiStudio.
  4. Follow the steps at http://ardupilot.org/dev/docs/building-the-code.html.
  5. In cloned repo: ./waf configure --board "board" and ./waf copter.

Create a DMA map and alternate function map, if not existent

  1. Extract the DMA mapping and alternate function mapping from the datasheet for the STM32F415: a. Download the datasheet as a pdf for the STM32F415 b. Find the tables with the DMA and alternate function mappings c. Download tabula and follow the instructions of the program to extract the tables into a csv

  2. Put the DMA map and alternate function map extracted into a configuration file: a. In libraries/AP_HAL_ChibiOS/hwdef/scripts/ create STM32F415xx.py b. Use the dma_parse.py and af_parse.py in the same folder to extract the table DMA and alternate function mappings from the csv and copy it into STM32F415XX.py

Create or modify the configuration for elle0, if needed

(1.) Create libraries/AP_HAL_ChibiOS/hwdef/elle0/hwdef.dat 2. Fill hwdef.dat with all the needed information for elle0 by copying from a hwdef.dat from a similar board and modifying it accordingly by reading the documentation for elle0 and STM32F415: a. Crystal frequency b. Board voltage c. Flash size and location of bootloader and application code d. Timing values e. USB information f. UARTs and pins

Be aware of initialization of the board getting skipped when turning it on in certain cases

  1. The board has an internal bootloader which gets executed when connected to usb, so do not boot while being connected via usb
  2. To boot properly, a bootloader has to be used when starting the board, because otherwise things like the floating point unit will not be initialized properly (3.) Create/Modify bootloader: 3.1. Create libraries/AP_HAL_ChibiOS/hwdef/elle0/hwdef-bf.dat if not existent 3.2. Copy the contents of another bootloader into the hwdef-bl.dat and modify it based on the hwdef.dat in the elle0 folder, similar to how the hwdef.dat was created before

Be aware of outdated blackmagic probes

  1. Old version of the blackmagic probe used to upload the program to the board are buggy and write garbage at specific sections on the board
  2. Update the black magic probe, which fixes the problem

Setting up the waf Build Environment on Windows using Cygwin

These setup instructions describe how to setup Cygwin on so that waf (the build system) can run natively on windows and build for all supported boards • Open a web browser to www.cygwin.com/install.html and download “setup-x86_64.exe”. • Paste the following command at a DOS prompt (press window and R key then enter cmd) in the directory where you downloaded “Run setup-x86_64.exe”. • setup-x86_64.exe -P Autoconf, automake, ccache, gcc-g++, git, lib tool, make, gawk, libexpat-devel, libxml2-devel, python27, python2-future, python27-libxml2, python27-pip, libxslt-devel, python27-devel, procps-ng, zip, gdb, ddd.

Install the GCC compiler

• This step is only required if you intend to compile for ARM-based boards

Download ArduPilot Source

The Ardupilot source files then need to be downloaded to your local Cygwin filesystem by cloning the git repository and updating the submodules. Enter the following commands into the Cygwin terminal to download the source files: • git clone https://github.com/ardupilot/ardupilot.git • cd ArduPilot • git submodule update --init –recursive

Build with waf

• You should now be able to start the “Cygwin64 Terminal” application from your Windows Start menu and build with waf as described in BUILD.md.

Porting to a new flight controller board

These steps will illustrate how to port ArduPilot to a new board with an emphasis on porting to STM32 based boards (the most common type) using ChibiOS. Step 1 - Getting Started • Determine which microcontroller the new flight controllers use. if it is a CPU we already support (STM32F42x, STM32F40x STM32F41x, STM32F745, STM32F765 or STM32F777 where “x” can be any number), then the port should be relatively straight forward. If it is another CPU, ping us on the ArduPilot/ChibiOS Gitter channel for advice on how to proceed. • Determine the crystal frequency (normally 8Mhz or 24Mhz). refer to the schematic or read the writing on the crystal which is normally a small silver square

Step 2 - Create a hwdef.dat file for the board • Make a subdirectory in libraries/AP_HAL_ChibiOS/hwdef for your board (i.e. “new-board”). This directory name will eventually be used during the build process (i.e. “waf configure –board new-board”) so keep the name relatively short. • copy/rename an existing template hwdef.dat that is similar to the CPU for your board into the directory created above. For example, if the board has an STMF40x chip copy the f405-min/hwdef.dat file into the new directory.

Step 3 - Configure and build a minimal firmware for the board Follow the Building the code instructions or take a shortcut and read the BUILD.md file which includes doing the following: • cd ArduPilot (or wherever you have cloned ArduPilot to) • ./waf configure --board new-board • ./waf copter If successful the build should produce an .apj file in build/new-board/bin/arducopter.apj

Step 4 - Upload an ArduPilot compatible bootloader to the board Some boards come with a bootloader pre-installed while others rely on the board manufacturer to use dfu to install the firmware to the board. In either case, in order to conveniently load ArduPilot to the board over USB, an ArduPilot compatible bootloader must be uploaded to the board using dfu. “dfu” can be downloaded from here. The source code for the bootloaders can be found in AP_Bootloader but pre-compiled binaries are available for many boards in the Tools/Bootloaders directory on our firmware server. Please refer to the README.txt to see if one of the existing bootloaders is compatible with the new board. Upload the bootloader to the board dfu-util -a 0 --dfuse-address 0x08000000 -D new-board-bootloader.bin –R

Step 5 - Upload the minimal firmware onto the board If using Mission Planner to load the firmware to the board: • Connect the board to the windows PC with a USB cable. • Go to MP’s Initial Setup >> Install Firmware screen and click on the Load custom firmware and select the .apj file and press OK. If the “Load custom firmware” link it not available go to the Config/Tuning >> Planner page and set the “Layout” to “Advanced” • If the MP fails to load the firmware to the board it is possible the “APJ_BOARD_ID” from your hwdef.dat file does not match the .apj firmware file. The board-id in the bootloader is listed in the bootloader’s README.txt file. A temporary workaround is to change the APJ_BOARD_ID in the hwdef.dat file to match the bootloader. Longer-term a bootloader specific to the new board needs to be created so that ground stations can differentiate this board from others and automatically load the correct firmware. Note: Any time you make a change to the board definition file, you must clean up the build, and reconfigure WAF before re-compiling: • ./waf distclean • ./waf configure --board new-board

Step 6 - Fill in the hwdef.dat to specify pins used for each peripheral function • Read the fmuv3 hwdef.dat file (used for The Cube) to understand the full list of hardware configurations that must be specified. • Start filling in the new board’s hwdef.dat file for each bus (SPI, I2C, UART, CAN, etc). Ideally you can refer to the board’s schematic to determine how pins should be configured but if the schematic is not available a trial-and-error approach may work because on each CPU, there are a limited number of pins that can be used for each peripheral function. See STM*.py scripts in the AP_HAL_ChibiOS/hwdef/scripts directory as a guide as to what pins can be used for each peripheral function. • As you enter new values into the hwdef.dat file you can re-compile and upload the firmware to test whether each peripheral function has begun working.

Step 7 - Bring up the sensors Similar to step 6, add the sensor-related configuration to the hwdef.dat file start with the bar first, then IMU, then compass and finally any other sensors the default sensor orientation should also be filled in along with other things upload and the firmware and test the sensors are working.

Step 8 - Enable parameter storage For boards with storage, the storage method used (either FRAM or Flash) should be specified in the hwdef.dat file. For an example of how FRAM is enabled, search for “ramtron” in the fmuv3 hwdef.dat file. In short, you add a couple of lines like this: • # enable RAMTROM parameter storage • define HAL_WITH_RAMTRON 1 For boards using Flash, the bootloader load address needs to be selected so that loading the code does not erase the parameters. See the FLASH_RESERVE_START_KB value in skyviper-f412 and skyviper-v2450 as a reference. It is also possible to use ArduPilot on a board with no storage. In this case configuration parameters will have their default values at startup. The parameter defaults can be defined by creating a new file in the /Tools/Frame_params directory and then add a reference to this file at the bottom of the hwdef.dat file like this: • env DEFAULT_PARAMETERS '’