Skip to content

User Guide: FlyingPI Setup

Michael Corcoran edited this page Aug 10, 2017 · 14 revisions

FlyingPI Setup

WORK IN PROGRESS

Build FlyingPIO Hardware

Pre-Requisites

Assembly

  • BMX055 requires care
  • OSRAM LED markings are confusing, the little mark/arrow goes away from the line toward the cathode
  • Test with current limited bench supply on battery pins, 12 V 100 mA or so, make sure no smoke, super-low current, check 5 V on 5 V pins
  • Test with 3V3 on 3V3 pins, make sure super-low current/no smoke
  • Press header onto Pi extension connector

Build Firmware

  • Requires dRonin build environment setup on your dev machine.
  • Install arm toolchain: sudo apt install gcc-arm-linux-gnueabihf. Note: This will uninstall gcc-multilib if you were using it previously for sim builds due to an upstream Ubuntu bug. Install linux-libc-dev:i386 to get x86 sim build working again.
  • PI_CROSS_SIM=yes make sim
  • make ef_flyingpio

Setup PI

  • Obtain Raspbian image, lite is fine (2017-04-10 is known to work, newer versions currently don't work with RT kernel).
  • Unzip, write to your SD Card (umount /dev/sdX1 etc., dd bs=4M status=progress if=20xx-xx-xx-raspbian-jessie-lite.img -of /dev/sdX)
  • Enable SSH on first boot (mount the SD card (reinsert on desktop distros), cd into boot partition, touch ssh)
  • Connect Ethernet and power up Pi
  • Enable SSH (semi?)permanently, ssh into Pi and sudo raspi-config > Interfacing Options > SSH
  • Copy flyingpi.cfg, flyingpio.dts, flyingpio_eeprom.txt from flight/targets/flyingpio, sim.elf from build/sim-pi, and fw_flyingpio.hex from build/flyingpio/ to home dir on pi (scp flight/targets/flyingpio/flyingpi* build/sim-pi/sim.elf build/fw_flyingpio/fw_flyingpio.hex pi@<pi address>:~)
wget https://github.com/d-ronin/linux/releases/download/linux-4.4.47-pi-rt59/linux-image-4.4.47-rt59-v7._1.0_armhf.deb
sudo dpkg -i linux-image-4.4.47-rt59-v7._1.0_armhf.deb 
cd /boot
sudo mv kernel7.img kernel7.img.old
sudo mv vmlinuz-4.4.47-rt59-v7+ kernel7.img
sudo reboot

uname -a

#------ this set of steps could be omitted if A) upstream had a good openocd, or B) we had an openocd package

sudo apt-get install links
links https://sourceforge.net/projects/openocd/files/latest/download
tar xjf openocd-0.10.0.tar.bz2
cd openocd-0.10.0
./configure --enable-sysfsgpio
make -j4
sudo make install
cd ..

#----- verify programming works

sudo openocd -f flyingpi.cfg

#----- provision the hat
dtc -I dts -O dtb flyingpio.dts -o flyingpio.dtbo

sudo apt-get install git
git clone https://github.com/raspberrypi/hats
cd hats/eepromutils/
make
./eepmake ../../flyingpio_eeprom.txt flyingpio.ee ../../flyingpio.dtbo
sudo dtparam i2c_vc=on
sudo ./eepflash.sh -w -t=24c32 -f=flyingpio.ee
sudo reboot

#---- check that we have spidevs
ls /dev/spid*

#--- pull flyingpio out of reset
sudo sh -c "echo 17 | tee /sys/class/gpio/export"
sudo sh -c "echo out | tee /sys/class/gpio/gpio17/direction"
sudo sh -c "echo 1 | tee /sys/class/gpio/gpio17/value"

#--- run the simulator by hand
sudo chrt -r -p 80 `pgrep spi0`

sudo ./sim.elf -r -s /dev/spidev0 -d ms5611:0:4 -d bmx055:0:1 -d bmm150:0:3 -d flyingpio:0:0

#---- connect with GCS over TCP

To avoid running sim as root (TODO: udev rules for SPI? GPIO perms set by default in raspbian):

setcap "cap_ipc_lock+ep cap_sys_nice+ep" sim.elf

WIP basic systemd unit:

[Unit]
Description=dRonin FlyingPI Firmware

[Service]
Type=simple
User=pi
WorkingDirectory=/home/pi
PermissionsStartOnly=true
ExecStartPre=-/bin/sh -c "echo 17 | tee /sys/class/gpio/export"
ExecStartPre=/bin/sh -c "echo out | tee /sys/class/gpio/gpio17/direction"
ExecStartPre=/bin/sh -c "echo 1 | tee /sys/class/gpio/gpio17/value"
ExecStartPre=/bin/sh -c "chrt -r -p 80 `pgrep spi0`"
ExecStartPre=/sbin/setcap "cap_ipc_lock+ep cap_sys_nice+ep" /home/pi/sim.elf
ExecStart=/home/pi/sim.elf -r -s /dev/spidev0 -d ms5611:0:4 -d bmx055:0:1 -d bmm150:0:3 -d flyingpio:0:0
ExecStopPost=/bin/sh -c "echo 0 | tee /sys/class/gpio/gpio17/value"

[Install]
WantedBy=multi-user.target

Clone this wiki locally