diff --git a/Doc/readme_generic_board.md b/Doc/readme_generic_board.md index a07ed6751..8adc47bad 100644 --- a/Doc/readme_generic_board.md +++ b/Doc/readme_generic_board.md @@ -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 + + 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 ``` @@ -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 diff --git a/cmake/modules/FindWiringPi.cmake b/cmake/modules/FindWiringPi.cmake index 4209480d9..7114c8379 100644 --- a/cmake/modules/FindWiringPi.cmake +++ b/cmake/modules/FindWiringPi.cmake @@ -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) diff --git a/src/apps/ttnmapper/generic/main.c b/src/apps/ttnmapper/generic/main.c index cca523071..5b7540f71 100644 --- a/src/apps/ttnmapper/generic/main.c +++ b/src/apps/ttnmapper/generic/main.c @@ -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 } diff --git a/src/boards/generic/CMakeSources.txt b/src/boards/generic/CMakeSources.txt index a89b33910..73d896092 100644 --- a/src/boards/generic/CMakeSources.txt +++ b/src/boards/generic/CMakeSources.txt @@ -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() \ No newline at end of file +set(RPI_LIBS rt pthread) +set(BOARD_LIBS ${WIRINGPI_LIBRARIES} ${RPI_LIBS}) +endif() diff --git a/src/boards/generic/Pi/gpio-board-pi.c b/src/boards/generic/Pi/gpio-board-pi.c index 0cbd34acd..269e4f94a 100644 --- a/src/boards/generic/Pi/gpio-board-pi.c +++ b/src/boards/generic/Pi/gpio-board-pi.c @@ -9,7 +9,7 @@ #include "board.h" #include #include "gpio.h" -#include "Log.h" +#include "log.h" #include "../posix/interrupt-simulate-posix.h" void GpioMcuInitialize(void) diff --git a/src/boards/generic/Pi/spi-board-pi.c b/src/boards/generic/Pi/spi-board-pi.c index 48cf49f95..3de67e5f1 100644 --- a/src/boards/generic/Pi/spi-board-pi.c +++ b/src/boards/generic/Pi/spi-board-pi.c @@ -6,7 +6,7 @@ */ #include "board.h" -#include "Log.h" +#include "log.h" #include #include diff --git a/src/boards/generic/spi-board.c b/src/boards/generic/spi-board.c index 1dbbef3ab..3f72ea936 100644 --- a/src/boards/generic/spi-board.c +++ b/src/boards/generic/spi-board.c @@ -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 diff --git a/src/boards/generic/spi-board.h b/src/boards/generic/spi-board.h index b38f9a8a5..1f5987642 100644 --- a/src/boards/generic/spi-board.h +++ b/src/boards/generic/spi-board.h @@ -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; diff --git a/src/mac/CMakeSources.txt b/src/mac/CMakeSources.txt index c4a423230..2ded2688b 100644 --- a/src/mac/CMakeSources.txt +++ b/src/mac/CMakeSources.txt @@ -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})