Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 20 of 20

Thread: Toolchain for teensy 3.6

  1. #1
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34

    Toolchain for teensy 3.6

    Good morning,

    for my PhD I’ve written a c++ library in order to simulate electric circuits. The goal is to use this library on arm platforms too, such as RPi (yet accomplished) but not yet for teensy with a really small and simplified example.

    Does an up-to-date version of toolchain exist? I’ve found a git repository but it is several years old.

    To compile it on my RPi I’ve used the compiler Linaro for arm-Linux-gnuabihf (https://releases.linaro.org/componen...nux-gnueabihf/), cmake for creating the project (with the toolchain) and Qt as IDE. Could it be possible doing the same for the teensy?

    Thanks

    Borja

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    You have it already, if you ever wrote a program for Teensy
    It is in arduino/hardware/tools/arm

  3. #3
    Senior Member
    Join Date
    Feb 2015
    Location
    Finland
    Posts
    216
    And it is actually arm-none-eabi toolchain, which is the freestanding (not under any OS) version; arm-gnuabi is the soft-floating-point ARM under an OS with GNU C library, and arm-gnuabihf is for ARM with hardware floating point support used under an OS with GNU C library.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,458
    You can get a newer toolchain here.

    https://developer.arm.com/tools-and-...u-rm/downloads

    However, ARM website does not provide binary downloads for any ARM-based Linux platforms, like Raspberry Pi. You will need to build it from source. You'd think ARM would be more interested in promoting use of ARM-based Linux, but they only build ready-to-use toolchains for X86 platforms.

    These newer toolchains may have minor compatibility issues with some of the code published for Teensy. If you want things to "just work", I do not recommend using a newer or different toolchain than the one we provide with Teensyduino. Likewise, we use C++14 dialect for C++ compiling. Others have not been tested and may have compatibility issues.

    Only a few months ago, some Coremark speed comparisons were done between the older toolchain we currently have in Teensyduino and the latest (at the time) available from that download page. The speed of compiled code with -O3 (fastest) optimization was similar but slightly slower in the (then) latest version. If you will be using the well supported C++14 dialect, there is little reason to switch to the newer toolchains.

  5. #5
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Hello,

    Thank you for the answers.

    I think there was a misunderstanding when I wrote toolchain. What I meant was “cmake toolchain” in the same way I used it for pc or rpi.

    Anyway I’ll take a look at your responses and try to compile a reduced project with several .hpp and .cpp. This is very important, because it’s not really doable pasting the complete code in a single file.

    By the way I’ve already downloaded the Linaro arm-none-eabi dist, however I needed a cmake toolchain ir order to create a simple project and compile it on Qt managing without Arduino ide.

    Thanks

    Borja

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    If you can't compile it with teensyduino, it's not very compatible...
    Why don't you make a library form it? This way everybody can use it easyly.

    Apart from that: of course can Arduino use several .h and .cpp files..

  7. #7
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    563
    This is the cmake toolchain I use for Teensy based projects:

    Code:
    set(CMAKE_SYSTEM_NAME Generic)
    set(CMAKE_SYSTEM_PROCESSOR arm)
    set(CMAKE_C_COMPILER arm-none-eabi-gcc)
    set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
    set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
    set(CMAKE_SIZE arm-none-eabi-size)
    set(CMAKE_C_COMPILER_ID GNU)
    set(CMAKE_CXX_COMPILER_ID GNU)
    set(CMAKE_C_COMPILER_FORCED TRUE)
    set(CMAKE_CXX_COMPILER_FORCED TRUE)

  8. #8
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Hi again,

    one year later I am resuming the task of compiling and running parts of the code of my thesis on ARM-M platforms. I've downloaded the toolchain (GNU Arm Embedded Toolchain v2020) from ARM website and created a Cmakelists for a simple test project using the aforementioned toolchain. In order to create the project for Visual Studio 2019 in my repository, I am launching Cmake with the command "cmake .. -DCMAKE_TOOLCHAIN_FILE=Teensy.cmake" on Windows10. However, Cmake assigned as C/C++ compilers the Visual Studio ones.

    I have several questions:

    • is it possible to compile the project on Windows using Visual Studio or I have to change IDE or OS?
    • I don't know if Cmake doesn't find the Toolchain in the path or it is necessary to be more explicit in the Cmakelists to assign the ARM compilers.
    • Is there a template to create the project using Cmake? If not, may you point out where there are mistakes in my files?
    • I attached Teensy.cmake, Cmakelists and the main program.


    Thank you so much
    Borja

    Here Teensy.cmake:

    Code:
    # Type of processor
    set(CMAKE_SYSTEM_NAME Generic)
    set(CMAKE_SYSTEM_PROCESSOR arm)
    
    # Where the target environment is 
    set(CMAKE_FIND_ROOT_PATH ${CMAKE_SOURCE_DIR}/arm-none-eabi)
    
    # Specify the cross compiler
    set(CMAKE_C_COMPILER arm-none-eabi-gcc)
    set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
    
    
    set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
    set(CMAKE_SIZE arm-none-eabi-size)
    set(CMAKE_C_COMPILER_ID GNU)
    set(CMAKE_CXX_COMPILER_ID GNU)
    set(CMAKE_C_COMPILER_FORCED TRUE)
    set(CMAKE_CXX_COMPILER_FORCED TRUE)
    Here Cmakelists:

    Code:
    cmake_minimum_required(VERSION 2.8)
    set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/Teensy.cmake")
    
    set(PROJECT_NAME Teensy)
    project(${PROJECT_NAME})
    
    set (${PROJECT_NAME}_FILES 
    		${${PROJECT_NAME}_SOURCE_DIR}/src/main.cpp
    		)
    
    add_executable (${PROJECT_NAME} ${${PROJECT_NAME}_FILES})
    target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src)
    Here the main program:

    Code:
    int main(void)
    {
    	// Main loop
    	while(1)
    	{
    	}
    }

  9. #9
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    563
    Hard to say what the issue is without more insight into how you're adding files and what the error messages you get are.

    We have a version of the Teensy 3.x core that we use for our projects and we use CMake for our build tooling. Here is the repo:
    https://gitlab.com/bolderflight/software/core

    There is an example in the examples directory of building an executable with the core library.

    EDIT: I should add that our version of the core lib is not comprehensive - we are working mostly in aircraft flight control and data acquisition systems, so the functionality we include is focused on supporting that work.

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,458
    Quote Originally Posted by Borja View Post
    resuming the task of compiling and running parts of the code of my thesis on ARM-M platforms.
    Are you using Teensy? Which model(s)?

  11. #11
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Hi,

    right now I am using T3.6, but I've bought T4.1 last week and I'd like to try on both.

    Thanks

  12. #12
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    When I run Cmake using the command cmake .. -DCMAKE_TOOLCHAIN_FILE=Teensy.cmake (files previously attached in this thread), no error occurrs, but Cmake assigns as compiler Visual Studio instead of ARM ones.

    I am attaching a screenshot of the Windows cmd where this happens.

    Hope this helps.

    By the way, I am going to take a look at the Gitlab repository example.

    Thanks!

    Click image for larger version. 

Name:	cmake.png 
Views:	9 
Size:	32.4 KB 
ID:	20914

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,043
    If you can live with standard makefiles and gnu make instead of Cmake you can have a look at VisualTeensy. It automatically generates makefiles for your Teensy configuration (board, settings, libraries) and sets up VisualCode to use this makefile for building and uploading. Should run out of the box.

    Here the repo (Win10 binaries included in the releases section) https://github.com/luni64/VisualTeensy. Instructions can be found here: https://github.com/luni64/VisualTeensy/wiki

  14. #14
    Junior Member
    Join Date
    Sep 2018
    Posts
    19
    I've used CMake extensively for cross-compiling on Linux, but never tried it on Windows, so I might be wrong but here are at least some things I could think of:

    The default CMake generator for Windows is Visual Studio, I doubt that it'll play nicely with a GCC cross-compiler. Try using a different generator like Ninja or GNU Make. See https://cmake.org/cmake/help/latest/...erators.7.html, you can specify it using the -G option, e.g. cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=... .
    Apparently, Visual Studio does support ARM cross compilation, but it doesn't seem to using CMake (and is probably not very well supported and documented).

    AFAIK, setting CMAKE_COMPILER_ID and COMPILER_FORCED shouldn't be necessary when using a toolchain file.

    Do the compiler executables have a .exe extension? Does CMake automatically append this on Windows, or do you have to specify this yourself?

    is it possible to compile the project on Windows using Visual Studio or I have to change IDE or OS?
    I'm sure it's possible in theory, but I doubt it's worth the hassle. Personally I use Visual Studio Code with the C/C++ and CMake extensions on Linux. It just works, and I can understand what's going on behind the scenes (which is not something I can say about Visual Studio).
    Don't get me wrong, Visual Studio is a great IDE for desktop Visual C++ development, but if you need non-standard libraries or if you want to do non-standard things like cross-compiling, it makes things too complicated in my opinion.
    Things have improved with better CMake support and VCPKG, but I still prefer VSCode/CMake/Ninja/Make/GCC on Linux. (I'm sure you can do similar things in VSCode on Windows if you don't want to switch operating systems, but I don't have much experience with that.)

    Pieter

  15. #15
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,458
    Teensy's core library comes with sample makefiles. They're intended for the gnu make, but they use only pretty basic make features. Maybe these can help?

    For Teensy 3.x:
    https://github.com/PaulStoffregen/co...ensy3/Makefile

    For Teensy 4.x:
    https://github.com/PaulStoffregen/co...ensy4/Makefile

  16. #16
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    563
    Yeah, I tend to use WSL for compiling Teensy projects with CMake on Windows. Works like a charm.

  17. #17
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Thank you for the responses, I find them very useful, but I need some time to read everything. I was only using Visual Studio to compile x86 versions on W10 and Qtcreator for x86 and ARM A (Rpi with arm-linux-gnueabihf toolchain) on Linux, but always configuring the projects with Cmake. I run a test on Ubuntu and I could configure and compile core repository, so I guess I should forget W10 for this task and use only Linux.

  18. #18
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Hi again,

    I installed arm toolchain on Ubuntu last weekend using these two commands: sudo apt-get update –y and sudo apt-get install -y gcc-arm-none-eabi. This time, when I try to configure the core project (from Taylor repository) typing make .. -DMCU=MK66FX1M0, the assigned compilers are ARM ones and I could compile the project with command make (see attachments). However, I was expecting an output file of blink example with .hex extension, whereas I found the compiled core library, and the blink example with no extension.

    Other examples compiled with Arudino IDE are possible to open with notepad and read the instructions in hexadecimal, but it is not possible with this file. Is everything correct? How could I load this blink example on my Teensy?

    Thanks

    Click image for larger version. 

Name:	cmake.jpg 
Views:	7 
Size:	45.9 KB 
ID:	20937
    Click image for larger version. 

Name:	compile.jpg 
Views:	13 
Size:	173.3 KB 
ID:	20938

  19. #19
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    563
    The way I set up my toolchain, make blink_hex would make the hex file and make blink_upload flashes the teensy using the command line uploader.

  20. #20
    Member
    Join Date
    Feb 2017
    Location
    A Coruña, Spain
    Posts
    34
    Thanks, now it works!

    I am going to use your example as a template to create a project with my code. It is very likely that my c++ library doesn't fit in T3.6 memory and I have to await T4.1, let me see...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •