diff --git a/.ci/Jenkinsfile-hardware_px4fmu-v2 b/.ci/Jenkinsfile-hardware_px4fmu-v2 new file mode 100644 index 0000000000..6a747b2099 --- /dev/null +++ b/.ci/Jenkinsfile-hardware_px4fmu-v2 @@ -0,0 +1,70 @@ +pipeline { + agent none + stages { + + stage('Build') { + agent { + docker { + image 'px4io/px4-dev-nuttx:2018-08-05' + args '-e CCACHE_BASEDIR=$WORKSPACE -v ${CCACHE_DIR}:${CCACHE_DIR}:rw' + } + } + steps { + sh 'export' + sh 'make distclean' + sh 'ccache -z' + sh 'git fetch --tags' + sh 'make nuttx_px4fmu-v2_test' + sh 'make sizes' + sh 'ccache -s' + stash includes: 'build/nuttx_px4fmu-v2_test/nuttx_px4fmu-v2_test.elf', name: 'px4fmu-v2_test' + stash includes: 'Tools/HIL/monitor_firmware_upload.py, Tools/HIL/run_tests.py', name: 'scripts' + sh 'make distclean' + } + } // stage Build + + stage('Flash and Run') { + agent { + label 'px4fmu-v2' + } + steps { + script { + try { + sh 'export' + sh 'find /dev/serial' + unstash 'px4fmu-v2_test' + sh ''' gdb -nx --batch \ + -ex "target extended-remote `find /dev/serial -name *Black_Magic_Probe_*-if00`" \ + -ex "monitor version" \ + -ex "monitor connect_srst enable" \ + -ex "monitor swdp_scan" \ + -ex "attach 1" \ + -ex "load" \ + -ex "kill" \ + build/nuttx_px4fmu-v2_test/nuttx_px4fmu-v2_test.elf + ''' + unstash 'scripts' + sh './Tools/HIL/monitor_firmware_upload.py --device `find /dev/serial -name *Black_Magic_Probe_*-if02` --baudrate 57600' + sh './Tools/HIL/run_tests.py --device `find /dev/serial -name *Black_Magic_Probe_*-if02`' + } catch (Exception err) { + // always report passed for now + currentBuild.result = 'SUCCESS' + } + } // script + } + options { + timeout(time: 300, unit: 'SECONDS') + } + + } // stage Flash + + } // stages + environment { + CCACHE_DIR = '/tmp/ccache' + CI = true + } + options { + buildDiscarder(logRotator(numToKeepStr: '10', artifactDaysToKeepStr: '30')) + timeout(time: 60, unit: 'MINUTES') + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index f4c8f4a196..f7d70d7826 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,8 +139,6 @@ list(GET config_args 0 OS) list(GET config_args 1 BOARD) list(GET config_args 2 LABEL) -set(THREADS "4" CACHE STRING "number of threads to use for external build processes") -set(DEBUG_PORT "/dev/ttyACM0" CACHE STRING "debugging port") set(EXTERNAL_MODULES_LOCATION "" CACHE STRING "External modules source location") if (NOT EXTERNAL_MODULES_LOCATION STREQUAL "") @@ -301,9 +299,7 @@ message(STATUS "C++ compiler: ${cxx_compiler_version_short}") #============================================================================= # external libraries # -px4_os_prebuild_targets(OUT prebuild_targets - BOARD ${BOARD} - THREADS ${THREADS}) +px4_os_prebuild_targets(OUT prebuild_targets BOARD ${BOARD}) #============================================================================= # build flags diff --git a/Jenkinsfile b/Jenkinsfile index 3a73dda27a..cd34e52127 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,7 +2,7 @@ pipeline { agent none stages { - stage('Analysis') { + stage('Analysis') { parallel { diff --git a/Tools/HIL/monitor_firmware_upload.py b/Tools/HIL/monitor_firmware_upload.py new file mode 100755 index 0000000000..ed4e78694a --- /dev/null +++ b/Tools/HIL/monitor_firmware_upload.py @@ -0,0 +1,35 @@ +#! /usr/bin/python + +import serial, time +import subprocess +from subprocess import call, Popen +from argparse import ArgumentParser +import re + +def monitor_firmware_upload(port, baudrate): + databits = serial.EIGHTBITS + stopbits = serial.STOPBITS_ONE + parity = serial.PARITY_NONE + ser = serial.Serial(port, baudrate, databits, parity, stopbits, 100) + + finished = 0 + + while finished == 0: + serial_line = ser.readline() + print(serial_line.replace('\n','')) + + if "NuttShell (NSH)" in serial_line: + finished = 1 + time.sleep(0.05) + ser.close() + +def main(): + parser = ArgumentParser(description=__doc__) + parser.add_argument('--device', "-d", nargs='?', default = None, help='') + parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) + args = parser.parse_args() + + monitor_firmware_upload(args.device, args.baudrate) + +if __name__ == "__main__": + main() diff --git a/Tools/HIL/run_tests.py b/Tools/HIL/run_tests.py new file mode 100755 index 0000000000..3d4e92fa72 --- /dev/null +++ b/Tools/HIL/run_tests.py @@ -0,0 +1,49 @@ +#! /usr/bin/python + +import serial, time +import subprocess +from subprocess import call, Popen +from argparse import ArgumentParser +import re + +def do_tests(port, baudrate): + databits = serial.EIGHTBITS + stopbits = serial.STOPBITS_ONE + parity = serial.PARITY_NONE + ser = serial.Serial(port, baudrate, databits, parity, stopbits, 100) + ser.write('\n\n') + + finished = 0 + while finished == 0: + serial_line = ser.readline() + print(serial_line.replace('\n','')) + + if "nsh>" in serial_line: + finished = 1 + time.sleep(0.05) + + ser.write('tests perf\n') + + finished = 0 + while finished == 0: + serial_line = ser.readline() + print(serial_line.replace('\n','')) + + if "perf PASSED" in serial_line: + finished = 1 + ser.close() + + time.sleep(0.05) + + ser.close() + +def main(): + parser = ArgumentParser(description=__doc__) + parser.add_argument('--device', "-d", nargs='?', default = None, help='') + parser.add_argument("--baudrate", "-b", dest="baudrate", type=int, help="Mavlink port baud rate (default=57600)", default=57600) + args = parser.parse_args() + + do_tests(args.device, args.baudrate) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/platforms/nuttx/CMakeLists.txt b/platforms/nuttx/CMakeLists.txt index 038583aa72..d4e299293e 100644 --- a/platforms/nuttx/CMakeLists.txt +++ b/platforms/nuttx/CMakeLists.txt @@ -298,11 +298,92 @@ if (BLOATY_PROGRAM) endif() # debugger helpers -configure_file(gdbinit.in .gdbinit) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Debug/gdbinit.in ${PX4_BINARY_DIR}/.gdbinit) add_custom_target(debug - COMMAND ${GDB} $ - DEPENDS ${FW_NAME} ${CMAKE_CURRENT_BINARY_DIR}/.gdbinit + COMMAND ${GDB} -iex 'set auto-load safe-path ${PX4_BINARY_DIR}' $ + DEPENDS ${FW_NAME} ${PX4_BINARY_DIR}/.gdbinit + WORKING_DIRECTORY ${PX4_BINARY_DIR} + USES_TERMINAL + ) + +file(GLOB_RECURSE black_magic_probe_path + FOLLOW_SYMLINKS + /dev/serial/by-id/usb-Black_Sphere_Technologies_Black_Magic_Probe_*-if00 + ) +file(GLOB_RECURSE black_magic_probe_console_path + FOLLOW_SYMLINKS + /dev/serial/by-id/usb-Black_Sphere_Technologies_Black_Magic_Probe_*-if02 + ) + +if(black_magic_probe_path) + + add_custom_target(blackmagic_debug + COMMAND ${GDB} --nh + -iex 'set auto-load safe-path ${PX4_BINARY_DIR}' + -ex 'target extended-remote ${black_magic_probe_path}' + -ex 'monitor version' + -ex 'monitor connect_srst enable' + -ex 'monitor swdp_scan' + -ex 'attach 1' + -ex 'load' + -ex 'run' + $ + DEPENDS ${FW_NAME} ${PX4_BINARY_DIR}/.gdbinit + WORKING_DIRECTORY ${PX4_BINARY_DIR} + USES_TERMINAL + ) + + add_custom_target(blackmagic_upload + COMMAND ${GDB} --nx --batch + -ex 'target extended-remote ${black_magic_probe_path}' + -ex 'monitor version' + -ex 'monitor connect_srst enable' + -ex 'monitor swdp_scan' + -ex 'attach 1' + -ex 'load' + -ex 'kill' + $ + DEPENDS ${FW_NAME} + WORKING_DIRECTORY ${PX4_BINARY_DIR} + USES_TERMINAL + COMMENT "Uploading with Black Magic Probe" + ) + + add_custom_target(blackmagic_console + COMMAND screen -t "${BOARD} console" ${black_magic_probe_console_path} 57600 8N1 + USES_TERMINAL + ) + +endif() + +add_custom_target(jlink_upload + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/Debug/jlink.sh + COMMAND ${GDB} --nx --batch + -iex 'set auto-load safe-path ${PX4_BINARY_DIR}' + -ex 'target remote localhost:2331' + -ex 'monitor reset' + -ex 'load' + -ex 'kill' + $ + DEPENDS ${FW_NAME} ${PX4_BINARY_DIR}/.gdbinit + WORKING_DIRECTORY ${PX4_BINARY_DIR} + USES_TERMINAL + ) + +add_custom_target(jlink_debug + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/Debug/jlink.sh + COMMAND ${GDB} --nh + -iex 'set auto-load safe-path ${PX4_BINARY_DIR}' + -ex 'target remote localhost:2331' + -ex 'monitor reset' + -ex 'load' + -ex 'monitor reset' + -ex 'continue' + $ + DEPENDS ${FW_NAME} ${PX4_BINARY_DIR}/.gdbinit + WORKING_DIRECTORY ${PX4_BINARY_DIR} USES_TERMINAL ) @@ -319,7 +400,9 @@ ExternalProject_Add(FlameGraph ) add_custom_target(profile - COMMAND ${CMAKE_COMMAND} -E env PATH="${PX4_BINARY_DIR}/external/Source/FlameGraph:$ENV{PATH}" ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/poor-mans-profiler.sh --elf=$ --nsamples=10000 + COMMAND ${CMAKE_COMMAND} -E env PATH="${PX4_BINARY_DIR}/external/Source/FlameGraph:$ENV{PATH}" + ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/poor-mans-profiler.sh --elf=$ --nsamples=10000 DEPENDS ${FW_NAME} ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/poor-mans-profiler.sh FlameGraph USES_TERMINAL + WORKING_DIRECTORY ${PX4_BINARY_DIR} ) diff --git a/platforms/nuttx/Debug/PX4 b/platforms/nuttx/Debug/PX4 index b3d06c0e06..ee7b3ec746 100644 --- a/platforms/nuttx/Debug/PX4 +++ b/platforms/nuttx/Debug/PX4 @@ -1,8 +1,6 @@ # # Various PX4-specific macros # -source platforms/nuttx/Debug/NuttX -source platforms/nuttx/Debug/ARMv7M echo Loading PX4 GDB macros. Use 'help px4' for more information.\n diff --git a/platforms/nuttx/gdbinit.in b/platforms/nuttx/Debug/gdbinit.in similarity index 68% rename from platforms/nuttx/gdbinit.in rename to platforms/nuttx/Debug/gdbinit.in index 5cd252d843..3996e71fd5 100644 --- a/platforms/nuttx/gdbinit.in +++ b/platforms/nuttx/Debug/gdbinit.in @@ -2,9 +2,13 @@ source ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/PX4 source ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/NuttX source ${PX4_SOURCE_DIR}/platforms/nuttx/Debug/ARMv7M -target extended-remote ${DEBUG_PORT} -monitor swdp_scan -attach 1 -monitor vector_catch disable hard set mem inaccessible-by-default off + set print pretty + +set pagination off + +set history save on +set history size unlimited + +set logging on diff --git a/platforms/nuttx/Debug/jlink.sh b/platforms/nuttx/Debug/jlink.sh new file mode 100755 index 0000000000..3d4873aff9 --- /dev/null +++ b/platforms/nuttx/Debug/jlink.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +JLinkGDBServerCLExe -startserver -USB -device Cortex-M4 -if SWD -speed auto > jlink.log & diff --git a/platforms/nuttx/Debug/olimex-px4fmu-debug.cfg b/platforms/nuttx/Debug/olimex-px4fmu-debug.cfg deleted file mode 100644 index d0cf066bf0..0000000000 --- a/platforms/nuttx/Debug/olimex-px4fmu-debug.cfg +++ /dev/null @@ -1,22 +0,0 @@ -# program a bootable device load on a mavstation -# To run type openocd -f mavprogram.cfg - -source [find interface/olimex-arm-usb-ocd-h.cfg] -source [find px4fmu-board.cfg] - -init -halt - -# Find the flash inside this CPU -flash probe 0 - -# erase it (128 pages) then program and exit - -#flash erase_sector 0 0 127 -# stm32f1x mass_erase 0 - -# It seems that Pat's image has a start address offset of 0x1000 but the vectors need to be at zero, so fixbin.sh moves things around -#flash write_bank 0 fixed.bin 0 -#flash write_image firmware.elf -#shutdown - diff --git a/platforms/nuttx/Debug/openocd.gdbinit b/platforms/nuttx/Debug/openocd.gdbinit deleted file mode 100644 index 9619ba529e..0000000000 --- a/platforms/nuttx/Debug/openocd.gdbinit +++ /dev/null @@ -1,21 +0,0 @@ -target remote :3333 - -# Don't let GDB get confused while stepping -define hook-step - mon cortex_m maskisr on -end -define hookpost-step - mon cortex_m maskisr off -end - -mon init -mon stm32_init -# mon reset halt -mon poll -mon cortex_m maskisr auto -set mem inaccessible-by-default off -set print pretty -source platforms/nuttx/Debug/PX4 - -echo PX4 resumed, press ctrl-c to interrupt\n -continue diff --git a/platforms/nuttx/Debug/poor-mans-profiler.sh b/platforms/nuttx/Debug/poor-mans-profiler.sh index 4f4add5532..d1a7fd56ae 100755 --- a/platforms/nuttx/Debug/poor-mans-profiler.sh +++ b/platforms/nuttx/Debug/poor-mans-profiler.sh @@ -18,7 +18,7 @@ # set -e -root=$(dirname $0)/.. +root=$(dirname $0) function die() { @@ -77,7 +77,7 @@ do shift done -[[ -z "$elf" ]] && die "Please specify the ELF file location, e.g.: build/px4fmu-v4_default/src/firmware/nuttx/firmware_nuttx" +[[ -z "$elf" ]] && die "Please specify the ELF file location, e.g.: build/nuttx_px4fmu-v4_default/nuttx_px4fmu-v4_default.elf" # # Temporary files @@ -102,7 +102,8 @@ then do if [[ "$taskname" = "" ]] then - arm-none-eabi-gdb $elf --batch -ex "set print asm-demangle on" \ + arm-none-eabi-gdb $elf --nx --quiet --batch \ + -ex "set print asm-demangle on" \ -ex "target extended /dev/ttyACM0" \ -ex "monitor swdp_scan" \ -ex "attach 1" \ @@ -111,11 +112,12 @@ then | sed -n 's/\(#.*\)/\1/p' \ >> $stacksfile else - arm-none-eabi-gdb $elf --batch -ex "set print asm-demangle on" \ + arm-none-eabi-gdb $elf --nx --quiet --batch \ + -ex "set print asm-demangle on" \ -ex "target extended /dev/ttyACM0" \ -ex "monitor swdp_scan" \ -ex "attach 1" \ - -ex "source $root/platforms/nuttx/Debug/Nuttx.py" \ + -ex "source $root/Nuttx.py" \ -ex "show mybt $taskname" \ 2> $gdberrfile \ | sed -n 's/0\.0:\(#.*\)/\1/p' \ diff --git a/platforms/nuttx/Debug/px4fmu-board.cfg b/platforms/nuttx/Debug/px4fmu-board.cfg deleted file mode 100644 index 9e8988d0ad..0000000000 --- a/platforms/nuttx/Debug/px4fmu-board.cfg +++ /dev/null @@ -1,37 +0,0 @@ -# The latest defaults in OpenOCD 0.7.0 are actually prettymuch correct for the px4fmu - -# increase working area to 32KB for faster flash programming -set WORKAREASIZE 0x8000 - -source [find target/stm32f4x.cfg] - -# needed for px4 -reset_config trst_only - -proc stm32_reset {} { - reset halt -# FIXME - needed to init periphs on reset -# 0x40023800 RCC base -# 0x24 RCC_APB2 0x75933 -# RCC_APB2 0 -} - -# perform init that is required on each connection to the target -proc stm32_init {} { - - # force jtag to not shutdown during sleep - #uint32_t cr = getreg32(STM32_DBGMCU_CR); - #cr |= DBGMCU_CR_STANDBY | DBGMCU_CR_STOP | DBGMCU_CR_SLEEP; - #putreg32(cr, STM32_DBGMCU_CR); - mww 0xe0042004 00000007 -} - -# if srst is not fitted use SYSRESETREQ to -# perform a soft reset -cortex_m reset_config sysresetreq - -# Let GDB directly program elf binaries -gdb_memory_map enable - -# doesn't work yet -gdb_flash_program disable diff --git a/platforms/nuttx/Debug/runopenocd.sh b/platforms/nuttx/Debug/runopenocd.sh deleted file mode 100755 index 56c005a76f..0000000000 --- a/platforms/nuttx/Debug/runopenocd.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -openocd -f interface/olimex-arm-usb-ocd-h.cfg -f $DIR/px4fmu-board.cfg diff --git a/platforms/nuttx/cmake/px4_impl_os.cmake b/platforms/nuttx/cmake/px4_impl_os.cmake index 216138d38f..9d0697cb7c 100644 --- a/platforms/nuttx/cmake/px4_impl_os.cmake +++ b/platforms/nuttx/cmake/px4_impl_os.cmake @@ -226,7 +226,6 @@ endfunction() # # Input: # BOARD : board -# THREADS : number of threads for building # # Output: # OUT : the target list @@ -237,7 +236,7 @@ endfunction() function(px4_os_prebuild_targets) px4_parse_function_args( NAME px4_os_prebuild_targets - ONE_VALUE OUT BOARD THREADS + ONE_VALUE OUT BOARD REQUIRED OUT BOARD ARGN ${ARGN}) diff --git a/platforms/posix/cmake/px4_impl_os.cmake b/platforms/posix/cmake/px4_impl_os.cmake index 0c5cb024b8..ed29e8347a 100644 --- a/platforms/posix/cmake/px4_impl_os.cmake +++ b/platforms/posix/cmake/px4_impl_os.cmake @@ -429,7 +429,6 @@ endfunction() # # Input: # BOARD : board -# THREADS : number of threads for building # # Output: # OUT : the target list @@ -440,7 +439,7 @@ endfunction() function(px4_os_prebuild_targets) px4_parse_function_args( NAME px4_os_prebuild_targets - ONE_VALUE OUT BOARD THREADS + ONE_VALUE OUT BOARD REQUIRED OUT BOARD ARGN ${ARGN}) diff --git a/platforms/qurt/cmake/px4_impl_os.cmake b/platforms/qurt/cmake/px4_impl_os.cmake index 6824c8968c..d5797f8337 100644 --- a/platforms/qurt/cmake/px4_impl_os.cmake +++ b/platforms/qurt/cmake/px4_impl_os.cmake @@ -224,7 +224,6 @@ endfunction() # # Input: # BOARD : board -# THREADS : number of threads for building # # Output: # OUT : the target list @@ -235,7 +234,7 @@ endfunction() function(px4_os_prebuild_targets) px4_parse_function_args( NAME px4_os_prebuild_targets - ONE_VALUE OUT BOARD THREADS + ONE_VALUE OUT BOARD REQUIRED OUT BOARD ARGN ${ARGN})