Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 155 additions & 8 deletions Doc/readme_generic_board.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,163 @@ The generic board target moves the minimum dependencies for compile and build of

The project was originally created to support the Raspberry Pi target but other generic targets could be added later.

2. CMake
2. Installing Dependencies
----------------

### Install CMake

Install [cmake](https://cmake.org) on your target

```
sudo apt-get install cmake libc6
```

### Install WiringPi on the RPi

```
sudo apt-get install git-core
mkdir -p ~/raspberrypi
cd ~/raspberrypi
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
./build #compile and install lib
```

3. CMake
----------------
The cmake directory can be used with the generic target for any cmake supported gcc like compile or cross complie platforms. See the cmake/CMakeLists.txt file for customizable parameters. The steps to use when building using CMake are:
1. Install [cmake](https://cmake.org) on your target. For raspbian this is as simple as sudo apt-get install cmake
2. Customize the cmake/CMakeLists file to specify details about your target RTC and GPIO implementations. See specific target sections below for detailed instructions about per-project configurations. Use `set(BOARD_RADIO "SX1276")` to specify the radio type used.
3. Create a "build" directory in the cmake subdirectory and cd into this directory.
4. Run `cmake ..` from this directory to generate makefiles
5. Run `./make` to build the project file
1. Customize the cmake/CMakeLists file to specify details about your target RTC and GPIO implementations. See specific target sections below for detailed instructions about per-project configurations. Use `set(BOARD_RADIO "SX1276")` to specify the radio type used.
2. Create a "build" directory in the cmake subdirectory and cd into this directory.
```
mkdir -p build
cd build
```
3. Run `cmake ..` from this directory to generate makefiles
4. Run `./make` to build the project file


### Cross-Compile with CMake for RPi


1. Add dependencies

```
apt-get install git rsync cmake libc6-i386 lib32z1 lib32stdc++6
```

2. Get the Raspberry Pi tools and toolchain

```
mkdir -p ~/raspberrypi
cd ~/raspberrypi
git clone git://github.com/raspberrypi/tools.git
```

3. Add the needes paths to the ENV variables.

```
echo 'export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin' >> ~/.bashrc

source ~/.bashrc
```

4. Now, verify that you can access the compiler:

```
arm-linux-gnueabihf-gcc -v
```

5. In your raspberrypi folder, make a folder called rootfs.

```
mkdir -p ~/raspberrypi/rootfs
cd ~/raspberrypi/
```

6. Connect to your Raspberry Pi board and install the needed libs. In our case, we need WiringPi.

```
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
cd wiringPi
git pull origin
./build #compile and install the lib
```

7. Now you need to copy the entire /lib and /usr directory from the Raspberry Pi to this newly created folder in our local machine.

```
rsync -rlv links -e "ssh -p 22" pi@raspberry-pi.local:/{lib,usr} $HOME/raspberrypi/rootfs
```

8. Now, we need to write a cmake config file. Open **~/raspberrypi/pi.cmake** in your favorite editor and insert the following:

```
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/raspberrypi/rootfs)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
```

9. Now you should be able to compile your cmake programs simply by adding this extra flag:

```
-D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake
```

**Example:**

```
cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../ && make
```

10. Demo/Example:

```
cd /tmp
mkdir -p helloworld/build
cd helloworld

cat << EOF > helloworld.cpp
#include<iostream>

int main(int argc, char *argv[]){
std::cout << "Hello World!" << std::endl;
return 0;
}
EOF

cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 2.8.9)
project (hello)
add_executable(hello helloworld.cpp)
EOF

mkdir -p build
cd build
cmake -D CMAKE_TOOLCHAIN_FILE=$HOME/raspberrypi/pi.cmake ../
make

scp -P 22 CMakeHelloWorld pi@raspberry-pi.local:/tmp/
ssh pi@raspberry-pi.local -p 22 /tmp/CMakeHelloWorld

```

### Cross-Compile with Make for RPi v2,3

1. Follow the steps 1. to 7. from the **Cross-Compile with CMake for RPi** instructions.
2. To compile your C++ code run your makefile with:

```
make CXX=arm-linux-gnueabihf-g++ LD=arm-linux-gnueabihf-ld
```

3. Apps Supporting Generic Board Targets
4. Apps Supporting Generic Board Targets
----------------
Use
```
Expand All @@ -25,7 +172,7 @@ The cmake directory can be used with the generic target for any cmake supported
1. ttnmapper
An aplication used to generate coverage maps, see http://ttnmapper.org/ for project overview. Configuration and usage details are TBD.

4. Supported Target Hardware
5. Supported Target Hardware
----------------
1. Raspberry Pi Target
1. To configure the Raspberry Pi target, ensure CMakeLists.txt uses
Expand Down
1 change: 1 addition & 0 deletions cmake/modules/FindWiringPi.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
find_library(WIRINGPI_LIBRARIES NAMES wiringPi)
find_path(WIRINGPI_INCLUDE_DIRS NAMES wiringPi.h)
include_directories(SYSTEM ${WIRINGPI_INCLUDE_DIRS})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(wiringPi "Could not find WiringPi. Either install it using instructions at http://wiringpi.com/download-and-install/ or specify a different BOARD_GPIO" WIRINGPI_LIBRARIES WIRINGPI_INCLUDE_DIRS)
2 changes: 1 addition & 1 deletion src/apps/ttnmapper/generic/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "board.h"
#include "LoRaMac.h"
#include "Log.h"
#include "log.h"
#include "LoRaMac-api-v3.h"

#define TTN_MAPPER_NWK_SKEY { 0xAE, 0x17, 0xE5, 0x67, 0xAE, 0xCC, 0x87, 0x87, 0xF7, 0x49, 0xA6, 0x2F, 0x55, 0x41, 0xD5, 0x22 }
Expand Down
5 changes: 3 additions & 2 deletions src/boards/generic/CMakeSources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ set(BOARD_SOURCES
if(BOARD_GPIO STREQUAL "RASPBERRY_PI")
find_package(WiringPi REQUIRED)
include_directories(${WiringPi_INCLUDE_DIRS})
set(BOARD_LIBS ${WIRINGPI_LIBRARIES} pthread)
endif()
set(RPI_LIBS rt pthread)
set(BOARD_LIBS ${WIRINGPI_LIBRARIES} ${RPI_LIBS})
endif()
2 changes: 1 addition & 1 deletion src/boards/generic/Pi/gpio-board-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "board.h"
#include <wiringPi.h>
#include "gpio.h"
#include "Log.h"
#include "log.h"
#include "../posix/interrupt-simulate-posix.h"

void GpioMcuInitialize(void)
Expand Down
2 changes: 1 addition & 1 deletion src/boards/generic/Pi/spi-board-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "board.h"
#include "Log.h"
#include "log.h"
#include <wiringPiSPI.h>
#include <errno.h>

Expand Down
2 changes: 1 addition & 1 deletion src/boards/generic/spi-board.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "spi-board.h"

#if BOARD_GPIO_RASPBERRY_PI
#include "pi/spi-board-pi.c"
#include "Pi/spi-board-pi.c"
#elif BOARD_GPIO_UNDEFINED
#warning "Using UNDEFINED board GPIO, link step will fail"
#else
Expand Down
2 changes: 1 addition & 1 deletion src/boards/generic/spi-board.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define SRC_BOARDS_GENERIC_SPI_BOARD_H_

#if BOARD_GPIO_RASPBERRY_PI
#include "pi/spi-board-pi.h"
#include "Pi/spi-board-pi.h"
#elif BOARD_GPIO_UNDEFINED
#warning "Using undefined GPIO, link step will fail"
typedef int SPI_HandleTypeDef;
Expand Down
2 changes: 1 addition & 1 deletion src/mac/CMakeSources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use_c99()
set(MAC_DIR ${SOURCE_DIR}/mac)
include(${SOURCE_DIR}/system/crypto/CMakeSources.txt)
set(SYSTEM_DIR ${SOURCE_DIR}/system)
set(MAC_SOURCES ${MAC_DIR}/LoraMac.c ${MAC_DIR}/LoraMac-api-v3.c ${MAC_DIR}/LoRaMacCrypto.c ${CRYPTO_SOURCES} ${SYSTEM_DIR}/timer.c)
set(MAC_SOURCES ${MAC_DIR}/LoRaMac.c ${MAC_DIR}/LoRaMac-api-v3.c ${MAC_DIR}/LoRaMacCrypto.c ${CRYPTO_SOURCES} ${SYSTEM_DIR}/timer.c)
include_directories(${CRYPTO_DIR} ${SYSTEM_DIR})