Home

Awesome

teensy cmake macros

audio-test basic-test vector-test eeprom-test spi-test

minimal dependency cmake toolchain to easily compile your teensy sketches and libraries, and optionally link with c++ std libraries.

TL/DR

<details> <summary>install build dependencies (click to expand) </summary> </details> <details> <summary>clone runtime dependencies (click to expand) </summary>
 > cd /home/nic/midi-smf-reader/deps
 > git clone https://github.com/PaulStoffregen/cores.git
 > git clone https://github.com/PaulStoffregen/Audio.git
 > git clone -b Juse_Use_SdFat https://github.com/PaulStoffregen/SD.git 
 > git clone https://github.com/PaulStoffregen/Wire.git
 > git clone https://github.com/PaulStoffregen/SPI.git
 > git clone https://github.com/PaulStoffregen/SerialFlash.git
 > git clone https://github.com/PaulStoffregen/arm_math.git
 > git clone https://github.com/greiman/SdFat.git
</details> <details> <summary>custom cmake toolchain (click to expand) </summary>
set(TEENSY_VERSION 41 CACHE STRING "Set to the Teensy version corresponding to your board (40 or 41 allowed)" FORCE)
set(CPU_CORE_SPEED 600000000 CACHE STRING "Set to 600000000, 24000000, 48000000, 72000000 or 96000000 to set CPU core speed" FORCE) # Derived variables
set(COMPILERPATH "/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/") 
set(DEPSPATH "/home/nic/midi-smf-reader/deps")
set(COREPATH "${DEPSPATH}/cores/teensy4/")
find_package(teensy_cmake_macros)
</details> <details> <summary>add CMakeLists.txt (click to expand) </summary>
cmake_minimum_required(VERSION 3.5)
project(midi_smf_reader C CXX)
import_arduino_library(cores ${COREPATH})
import_arduino_library(SPI ${DEPSPATH}/SPI)
import_arduino_library(SdFat ${DEPSPATH}/SdFat/src common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver)
import_arduino_library(SD ${DEPSPATH}/SD/src)

# add custom library
teensy_add_library(my_teensy_library my_teensy_library.cpp)

teensy_add_executable(my_firmware sketch.ino)
teensy_target_link_libraries(my_firmware my_teensy_library SD SdFat SPI cores) # order is IMPORTANT because we are garbage collecting symbols --gc-collect

# if you need to link to std library (using <Vector>, etc) 
set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "")
target_link_libraries(my_firmware.elf stdc++)
</details> <details> <summary>build (click to expand) </summary>
> mkdir cmake-build-debug
> cd cmake-build-debug
> cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.toolchain.cmake" 
> make       
</details>

usage

  teensy_target_link_libraries(my_firmware mylibrary SD SdFat SPI cores)
   set(CMAKE_EXE_LINKER_FLAGS "--specs=nano.specs" CACHE INTERNAL "")
   target_link_libraries(my_firmware.elf stdc++)
  teensy_include_directories(../../src)

used in