From 529460d5736287e90f3a4970d5431b672140b5c4 Mon Sep 17 00:00:00 2001 From: Kabir Mohammed Date: Fri, 29 Apr 2016 09:39:23 +0530 Subject: [PATCH] Fix RPi2 build system --- Tools/scp_upload.sh | 24 +++++ cmake/common/px4_base.cmake | 18 ++++ cmake/configs/posix_rpi2_release.cmake | 98 ++++++++++++++----- ...olchain-arm-linux-gnueabihf-raspbian.cmake | 86 ++++++++++++++++ posix-configs/rpi2/init/rcS_navio | 0 posix-configs/rpi2/mainapp.config | 17 ++++ src/firmware/posix/CMakeLists.txt | 24 +++++ .../df_bmp280_wrapper/df_bmp280_wrapper.cpp | 4 +- 8 files changed, 245 insertions(+), 26 deletions(-) create mode 100755 Tools/scp_upload.sh create mode 100644 cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake delete mode 100644 posix-configs/rpi2/init/rcS_navio create mode 100644 posix-configs/rpi2/mainapp.config diff --git a/Tools/scp_upload.sh b/Tools/scp_upload.sh new file mode 100755 index 0000000000..37b2ce9898 --- /dev/null +++ b/Tools/scp_upload.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [[ "$#" < 2 ]]; then + echo "usage: scp_upload.sh SRC1 [SRC2 ...] DEST" + exit +fi + +echo "Uploading..." + +# Get last argument +for last; do true; done + +# Go through source files and push them one by one. +i=0 +for arg +do + if [[ $((i+1)) == "$#" ]]; then + break + fi + # echo "Pushing $arg to $last" + #adb push $arg $last + scp $arg pi@px4autopilot:$last + ((i+=1)) +done diff --git a/cmake/common/px4_base.cmake b/cmake/common/px4_base.cmake index 3bdcfe1333..2098996188 100644 --- a/cmake/common/px4_base.cmake +++ b/cmake/common/px4_base.cmake @@ -528,6 +528,24 @@ function(px4_add_adb_push) ) endfunction() +function(px4_add_scp_push) + px4_parse_function_args( + NAME px4_add_upload + ONE_VALUE OS BOARD OUT DEST + MULTI_VALUE FILES DEPENDS + REQUIRED OS BOARD OUT FILES DEPENDS DEST + ARGN ${ARGN}) + + add_custom_target(${OUT} + COMMAND ${CMAKE_SOURCE_DIR}/Tools/scp_upload.sh ${FILES} ${DEST} + DEPENDS ${DEPENDS} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "uploading ${BUNDLE}" + VERBATIM + USES_TERMINAL + ) +endfunction() + #============================================================================= # diff --git a/cmake/configs/posix_rpi2_release.cmake b/cmake/configs/posix_rpi2_release.cmake index b10914951a..64d20d2fbb 100644 --- a/cmake/configs/posix_rpi2_release.cmake +++ b/cmake/configs/posix_rpi2_release.cmake @@ -1,59 +1,109 @@ include(posix/px4_impl_posix) -if ("${RPI_TOOLCHAIN_DIR}" STREQUAL "") - set(RPI_TOOLCHAIN_DIR /opt/rpi_toolchain) -endif() +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake) set(CMAKE_PROGRAM_PATH "${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin" ${CMAKE_PROGRAM_PATH} ) -set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchains/Toolchain-arm-linux-gnueabihf.cmake) +# This definition allows to differentiate if this just the usual POSIX build +# or if it is for the RPi. +add_definitions( + -D__PX4_POSIX_RPI2 + ) set(config_module_list + # + # Board support modules + # drivers/device - platforms/common - platforms/posix/px4_layer - platforms/posix/work_queue + modules/sensors + platforms/posix/drivers/df_mpu9250_wrapper + platforms/posix/drivers/df_bmp280_wrapper + platforms/posix/drivers/df_hmc5883_wrapper + platforms/posix/drivers/df_trone_wrapper + platforms/posix/drivers/df_isl29501_wrapper + + # + # System commands + # systemcmds/param systemcmds/mixer systemcmds/ver systemcmds/esc_calib - systemcmds/reboot systemcmds/topic_listener systemcmds/perf - modules/uORB - modules/param - modules/systemlib - modules/systemlib/mixer - modules/sensors - modules/mavlink + + # + # Estimation modules (EKF/ SO3 / other filters) + # + #modules/attitude_estimator_ekf + modules/ekf_att_pos_estimator modules/attitude_estimator_q modules/position_estimator_inav - modules/navigator - modules/vtol_att_control - modules/mc_pos_control + modules/local_position_estimator + modules/ekf2 + + # + # Vehicle Control + # modules/mc_att_control - modules/land_detector + modules/mc_pos_control modules/fw_att_control - modules/fw_pos_control_l1 - modules/dataman + modules/fw_pos_control_l1 + modules/vtol_att_control + + # + # Library modules + # modules/sdlog2 modules/logger modules/commander modules/load_mon + modules/param + modules/systemlib + modules/systemlib/mixer + modules/uORB + modules/dataman + modules/land_detector + modules/navigator + modules/mavlink + + # + # PX4 drivers + # + + # + # Libraries + # lib/controllib lib/mathlib lib/mathlib/math/filter - lib/conversion - lib/ecl - lib/external_lgpl lib/geo + lib/ecl lib/geo_lookup lib/launchdetection + lib/external_lgpl + lib/conversion lib/terrain_estimation lib/runway_takeoff lib/tailsitter_recovery lib/DriverFramework/framework -) + + # + # POSIX + # + platforms/common + platforms/posix/px4_layer + platforms/posix/work_queue + + ) + +set(config_df_driver_list + mpu9250 + bmp280 + hmc5883 + trone + isl29501 + ) diff --git a/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake b/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake new file mode 100644 index 0000000000..bfd68043da --- /dev/null +++ b/cmake/toolchains/Toolchain-arm-linux-gnueabihf-raspbian.cmake @@ -0,0 +1,86 @@ +# defines: +# +# NM +# OBJCOPY +# LD +# CXX_COMPILER +# C_COMPILER +# CMAKE_SYSTEM_NAME +# CMAKE_SYSTEM_VERSION +# GENROMFS +# LINKER_FLAGS +# CMAKE_EXE_LINKER_FLAGS +# CMAKE_FIND_ROOT_PATH +# CMAKE_FIND_ROOT_PATH_MODE_PROGRAM +# CMAKE_FIND_ROOT_PATH_MODE_LIBRARY +# CMAKE_FIND_ROOT_PATH_MODE_INCLUDE + +include(CMakeForceCompiler) + +if ("$ENV{RPI_TOOLCHAIN_DIR}" STREQUAL "") + message(FATAL_ERROR "RPI_TOOLCHAIN_DIR not set") +else() + set(RPI_TOOLCHAIN_DIR $ENV{RPI_TOOLCHAIN_DIR}) +endif() + +# this one is important +set(CMAKE_SYSTEM_NAME Generic) + +#this one not so much +set(CMAKE_SYSTEM_VERSION 1) + +# specify the cross compiler +find_program(C_COMPILER arm-linux-gnueabihf-gcc + PATHS ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin + NO_DEFAULT_PATH + ) + +if(NOT C_COMPILER) + message(FATAL_ERROR "could not find arm-linux-gnueabihf-gcc compiler") +endif() +cmake_force_c_compiler(${C_COMPILER} GNU) + +find_program(CXX_COMPILER arm-linux-gnueabihf-g++ + PATHS ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin + NO_DEFAULT_PATH + ) + +if(NOT CXX_COMPILER) + message(FATAL_ERROR "could not find arm-linux-gnueabihf-g++ compiler") +endif() +cmake_force_cxx_compiler(${CXX_COMPILER} GNU) + +# compiler tools +foreach(tool objcopy nm ld) + string(TOUPPER ${tool} TOOL) + find_program(${TOOL} arm-linux-gnueabihf-${tool} + PATHS ${RPI_TOOLCHAIN_DIR}/gcc-linaro-arm-linux-gnueabihf-raspbian/bin + NO_DEFAULT_PATH + ) + if(NOT ${TOOL}) + message(FATAL_ERROR "could not find arm-linux-gnueabihf-${tool}") + endif() +endforeach() + +# os tools +foreach(tool echo patch grep rm mkdir nm genromfs cp touch make unzip) + string(TOUPPER ${tool} TOOL) + find_program(${TOOL} ${tool}) + if(NOT ${TOOL}) + message(FATAL_ERROR "could not find ${TOOL}") + endif() +endforeach() + +set(LINKER_FLAGS "-Wl,-gc-sections") +set(CMAKE_EXE_LINKER_FLAGS ${LINKER_FLAGS}) +set(CMAKE_C_FLAGS ${C_FLAGS}) +set(CMAKE_CXX_LINKER_FLAGS ${C_FLAGS}) + +# where is the target environment +set(CMAKE_FIND_ROOT_PATH get_file_component(${C_COMPILER} PATH)) + +# search for programs in the build host directories +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +# for libraries and headers in the target directories +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/posix-configs/rpi2/init/rcS_navio b/posix-configs/rpi2/init/rcS_navio deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/posix-configs/rpi2/mainapp.config b/posix-configs/rpi2/mainapp.config new file mode 100644 index 0000000000..28fbb2a67c --- /dev/null +++ b/posix-configs/rpi2/mainapp.config @@ -0,0 +1,17 @@ +uorb start +param set SYS_AUTOSTART 4001 +sleep 1 +param set MAV_TYPE 2 +df_mpu9250_wrapper start +df_hmc5883_wrapper start +sensors start +commander start +ekf2 start +land_detector start multicopter +mc_pos_control start +mc_att_control start +mavlink start -u 14556 -r 1000000 +sleep 1 +mavlink stream -u 14556 -s HIGHRES_IMU -r 50 +mavlink stream -u 14556 -s ATTITUDE -r 50 +mavlink boot_complete diff --git a/src/firmware/posix/CMakeLists.txt b/src/firmware/posix/CMakeLists.txt index 030ad0793c..ce2b469961 100644 --- a/src/firmware/posix/CMakeLists.txt +++ b/src/firmware/posix/CMakeLists.txt @@ -36,6 +36,30 @@ if ("${BOARD}" STREQUAL "eagle" OR ("${BOARD}" STREQUAL "excelsior")) ${CMAKE_SOURCE_DIR}/posix-configs/eagle/flight/mainapp.config DEPENDS mainapp DEST /home/linaro) + +elseif ("${BOARD}" STREQUAL "rpi2") + + add_executable(mainapp + ${CMAKE_SOURCE_DIR}/src/platforms/posix/main.cpp + apps.h + ) + + target_link_libraries(mainapp + -Wl,--start-group + ${module_libraries} + df_driver_framework + ${df_driver_libs} + pthread m rt + -Wl,--end-group + ) + + px4_add_scp_push(OUT upload + OS ${OS} + BOARD ${BOARD} + FILES ${CMAKE_CURRENT_BINARY_DIR}/mainapp + ${CMAKE_SOURCE_DIR}/posix-configs/rpi2/mainapp.config + DEPENDS mainapp + DEST /home/pi) else() add_executable(mainapp diff --git a/src/platforms/posix/drivers/df_bmp280_wrapper/df_bmp280_wrapper.cpp b/src/platforms/posix/drivers/df_bmp280_wrapper/df_bmp280_wrapper.cpp index 3f69985cf6..0383a3ca13 100644 --- a/src/platforms/posix/drivers/df_bmp280_wrapper/df_bmp280_wrapper.cpp +++ b/src/platforms/posix/drivers/df_bmp280_wrapper/df_bmp280_wrapper.cpp @@ -178,10 +178,10 @@ int DfBmp280Wrapper::_publish(struct baro_sensor_data &data) const double R = 287.05; /* ideal gas constant in J/kg/K */ /* current pressure at MSL in kPa */ - double p1 = MSL_PRESSURE / 1000.0; + double p1 = MSL_PRESSURE / 1000.0f; /* measured pressure in kPa */ - double p = data.pressure_pa / 1000.0; + double p = data.pressure_pa / 1000.0f; /* * Solve: