GithubHelp home page GithubHelp logo

newdigate / teensy-cmake-macros Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 74 KB

build teensy apps and libraries using cmake and gcc-arm-none-eabi

License: MIT License

CMake 86.29% C++ 13.71%
cmake cmakelists teensy gcc-arm x-compile arm cortex cortex-m devops no-arduino noduino

teensy-cmake-macros's Introduction

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.

  • custom teensy toolchain using cmake and arm-none-eabi-gcc
  • based on ronj/teensy-cmake-template
  • targetting Teensy 4.x, tested on Teensy 4.1 (should be easy to extend for 3.x)
  • compiles library code to .a archive files to avoid unnecessary recompiling

TL/DR

install build dependencies (click to expand)
  • arm-none-eabi-gcc
  • cmake
  • teensy-cmake-macros
    > git clone https://github.com/newdigate/teensy-cmake-macros.git
    > cd teensy-cmake-macros
    > mkdir cmake-build-debug
    > cd cmake-build-debug
    > cmake ..
    > sudo make install        
clone runtime dependencies (click to expand)
  • clone necessary dependencies to a chosen location ${DEPSPATH}
 > 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
custom cmake toolchain (click to expand)
  • add a custom cmake toolchain file to your project cmake/toolchains/teensy41.toolchain.cmake
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)
  • update DEPSPATH, COMPILERPATH and COREPATH to your dependencies folder, arm-none-eabi-gcc bin folder and path to teensy4 cores
add CMakeLists.txt (click to expand)
  • create a CMakeLists.txt file in the root directory of your project
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++)
build (click to expand)
  • run from a terminal in your repository root directory
> mkdir cmake-build-debug
> cd cmake-build-debug
> cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE:FILEPATH="../cmake/toolchains/teensy41.toolchain.cmake" 
> make       

usage

  • teensy_add_executable ( TARGET files... )

    teensy_add_executable(myapplication midiread.cpp)
  • teensy_add_library ( TARGET files... )

    teensy_add_library(mylibrary library1.cpp)
  • import_arduino_library ( LibraryName LibraryPath additionalRelativeSourceFolders)

    import_arduino_library(cores ${COREPATH})
    import_arduino_library(SPI ${DEPSPATH}/SPI)        # SPI@Juse_Use_SdFat
    import_arduino_library(SdFat ${DEPSPATH}/SdFat/src common DigitalIO ExFatLib FatLib FsLib iostream SdCard SpiDriver)
    import_arduino_library(SD ${DEPSPATH}/SD/src)  
  • teensy_target_link_libraries ( TARGET libraries...)

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

used in

teensy-cmake-macros's People

Contributors

newdigate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

teensy-cmake-macros's Issues

Linking errors with .bss

Ive been trying to get your porject to work and have run into some issues. I get the following errors when I try to make my project. I get this with both make and ninja.

Would appreciate any guidance. Im coming from platformio which I had some issues with..

  • Ubuntu 22.04
  • Teensy 4.1
  • Teensy core 1.59
  • Cmake 3.27.8
  • arm-none-eabi-g++ (15:10.3-2021.07-4) 10.3.1 20210621 (release)

Main.cpp

#include <Arduino.h>

int main() {
    while (1) {
        delay(1000);
    }
}

CmakeLists.txt

cmake_minimum_required(VERSION 3.25)
import_arduino_library(cores ${COREPATH})
project(untitled C CXX)
teensy_add_executable(untitled main.cpp)

Toolchain

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 "/usr/bin/")
set(DEPSPATH "/home/craig/git/gototags/internal/hardware/teensy-1/")
set(COREPATH "/home/craig/git/gototags/internal/hardware/teensy-1/PaulStoffregen/cores/teensy4/")

Errors

[ 94%] Building C object CMakeFiles/cores.o.dir/home/craig/git/gototags/internal/hardware/teensy-1/PaulStoffregen/cores/teensy4/memcpy-armv7m.S.obj
[ 95%] Building C object CMakeFiles/cores.o.dir/home/craig/git/gototags/internal/hardware/teensy-1/PaulStoffregen/cores/teensy4/memset.S.obj
[ 96%] Linking CXX static library libcores.o.a
[ 96%] Built target cores.o
[ 97%] Building CXX object CMakeFiles/untitled.elf.dir/main.cpp.obj
[ 98%] Linking CXX executable untitled.elf
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: address 0x100 of untitled.elf section `.bss' is not within region `DTCM'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: address 0x100 of untitled.elf section `.bss' is not within region `DTCM'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol ImageVectorTable; not setting start address
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/untitled.elf.dir/build.make:97: untitled.elf] Error 1
make[1]: *** [CMakeFiles/Makefile2:113: CMakeFiles/untitled.elf.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.