Skip to content

Commit a4f3b61

Browse files
committed
build instructions
1 parent 37938c3 commit a4f3b61

File tree

5 files changed

+225
-3
lines changed

5 files changed

+225
-3
lines changed

CMakeSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"ctestCommandArgs": "",
1212
"cmakeToolchain": "/home/dev/rpi/Toolchain-rpi.cmake",
1313
"inheritEnvironments": [ "linux_arm" ],
14-
"remoteMachineName": "-508256211;localhost (username=dev, port=5000, authentication=Password)",
14+
"remoteMachineName": "-508256211;localhost (username=test, port=5000, authentication=Password)",
1515
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
1616
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
1717
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",
@@ -34,7 +34,7 @@
3434
"ctestCommandArgs": "",
3535
"cmakeToolchain": "/home/dev/rpi/Toolchain-rpi.cmake",
3636
"inheritEnvironments": [ "linux_arm" ],
37-
"remoteMachineName": "-508256211;localhost (username=dev, port=5000, authentication=Password)",
37+
"remoteMachineName": "-508256211;localhost (username=test, port=5000, authentication=Password)",
3838
"remoteCMakeListsRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/src",
3939
"remoteBuildRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/build/${name}",
4040
"remoteInstallRoot": "$HOME/.vs/${projectDirName}/${workspaceHash}/out/install/${name}",

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# LabNet
1+
# LabNet
2+
3+
LabNet is a server to control hardware connected to RaspberryPi over Ethernet in behavioral experiment with animals. The protocol uses Google [Protobuf](https://github.com/protocolbuffers/protobuf) for the TCP/IP transport. The main goals are:
4+
5+
1. Simple communication protocol.
6+
2. Easy to add support for new hardware.
7+
3. Low latencies. Commands are mostly executed in 1ms, which includes also the communication over the network.
8+
9+
Build instructions can be found [here](doc/build_instructions.md).

doc/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# our local base image
2+
FROM debian:buster
3+
4+
LABEL description="Container for use with Visual Studio"
5+
6+
# install build dependencies
7+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y sudo rsync zip openssh-server make wget cmake ninja-build
8+
9+
RUN useradd -rm -d /home/dev -s /bin/bash -g root -G sudo -u 1000 test
10+
11+
RUN echo 'test:test' | chpasswd
12+
13+
RUN mkdir /home/dev/rpi
14+
RUN wget https://github.com/Pro/raspi-toolchain/releases/latest/download/raspi-toolchain.tar.gz -P /home/dev/rpi/
15+
RUN tar xfz /home/dev/rpi/raspi-toolchain.tar.gz --strip-components=1 -C /opt
16+
RUN rm /home/dev/rpi/raspi-toolchain.tar.gz
17+
COPY Toolchain-rpi.cmake /home/dev/rpi
18+
RUN chown test /home/dev/rpi
19+
20+
RUN service ssh start
21+
22+
EXPOSE 22
23+
24+
CMD ["/usr/sbin/sshd","-D"]

doc/Toolchain-rpi.cmake

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
############################################################################
2+
# toolchain-raspberry.cmake
3+
# Copyright (C) 2014 Belledonne Communications, Grenoble France
4+
#
5+
############################################################################
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License
9+
# as published by the Free Software Foundation; either version 2
10+
# of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
############################################################################
22+
23+
# Based on:
24+
# https://gitlab.linphone.org/BC/public/linphone-cmake-builder/blob/master/toolchains/toolchain-raspberry.cmake
25+
# Updated version:
26+
# https://github.com/Pro/raspi-toolchain/blob/master/Toolchain-rpi.cmake
27+
28+
if("$ENV{RASPBERRY_VERSION}" STREQUAL "")
29+
set(RASPBERRY_VERSION 1)
30+
else()
31+
if($ENV{RASPBERRY_VERSION} VERSION_GREATER 3)
32+
set(RASPBERRY_VERSION 3)
33+
else()
34+
set(RASPBERRY_VERSION $ENV{RASPBERRY_VERSION})
35+
endif()
36+
endif()
37+
38+
# RASPBIAN_ROOTFS should point to the local directory which contains all the libraries and includes from the target raspi.
39+
# Get them with:
40+
# rsync -vR --progress -rl --delete-after --safe-links pi@192.168.1.PI:/{lib,usr,opt/vc/lib} $HOME/rpi/rootfs
41+
# Then RASPBIAN_ROOTFS=$HOME/rpi/rootfs
42+
43+
if("$ENV{RASPBIAN_ROOTFS}" STREQUAL "")
44+
message(FATAL_ERROR "Define the RASPBIAN_ROOTFS environment variable to point to the raspbian rootfs.")
45+
else()
46+
set(SYSROOT_PATH "$ENV{RASPBIAN_ROOTFS}")
47+
endif()
48+
set(TOOLCHAIN_HOST "arm-linux-gnueabihf")
49+
50+
message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
51+
52+
set(TOOLCHAIN_CC "${TOOLCHAIN_HOST}-gcc")
53+
set(TOOLCHAIN_CXX "${TOOLCHAIN_HOST}-g++")
54+
set(TOOLCHAIN_LD "${TOOLCHAIN_HOST}-ld")
55+
set(TOOLCHAIN_AR "${TOOLCHAIN_HOST}-ar")
56+
set(TOOLCHAIN_RANLIB "${TOOLCHAIN_HOST}-ranlib")
57+
set(TOOLCHAIN_STRIP "${TOOLCHAIN_HOST}-strip")
58+
set(TOOLCHAIN_NM "${TOOLCHAIN_HOST}-nm")
59+
60+
set(CMAKE_CROSSCOMPILING TRUE)
61+
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
62+
63+
# Define name of the target system
64+
set(CMAKE_SYSTEM_NAME "Linux")
65+
if(RASPBERRY_VERSION VERSION_GREATER 1)
66+
set(CMAKE_SYSTEM_PROCESSOR "armv7")
67+
else()
68+
set(CMAKE_SYSTEM_PROCESSOR "arm")
69+
endif()
70+
71+
# Define the compiler
72+
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
73+
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})
74+
75+
# List of library dirs where LD has to look. Pass them directly through gcc. LD_LIBRARY_PATH is not evaluated by arm-*-ld
76+
set(LIB_DIRS
77+
"/opt/cross-pi-gcc/arm-linux-gnueabihf/lib"
78+
"/opt/cross-pi-gcc/lib"
79+
"${SYSROOT_PATH}/opt/vc/lib"
80+
"${SYSROOT_PATH}/lib/${TOOLCHAIN_HOST}"
81+
"${SYSROOT_PATH}/usr/local/lib"
82+
"${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}"
83+
"${SYSROOT_PATH}/usr/lib"
84+
"${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}/blas"
85+
"${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}/lapack"
86+
"${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}/pulseaudio"
87+
)
88+
# You can additionally check the linker paths if you add the flags ' -Xlinker --verbose'
89+
set(COMMON_FLAGS "-I${SYSROOT_PATH}/usr/include ")
90+
FOREACH(LIB ${LIB_DIRS})
91+
set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
92+
ENDFOREACH()
93+
94+
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}")
95+
96+
if(RASPBERRY_VERSION VERSION_GREATER 3)
97+
set(CMAKE_C_FLAGS "-mcpu=cortex-a72 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}" CACHE STRING "Flags for Raspberry PI 4")
98+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 3")
99+
elseif(RASPBERRY_VERSION VERSION_GREATER 2)
100+
set(CMAKE_C_FLAGS "-mcpu=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}" CACHE STRING "Flags for Raspberry PI 3")
101+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 3")
102+
elseif(RASPBERRY_VERSION VERSION_GREATER 1)
103+
set(CMAKE_C_FLAGS "-mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard ${COMMON_FLAGS}" CACHE STRING "Flags for Raspberry PI 2")
104+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 2")
105+
else()
106+
set(CMAKE_C_FLAGS "-mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard ${COMMON_FLAGS}" CACHE STRING "Flags for Raspberry PI 1 B+ Zero")
107+
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "Flags for Raspberry PI 1 B+ Zero")
108+
endif()
109+
110+
set(CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH};${CMAKE_SYSROOT}")
111+
112+
113+
# search for programs in the build host directories
114+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
115+
# for libraries and headers in the target directories
116+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
117+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
118+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

doc/build_instructions.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Build instructions
2+
3+
The project uses CMake as build system. We will describe two compilation ways. Both ways need a running Raspberry Pi. But in case of Visual Studio only for debugging.
4+
5+
## Requirements
6+
On Raspberry Pi we need some packages.
7+
1. CMake
8+
2. libsfml-dev
9+
3. libasio-dev
10+
4. libboost-system-dev
11+
5. wiringpi
12+
6. libprotoc-dev
13+
7. gdbserver - only for debugging with Visual Studio 2019.
14+
15+
## On RaspberryPi
16+
17+
We recomend to use [VS Code](https://code.visualstudio.com) as IDE. You will need following extensions: C/C++ and CMake Tools from Microsoft. If you want to use VS Code remotelly you will also need Remove-SSH extension from Microsoft.
18+
19+
We also recomment to use Raspberry Pi 4 with at least 2GB RAM otherwise the compilation can take a long time.
20+
21+
1. Clone the repository with submodules:
22+
```sh
23+
git clone --recursive https://github.com/WinterLab-Berlin/LabNet
24+
```
25+
2. Open the folder with VS Code.
26+
3. Select as kit the GCC 8.3.0.
27+
4. Select as build target Release.
28+
5. Build the project.
29+
30+
## Visual Studio 2019
31+
With Visual Studio 2019 it is also possible to compile and remotely debug applications for Linux. We need the "C++-CMake-Tools for Linux" component for this.
32+
33+
### Docker
34+
To speedup the compilation we will use a docker image which will contain the complete toolchain.
35+
36+
We need "Toolchain-rpi.cmake" and "Dockerfile" files from doc folder. The toolchain is based on [raspi-toolchain](https://github.com/Pro/raspi-toolchain).
37+
38+
1. Change in the terminal to the folder with both files.
39+
2. build the docker image
40+
```sh
41+
docker build -t debian-vs -f .\Dockerfile .
42+
```
43+
3. start the new container
44+
```sh
45+
docker run -d -p 5000:22 debian-vs
46+
```
47+
4. connect with ssh to the container with:
48+
```sh
49+
ssh test@localhost -p 5000
50+
```
51+
the password is also "test".
52+
5. to cross-compile we also need all current libraries and include files from your raspberry:
53+
```sh
54+
# Use the correct IP address here
55+
rsync -vR --progress -rl --delete-after --safe-links pi@192.168.1.PI:/{lib,usr,etc/ld.so.conf.d,opt/vc/lib} $HOME/rpi/rootfs
56+
```
57+
6. the docker container is now ready to use.
58+
59+
### Visual Studio 2019
60+
Don't forget to install the "C++-CMake-Tools for Linux" component.
61+
62+
1. Clone the repository with submodules:
63+
```sh
64+
git clone --recursive https://github.com/WinterLab-Berlin/LabNet
65+
```
66+
2. Open the LabNet folder with Visual Studio.
67+
3. Configure both ssh connections to the docker container and the target Raspberry Pi under "Tools\Options\Cross Platform\Connection Manager". Select the Raspberry Pi connection as default one.
68+
4. Open "CMakeSettings.json".
69+
5. Choose under "Remote machine name" the docker container connection for Debug and Release configurations.
70+
6. This step is only necessary if Raspberry Pi connection is not the default one. Right click on "CMakeList.txt" and select "Open Debug And Launch Settings". In the json file delete the value of the "remoteMachineName" parameter. Press "Ctr+Spacebar" and select the right connection.
71+
7. Choose the build configuration "Linux-GCC-Release" or "Linux-GCC-Debug" and "gdbserver" as startup item.
72+
8. If you press "Start Debugging" Visual Studio will compile LabNet on the docker container, transfer it to Raspberry Pi and start over gdbserver.

0 commit comments

Comments
 (0)