Difference between revisions of "Compiling"

From PaparazziUAV
Jump to navigation Jump to search
(Redirected page to FirmwareFlashing)
 
(37 intermediate revisions by 8 users not shown)
Line 1: Line 1:
== Introduction ==
#REDIRECT [[FirmwareFlashing]]
 
The goal of this part of the documentation is to give you insight in how to give your Autopilot board a ''Brain''. Airborne autopilot code, flight plans and configuration settings are compiled into a single file, sometimes referred to as a ''binary image''. After compilation this file is transferred to the Autopilot board micro-controller flash ROM through use of an USB cable. Note that most tuning and flight plan parameters can be changed in-flight but after each power cycle, the autopilot reverts to the original settings. Permanent changes are made by recompiling the airborne code and it's new configurations settings, and re-upload this to the autopilot board. It may sound complicated but in fact it is quite simple if you follow the steps below.
 
== Get access to your computers USB port ==
 
Regular users, (also known as Non-Root) by default, as security measure, can not access and interact with hardware in- and output- devices (I/O), USB ports included. To make it possible, the user you are using to program the autopilot board must be a member of the ''plugdev'' group. The original username you used when you installed your Linux OS usually is already a member.
 
If you are '''not''' already a member, add yourself to this ''plugdev'' group with the following command:
 
  $ sudo adduser $USER plugdev
 
It will be effective only on your next login or after the command
 
  $ newgrp plugdev
 
== USB flashing ==
 
The Paparazzi device rules are required for USB flashing.  Copy them into place if you haven't already done so:
  $ sudo cp $PAPARAZZI_HOME/conf/system/udev/rules/10-paparazzi.rules /etc/udev/rules.d/
 
If you are using Ubuntu, the Braille TTY driver interferes with FTDI USB Serial adapters and should be removed:
 
$ sudo apt-get remove brltty
 
[[Image:Tiny_test_wiring.jpg|thumb|Example wiring for programming and telemetry]]
If the autopilot senses a connected USB cable during power-on, it will wait to receive a firmware image rather than booting normally.  The firmware can be compiled and flashed by several means, '''the simplest way using the [[Paparazzi_Center|Paparazzi Center]]''', the traditional way being:
make AIRCRAFT=''myplane'' clean_ac ap.upload
(where ''myplane'' is the name of your airframe as defined in <tt>conf/conf.xml</tt>)
 
This command erases any compiled autopilot code from the PC, recompiles everything from scratch, and then sends it to the autopilot. 
Variations include:
* make AIRCRAFT=''myplane'' sim
*: Compiles your code for use in the simulator - note that "clean_ac" will remove this code, so the simulator code must be rebuilt each time a clean has been performed.
* make AIRCRAFT=''myplane'' fbw.upload
*: This is needed when configuring the separate "fly by wire" MCU on the [[Classix]] autopilot.
* make AIRCRAFT=''myplane'' ap
*: This will simply build the portions of autopilot code that have changed since the last compile without attempting to flash.  Note: this method may not detect certain changes (i.e. changes to the airframe makefile section or CVS updated code).
* make AIRCRAFT=''myplane'' ap.upload FLASH_MODE=IAP
*: Specifies USB flashing.  This should be specified at the top of the makefile section of your airframe file but can be overridden here.  Use FLASH_MODE=IAS for serial flashing.
 
=== Verify that above upload works ===
 
==== Step 1 ====
 
Connect an USB cable to the USB port (U23, corner of the board). If you type the following command
 
<gallery>
Image:Fase2_Insert_Flightplan_A.jpg|Board to mini USB connect
Image:Fase2_Insert_Flightplan_B.jpg|Make sure you have a connector for power ('''Don't''' power up yet!)
Image:Fase2_Insert_Flightplan_C.jpg|Connect USB to PC '''and''' Board
Image:Fase2_Insert_Flightplan_D.jpg|only '''now''', power up the board
</gallery>
 
$ dmesg | tail -5
 
in your terminal, should see messages that look like:
 
  [79212.484187] pl2303 1-2.3:1.0: device disconnected
  [82312.463077] usb 5-1: new high speed USB device using ehci_hcd and address 23
  [82327.555770] usb 5-1: device descriptor read/64, error -110
  [82342.752307] usb 5-1: device descriptor read/64, error -110
  [82342.968031] usb 5-1: new high speed USB device using ehci_hcd and address 24
 
Which confirms that your device is powered up and working for your OS. If not - check your power and connections. Failing that - prepare to download the USB Bootloader through the 'Upload' connector.
 
Above output is and example from the feedback from the Tiny2.1 Autopilot board
 
==== Step 2 ====
 
Upload the compiled Autopilot code a.k.a, firmware
 
  $ make AIRCRAFT=DEMO demo2.upload
 
    make[1]: Leaving directory `/usr/share/paparazzi'
    cd sw/airborne; make PAPARAZZI_SRC=/usr/share/paparazzi PAPARAZZI_HOME=/home/dirkx/paparazzi3 TARGET=demo2 all
    make[1]: Entering directory `/usr/share/paparazzi/sw/airborne'
    /home/dirkx/paparazzi3/var/demo/demo2/demo2.elf  :
    section    size        addr
    .text      956        16384
    .ctors        0        17340
    .dtors        0        17340
    .data        0  1073741824
    .bss        12  1073741824
    .stack    4096  1073742080
    .comment    54            0
    Total      5118
    make[1]: Leaving directory `/usr/share/paparazzi/sw/airborne'
    cd sw/airborne; make PAPARAZZI_SRC=/usr/share/paparazzi PAPARAZZI_HOME=/home/dirkx/paparazzi3 TARGET=demo2 upload
    make[1]: Entering directory `/usr/share/paparazzi/sw/airborne'
    /usr/share/paparazzi/sw/ground_segment/lpc21iap/lpc21iap  /home/dirkx/paparazzi3/var/demo/demo2/demo2.elf
    .
    Found USB device
    BootROM code: 2.12
    Part ID: 0x0402FF25 (LPC2148, 512k Flash, 32k+8k RAM)
    BootLoader version: 1.3
    #
    Starting software at 0x00004000
    make[1]: Leaving directory `/usr/share/paparazzi/sw/airborne'
    make: Leaving directory `/usr/share/paparazzi'
 
Which confirms that your device has the bootloader functioning. The important bit of output is:
 
    Found USB device
    BootROM code: 2.12
    Part ID: 0x0402FF25 (LPC2148, 512k Flash, 32k+8k RAM)
    BootLoader version: 1.3
    #
 
In the aboveexample we're using a modified [http://paparazzi.enac.fr/wiki/Using_demo_programs_in_sw/airborne| demo] - which flashes the LEDs with a Tiny2.1 board): Be aware that the demos involving serial ports do not currently work with Tiny V2's.
 
==== Step 3 ====
 
Observe the LEDs flashing.
 
==== Step 4 ====
 
Disconnect the USB cable, Disconnect the power and reconnect the power of the autopilot board. The LED's should flash again.
 
==== Step 5 ====
 
Select aircraft MJ5, build and upload.
 
Select airframe funjet1.xml (if you have a Tiny V2)
 
Connect the serial port of your tiny to your PC using a level converter and select session Flight USB serial@9600.
 
If you are using funjet1.xml:
*Stop all the processes but do not remove them.
*Edit the line Data Link and add "-s 57600" to the end, to tell the data link the baud rate of the MJ5.
*Restart Data Link, Server and GCS in that order.
 
If all went well, it should work and you should see messages coming in from the Tiny!
 
== Installing the tunnel for direct access to the GPS ==
 
This completely replaces the normal autopilot code (leaving the USB bootloader intact) with a simple serial-to-serial pass-thru that essentially connects the GPS serial port directly to the modem serial port or a USB-to-serial connection that creates a USB serial port that goes to GPS port or modem port. Use this only to gain direct access to the GPS for testing/configuration with [[GPS#GPS_configuration_using_U-Center|U-Center]] or other software.
 
==== UART tunnel ====
 
Use this if you have a serial cable to connect. The LEDs will blink when data is transferred. Type the following command from your paparazzi folder, substituting the name of your airframe and paying attention to case sensitivity:
make AIRCRAFT=''myplane'' tunnel.upload
Connect the USB cable and power on the autopilot to receive the code.
 
This can be done without the USB bootloader by appending ''FLASH_MODE=ISP'' to the command line (specifying ISP serial loading).  This will require a serial cable connection (i.e. FTDI USB-to-TTL). '''WARNING!''' Installing tunnel code with the ISP method will erase any USB bootloader code. Make sure you are able to install a bootloader yourself.
 
==== USB tunnel ====
 
This can be done without a serial cable just by having USB. The LEDs will blink when data is transferred. It can connect to either serial port on the autopilot (for Tiny 2.11: uart0=gps, uart1=modem). To connect USB to the gps type the following command from your paparazzi folder, substituting the name of your airframe and paying attention to case sensitivity:
make AIRCRAFT=''myplane'' usb_tunnel_0.upload
Connect the usb cable and power on the autopilot to receive the code. The code will switch the USB to emulate a serial port that you can access at '''/dev/ttyACMx'''. Windows user can extract the usbser.sys file from .cab file in C:\WINDOWS\Driver Cache\i386 and store it somewhere (C:\temp is a good place) along with the [[Media:Usbser.zip|usbser.inf]] file. Windows then creates an extra COMx port that you can use in a terminal program or with ucenter.
To use the USB tunnel make sure you first power the autopilot before connecting USB not to end up in the USB bootloader.
 
== Installing the USB Bootloader ==
 
The USB bootloader only needs to be installed '''once''', when the board is first built and has never been used. [Image:Bare_TWOG_Board.jpg|thumb|right|Bare_TWOG_Board] The Bootloader is uploaded through the serial interface UART0 (Serial1) by holding pin P0.14 low during power-up on Tiny V1.x. For Tiny V2.x this pin is called BOOT. Also GPS_RESET has to be tied low during the serial programming to keep the GPS receiver quiet that shares the serial port with the download. If you have a TWOG, it is easier just to unplug the GPS module temporarily. If you did not make and soldered the Autopilot board yourself but bought it somewhere it may have already had the USB bootloader installed, please check with your supplier. In that case you can just '''skip''' the steps described here.
 
You will need to convert the PC's RS232 Serial with voltage levels of +/-13V to 3.3V (or 5V) TTL in order to communicate directly with the Autopilot board. This can be accomplished in multiple ways. The easiest and most convenient method is to purchase or build a USB -> Serial 3.3V adapter similar to this one [http://www.ftdichip.com/Products/EvaluationKits/TTL-232R-3V3.htm TTL-232R-3V3] [[Image:The_FTDI_RS232_USB_Cable.jpg|thumb|right|The FTDI RS232 USB Cable]]
 
Some examples of suppliers:
[http://www.sparkfun.com/commerce/product_info.php?products_id=199]
[http://www.sparkfun.com/commerce/product_info.php?products_id=718]
[http://www.pololu.com/products/pololu/0391/]
[http://www.hvwtech.com/products_view.asp?CatID=166&SubCatID=183&SubSubCatID=0&ProductID=409]
 
It is strongly advised that you use a USB-serial converter with of the [www.ftdichip.com/ FTDI brand] chip as FTDI serial chips are by default working well in Linux. As a nice bonus, the Paparazzi ground station software is configured to look for modems on FTDI ports by default, the converter can likely serve as a modem interface after it's use in Bootloader uploading.
 
Make up a wiring harness similar to the following.
 
<gallery>
Image:Cable_Bootloader_Full.jpg|Bootloader cable
Image:Cable_Bootloader_To_FTDI_USB.jpg|Bootloader cable to FTDI USB
Image:Bootloader_helper_cable_to_USB_FTDI_Cable.jpg|Bootloader helper cable to USB FTDI cable
</gallery>
 
You may vary the details, however this is a working solution:
 
Tiny V1.x (SERIAL_1):<br />
TINY RXD0  <-- PC SERIAL TX (5V or 3.3V)
TINY TXD0  --> PC SERIAL RX (5V or 3.3V)
TINY P0.14 --> attach to ground, or wire through a pushbutton to ground
TINY GND  --> PC SERIAL ADAPTER GND
TINY RESET --> ''optional'' wired to ground through a pushbutton so you can reset
 
 
Tiny V2.x (DOWNLOAD):<br />
TINY LPC_RXD0  <-- PC SERIAL TX (5V or 3.3V)
TINY LPC_TXD0  --> PC SERIAL RX (5V or 3.3V)
TINY BOOT      --> attach to ground, or wire through a pushbutton to ground
TINY GPS_RESET --> attach to ground, or wire through a pushbutton to ground
TINY GND      --> PC SERIAL ADAPTER GND
 
 
TWOG V1.x (DOWNLOAD):<br />
TWOG LPC_RXD0  <-- PC SERIAL TX (5V or 3.3V)
TWOG LPC_TXD0  --> PC SERIAL RX (5V or 3.3V)
TWOG BOOT      --> attach to ground, or wire through a pushbutton to ground
TWOG GND      --> PC SERIAL ADAPTER GND
For TWOG make sure the GPS module is '''unplugged''' from the board. This is to prevent GPS serial data to disturb the uploading of the bootloader.
 
[[Image:Where_To_Insert_Bootloader_Cable.jpg|thumb|right|Where to insert Bootloader cable]]
 
Once this wiring is ready you will be ready to upload the USB Bootloader to the autopilot board from your PC.
 
To prepare the Autopilot board to accept uploads over it's serial port you must have pin P0.14 LOW for at least 3ms while it is powering up or resetting.  While it is still powered up it is ready to accept the Bootloader firmware code upload over the serial connection. 
 
<gallery>
Image:Point_To_Connect_Ground.jpg|thumb|Point to_connect ground
Image:Closeup_Ground_Point.jpg|Closeup ground point
Image:Grounding_For_Bootloader_Closeup.jpg|closeup grounding point detail for Bootloader uploading
</gallery>
 
The next step while your board is all connected and powered up is to type the commands for uploading the bootloader firmware.
 
<gallery>
Image:Powerup_Now.jpg|Powerup now
Image:TWOG_Bootloader_Overview.jpg|TWOG Bootloader overview
</gallery>
 
'''In Linux'''
 
From your Paparazzi folder in Linux, type:
 
$ make upload_bl PROC=GENERIC
 
This will begin compiling your USB Bootloader and then attempt to transfer it to the Autopilot board. This will also assume you are using a USB -> Serial adapter for the connection.  It uses /dev/ttyUSB0 by default. If your adapter is mapped to a different tty, you will need to modify the Makefile accordingly.
 
[[Image:Wait_For_Bootloader_To_Upload.jpg|thumb|Wait for the bootloader to upload]]
 
If everything is connected and dsetup correctly, after a while you will see the following messages
 
[[Image:Shell_bootloader_upload_success.jpg|thumb|Shell Bootloader upload success]]
 
'''In Windows'''
 
If for some reason you need to program your autopilot board USB Bootloader in MS Windows you have to download the [http://www.standardics.nxp.com/support/documents/microcontrollers/zip/flash.isp.utility.lpc2000.zip LPC2000 Flash Utility V2.2.3] or later. You will then prepare the autopilot board and start it in ISP bootloader state as described in the previous. This small utility will ony help uploading the Bootloder firmware. You will need to copy your compiled '''bl.hex''' file from Linux to your Windows OS. This file will be then uploaded.
 
== Troubleshooting ==
 
As a rapidly evolving open-source project, on occasion your software may fail to compile after a [[Installation#Software_Updates|SVN Update]].  This is most likely due to a new or changed variable name that is now required in your airframe, flight plan, etc.  Since the user-configured files are not updated automatically you may need to view the most recently changed sample airframe or flight plan files to find the required changes.<br>
See the [[Software_Troubleshooting|Software Troubleshooting]] page for help with common compilation errors.

Latest revision as of 08:33, 7 February 2013

Redirect to: