Skip to content

Commit

Permalink
Added support for Teensy upload and related improvements (rosserial_a…
Browse files Browse the repository at this point in the history
…rduino)

Size script is now correctly generated and uses teensy_size

Upload target using teensy_loader_cli works correctly

Arduino/Teensy hardware platforms are added correctly,
whether with or without extra avr directory

required_variables now also detects files that were not found
  • Loading branch information
warnerjon12 committed Mar 4, 2022
1 parent 4f37a02 commit cf90ee3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 16 deletions.
81 changes: 65 additions & 16 deletions rosserial_arduino/arduino-cmake/cmake/Platform/Arduino.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -661,34 +661,39 @@ function(REGISTER_HARDWARE_PLATFORM PLATFORM_PATH)
find_file(${PLATFORM}_CORES_PATH
NAMES cores
PATHS ${PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to directory containing the Arduino core sources.")

find_file(${PLATFORM}_VARIANTS_PATH
NAMES variants
PATHS ${PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to directory containing the Arduino variant sources.")

find_file(${PLATFORM}_BOOTLOADERS_PATH
NAMES bootloaders
PATHS ${PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to directory containing the Arduino bootloader images and sources.")

find_file(${PLATFORM}_PROGRAMMERS_PATH
NAMES programmers.txt
PATHS ${PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to Arduino programmers definition file.")

find_file(${PLATFORM}_BOARDS_PATH
NAMES boards.txt
PATHS ${PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to Arduino boards definition file.")

if(${PLATFORM}_BOARDS_PATH)
load_arduino_style_settings(${PLATFORM}_BOARDS "${PLATFORM_PATH}/boards.txt")
load_arduino_style_settings(${PLATFORM}_BOARDS "${${PLATFORM}_BOARDS_PATH}")
endif()

if(${PLATFORM}_PROGRAMMERS_PATH)
load_arduino_style_settings(${PLATFORM}_PROGRAMMERS "${ARDUINO_PROGRAMMERS_PATH}")
load_arduino_style_settings(${PLATFORM}_PROGRAMMERS "${${PLATFORM}_PROGRAMMERS_PATH}")
endif()

if(${PLATFORM}_VARIANTS_PATH)
Expand Down Expand Up @@ -1260,7 +1265,11 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
set(UPLOAD_TARGET ${TARGET_NAME}-upload)
set(AVRDUDE_ARGS)

setup_arduino_bootloader_args(${BOARD_ID} ${TARGET_NAME} ${PORT} "${AVRDUDE_FLAGS}" AVRDUDE_ARGS)
if(NOT DEFINED TEENSY)
setup_arduino_bootloader_args(${BOARD_ID} ${TARGET_NAME} ${PORT} "${AVRDUDE_FLAGS}" AVRDUDE_ARGS)
else()
set(AVRDUDE_ARGS "--mcu=${${BOARD_ID}.build.mcu}" ${AVRDUDE_FLAGS})
endif()

if(NOT AVRDUDE_ARGS)
message("Could not generate default avrdude bootloader args, aborting!")
Expand All @@ -1272,12 +1281,20 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
endif()
set(TARGET_PATH ${EXECUTABLE_OUTPUT_PATH}/${TARGET_NAME})

list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH}.hex")
list(APPEND AVRDUDE_ARGS "-Ueeprom:w:${TARGET_PATH}.eep:i")
add_custom_target(${UPLOAD_TARGET}
${ARDUINO_AVRDUDE_PROGRAM}
${AVRDUDE_ARGS}
DEPENDS ${TARGET_NAME})
if(DEFINED TEENSY)
list(APPEND AVRDUDE_ARGS "${TARGET_PATH}.hex")
add_custom_target(${UPLOAD_TARGET}
${TEENSY_LOADER_CLI_PROGRAM}
${AVRDUDE_ARGS}
DEPENDS ${TARGET_NAME})
else()
list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_PATH}.hex")
list(APPEND AVRDUDE_ARGS "-Ueeprom:w:${TARGET_PATH}.eep:i")
add_custom_target(${UPLOAD_TARGET}
${ARDUINO_AVRDUDE_PROGRAM}
${AVRDUDE_ARGS}
DEPENDS ${TARGET_NAME})
endif()

# Global upload target
if(NOT TARGET upload)
Expand Down Expand Up @@ -2012,6 +2029,21 @@ endfunction()
function(SETUP_ARDUINO_SIZE_SCRIPT OUTPUT_VAR)
set(ARDUINO_SIZE_SCRIPT_PATH ${CMAKE_BINARY_DIR}/CMakeFiles/FirmwareSize.cmake)

if(DEFINED TEENSY)

file(WRITE ${ARDUINO_SIZE_SCRIPT_PATH} "
set(TEENSYSIZE_PROGRAM ${TEENSYSIZE_PROGRAM})
execute_process(COMMAND \${TEENSYSIZE_PROGRAM} \${FIRMWARE_IMAGE}
OUTPUT_VARIABLE SIZE_OUTPUT)
string(STRIP \"\${SIZE_OUTPUT}\" RAW_SIZE_OUTPUT)
message(\"\${RAW_SIZE_OUTPUT}\\n\")
")

else()

file(WRITE ${ARDUINO_SIZE_SCRIPT_PATH} "
set(AVRSIZE_PROGRAM ${AVRSIZE_PROGRAM})
set(AVRSIZE_FLAGS -C --mcu=\${MCU})
Expand Down Expand Up @@ -2089,6 +2121,8 @@ function(SETUP_ARDUINO_SIZE_SCRIPT OUTPUT_VAR)
endif()
")

endif(DEFINED TEENSY)

set(${OUTPUT_VAR} ${ARDUINO_SIZE_SCRIPT_PATH} PARENT_SCOPE)
endfunction()

Expand Down Expand Up @@ -2194,6 +2228,8 @@ function(REQUIRED_VARIABLES)
foreach(VAR ${INPUT_VARS})
if ("${${VAR}}" STREQUAL "")
message(FATAL_ERROR "${VAR} not set: ${INPUT_MSG}")
elseif("${${VAR}}" STREQUAL "${VAR}-NOTFOUND")
message(FATAL_ERROR "${VAR} file not found: ${INPUT_MSG}")
endif()
endforeach()
endfunction()
Expand Down Expand Up @@ -2390,17 +2426,27 @@ if(DEFINED TEENSY)
find_file(TEENSY_LIBRARIES_PATH
NAMES libraries
PATHS ${TEENSY_PLATFORM_PATH}
PATH_SUFFIXES avr
DOC "Path to directory containing the Teensy libraries.")

find_file(TEENSYDUINO_VERSION_PATH
NAMES lib/teensyduino.txt
PATHS ${ARDUINO_SDK_PATH}
DOC "Path to Teensyduino version file.")

# TODO: actually use this or maybe hardware/tools/teensy_size
# TODO: also allow upload
find_program(ARMSIZE_PROGRAM
NAMES arm-none-eabi-size)
find_file(TEENSY_TOOLS_PATH
NAMES hardware/tools
PATHS ${ARDUINO_SDK_PATH}
DOC "Path to Teensy tools.")

find_program(TEENSY_LOADER_CLI_PROGRAM
NAMES teensy_loader_cli
PATHS ${TEENSY_TOOLS_PATH}
DOC "Path to teensy_loader_cli programmer binary.")

find_program(TEENSYSIZE_PROGRAM
NAMES teensy_size
PATHS ${TEENSY_TOOLS_PATH})

if(NOT CMAKE_OBJCOPY)
find_program(ARMOBJCOPY_PROGRAM
Expand All @@ -2416,7 +2462,9 @@ if(DEFINED TEENSY)
TEENSY_LIBRARIES_PATH
TEENSY_BOARDS_PATH
TEENSYDUINO_VERSION_PATH
ARMSIZE_PROGRAM
TEENSY_TOOLS_PATH
TEENSY_LOADER_CLI_PROGRAM
TEENSYSIZE_PROGRAM
${ADDITIONAL_REQUIRED_VARS}
MSG "Invalid Arduino SDK path (${ARDUINO_SDK_PATH}).\n")

Expand All @@ -2427,7 +2475,6 @@ if(DEFINED TEENSY)

message(STATUS "Teensyduino version ${TEENSYDUINO_VERSION}: ${ARDUINO_SDK_PATH}")

# TODO update
setup_arduino_size_script(ARDUINO_SIZE_SCRIPT)
set(ARDUINO_SIZE_SCRIPT ${ARDUINO_SIZE_SCRIPT} CACHE INTERNAL "Arduino Size Script")

Expand All @@ -2448,5 +2495,7 @@ if(DEFINED TEENSY)
TEENSY_LIBRARIES_PATH
TEENSY_BOARDS_PATH
TEENSYDUINO_VERSION_PATH
ARMSIZE_PROGRAM)
TEENSY_TOOLS_PATH
TEENSY_LOADER_CLI_PROGRAM
TEENSYSIZE_PROGRAM)
endif()
4 changes: 4 additions & 0 deletions rosserial_arduino/arduino-cmake/cmake/TeensyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake)
endif()

include(ArduinoToolchain)

list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/arm)
list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/arm/arm-none-eabi)

set(TEENSY "" CACHE STRING "Using one of the Teensy boards")
set(CMAKE_SYSTEM_NAME Arduino)
set(CMAKE_SYSTEM_PROCESSOR arm)
Expand Down

0 comments on commit cf90ee3

Please sign in to comment.