Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 10 1 2 3 ... LastLast
Results 1 to 25 of 246

Thread: Compiling Teensy Sketches with VisualCode (Win10)

Hybrid View

  1. #1
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222

    Compiling Teensy Sketches with VisualCode (Win10)

    Inspired by this thread, I did a quick and pragmatic experiment compiling a blink sketch for Teensy 3.2 with Visual Code (Win10).
    First of all: it works perfectly including Intellisense and all the convenience functions from a modern build environment. Build time is about 30s for a complete rebuild and below 1s if you only touch the sketch. Uploading with the teensy uploader as well as with TyCommander is included.


    The place to start :: VisualCode projects for PJRC Teensy boards >> github::luni64/VisualTeensy
    VisualTeensy
    VisualCode is a modern, open source code editor which can easily be used to compile and upload sketches for the PJRC Teensy Boards using VisualTeensy. VisualTeensy is a small Windows utility which fully automates the generation of Teensy projects for VisualCode. Precompiled binaries can be downloaded here.
    Here a screenshot of the environment:
    Click image for larger version. 

Name:	build1.jpg 
Views:	1005 
Size:	78.1 KB 
ID:	14592^

    Getting it going is quite simple and needs to be done only once.
    • Download make.exe and copy it to some convenient place. You can download it from e.g. http://www.equation.com/servlet/equation.cmd?fa=make
    • Download and install VSCode
    • The first time you open a c++ file it ask you to install supporting extensions. Install the extension "c/c++ Intellisense, debugging, and code browsing".
    • I attached the "blink workspace" to this post, extract it to some convenient place and open the file "test.code-workspace" using "File | Open Workspace.
    • Open the file c_cpp_properties.json in .vscode and adjust the path to match your Arduino installation.
    • Open the file tasks.json in .vscode and adjust the path to your make.exe. Note: this has to be done for all the build tasks in the file (didn't find a way how to centralise that setting)
    • Open the makefile and adjust the path to your Arduino installation (ARDUINO_BASE) and the path to TyCommander (UPL_BASE_TYCMD) if you want to use it.
    • The file flags.mk contains the board specific settings, you can change that manually or use Board2Make for auto generating it (https://github.com/luni64/Board2Make)

    That's all.

    You can compile / upload with CTRL + SHIFT + B (or via Tasks|Run Build Tasks) which gives you the following options:

    • Build -> this will build the sketch
    • Clean -> deletes all generated binaries -> the next build will start from scratch
    • Rebuild User Code -> rebuilds everything but the teensy core.
    • Upload with Teensy uploader
    • Upload with TyCommander


    Tested this with Arduino 1.8.5

    Hope somebody can use this as a starter

    test.zip
    Last edited by defragster; 09-23-2018 at 09:54 PM. Reason: Updated github Link to VisualTeensy

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,733
    Glad that worked! Does the Arduino extension add/break anything? :: marketplace.visualstudio.com vscode.vscode-arduino

    With the automated Make editor - would it be possible to add compile/link flags as well? For instance those that emit asm or custom flags for libraries use or testing?

  3. #3
    nice work.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    Quote Originally Posted by defragster View Post
    Glad that worked! Does the Arduino extension add/break anything? :: marketplace.visualstudio.com vscode.vscode-arduino With the automated Make editor - would it be possible to add compile/link flags as well? For instance those that emit asm or custom flags for libraries use or testing?
    The setup can not interfere with anything in VSCode. All the configuration I did is restricted to the used project folder. Regarding custom compile flags: That's a good idea, I'll add that.

    I also installed the Arduino extension you linked to. It does work but as already mentioned in this thread it currently does not work for Teensy. Additionally I didn't get intellisense working correctly with it, seems like they point it to a wrong include folder but maybe I misconfigured it.

    Personal opinion: The extension tries to mimic the Arduino build system which is one of the main reasons why I went to another IDE (VisualStudio) in the first place. So I'm probably not in the target group for that extension. Anyway, I think I'll switch from VisualStudio to VSCode since I really like the lean approach of it. But I won't use the extension and stick with my flexible, makefile based builds as posted above. Anyway, I try to extend Board2Make to autogenerate all the necessary settings for VSCode to make setting up Teensy projects much simpler.
    Last edited by luni; 08-30-2018 at 12:52 PM.

  5. #5
    If you dont mind, Ill steal the approach from Board2Make and make a command line python tool out of it

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    Quote Originally Posted by rjp View Post
    If you dont mind, Ill steal the approach from Board2Make and make a command line python tool out of it
    Sure, good idea. Might be even better to make a vscode extension out of it but I'm quite illiterate regarding javascript :-/

  7. #7
    Quote Originally Posted by luni View Post
    Sure, good idea. Might be even better to make a vscode extension out of it but I'm quite illiterate regarding javascript :-/
    illiterate at javascript is a feature, not a bug.

    im avoiding loading up VSCode with too many extensions - command line tools with instant access via the builtin terminal is the trick, i dont want to slow down the startup speed i love

  8. #8
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,909
    @luni,
    just realized that there is an Arduino for VSCode extension.
    Any reason (apart for not touching VSCode) for not using that path?

  9. #9
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,733
    Quote Originally Posted by WMXZ View Post
    @luni,
    just realized that there is an Arduino for VSCode extension.
    Any reason (apart for not touching VSCode) for not using that path?
    See posts #2 and #4 … doesn't offer help for Teensy

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    Quote Originally Posted by WMXZ View Post
    @luni,
    just realized that there is an Arduino for VSCode extension.
    Any reason (apart for not touching VSCode) for not using that path?
    @WMXZ as defragster already wrote, it currently doesn't support teensy, but I'm sure it will soon.

    Just my personal opinion / use case:
    I like clean build systems which do as little as possible behind the scenes to avoid being dependent on them in the long run. I had a few very bad experiences with old projects needing a fix or some enhancements years after the launch. Of course the original IDE didn't work in my new operating system, or they changed some libraries which are not compatible to my old code anymore etc... Even if you get it compiled in the new system, you probably need to go to all the testing again since you might have broke something...

    I therefore always try building with standard tools. In fact VisualTeensy can easily set up a project that only depends on "gnu make" and the "gcc compiler". You don't need VisualTeensy after generation of the project, you don't even need vsCode. If you want, you can simply say "make" on the command line and it will build the project. This is somehow very reassuring for me :-)

    The good thing with vsCode is that I get all the conveniences of a modern IDE without the price of being dependent on it. So, this is a somehow ideal solution for me.

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    That's a very valid point indeed. Looking forward to test it

  12. #12
    Junior Member
    Join Date
    Jul 2015
    Location
    Bellevue, WA
    Posts
    11
    What would be the best way to add some Arduino Libraries to the Make file?

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    No need to adopt the makefile. It is sufficient to copy the library sources to a subfolder of the project src folder. Something like this:

    Code:
    src
    |__ main.cpp
    |__ anotherProjectFile.cpp
    |__ someLib
         |__ someLib.h
         |__ someLib.cpp
         |__ anotherLibFile.cpp
    You'd use it like this in the sketch (includepath is relative to the src folder)
    Code:
    #include "Arduino.h"
    #include "someLib/someLib.h"
    
    void setup()
    {
    }
    .....
    You can of course tweak the makefile to use the libraries directly but I personally prefer to have all the sources of a project in the project folder.

    I'm currently working on an improved version of the project generator. It now generates the complete project including the makefile, c_cpp_properties.json, tasks.json and a sample "blink" automatically. Drop me a note if you want to test a beta version.

  14. #14
    Senior Member CorBee's Avatar
    Join Date
    Jun 2018
    Location
    Netherlands
    Posts
    346
    Hi,

    I am using Visual Studio in combination with PlatformIO to program my Teensy. Works without problems. Easy to select libraries etc.

    regards
    Cor

  15. #15
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,909
    Now, I also have to learn c#

    Before doing that and customize the code to my 0.1% users relevant requirements, I will ask first

    I note that rtc_localtime symbol is not estimated, how difficult is it to do that in the makefile and to generate a task that forces a relink for every upload ?

    on an eclipse base system I added the following (windows relevant ) instruction

    Code:
    -Xlinker --defsym -Xlinker __rtc_localtime=$$(date +%s)
    I guess, It should be the same, right?

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222

    VisualTeensy

    I finally finished the first beta version of my project generator for VSCode and published it on GitHub: https://github.com/luni64/VisualTeensy. The repo contains a quick usage guide. Here a screenshot of the setup screen:

    Click image for larger version. 

Name:	quickSetupExample.PNG 
Views:	156 
Size:	41.2 KB 
ID:	14717

    Key features:

    • Once you did the initial setup, generating a new Teensy project can be as quick as choosing a project folder, the used Teensy board and a click on "Generate". The generation of the required makefile, task.json and c_cpp_properities.json is done automatically.
    • You can upload firmware using the standard PJRC uploader and/or TyCommander using VSCode.
    • VisualTeensy doesn't need any installation and doesn't change any system configuration. Just copy VisualTeensy.exe (attached) to a convenient place and start it by double clicking.
    • VisualTeensy does not install any extension to VSCode and does not change any VSCode configuration outside of the project folder.
    • If you want you can generate self contained projects: On request VisualTeensy copies the Teensiduino core library to the VSCode project folder and uses this copy for building. You can also use a standard gcc compiler to make the project completely independend of the current Arduino installation.
    • Intellisense, code completion and all the other goodies of a modern IDE work perfectly out of the box.


    Maybe someone has time and inclination to give it a try and do a quick test. Any input, bug reports, additional requirements etc. are very welcome.


    VisualTeensy.zip
    Last edited by luni; 09-12-2018 at 09:11 PM.

  17. #17
    Senior Member
    Join Date
    Nov 2012
    Posts
    142
    Quote Originally Posted by luni View Post
    I finally finished the first beta version of my project generator for VSCode and published it on GitHub: https://github.com/luni64/VisualTeensy. The repo contains a quick usage guide.
    Nice extension!

    Are you considering targeting macOS as well?

  18. #18
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    I did some opimization of the code and added default values for most of the settings. If you have a standard Arduino / Teensyduino installation and if vsCode is installed, generating a new project, compiling and uploading to a Teensy now is a matter of a few clicks only.

    Here a short quickstart video showing the usage:


  19. #19
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,909
    Quote Originally Posted by luni View Post
    I did some opimization of the code and added default values for most of the settings. If you have a standard Arduino / Teensyduino installation and if vsCode is installed, generating a new project, compiling and uploading to a Teensy now is a matter of a few clicks only.
    And what about existing projects? how should one handle Arduino libraries that are usually searched for by Arduino and also VisualMicro?
    Last edited by WMXZ; 09-23-2018 at 06:41 PM.

  20. #20
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    I did some experiments with the parallel option for GNU make (-j -Otarget). The results are just amazing. On my garden-variety PC (Intel i5, 2.9Ghz, 6GB Ram) a complete rebuild of Teensyduino including a simple blink example usually took about 30s . Activating parallel make accelerates the process to a about 5s for a build from scratch including the upload to the board with TyCommander. A normal rebuild of the user files only (including upload) is done in less than one second.

    Current VisualTeensy version including GNU make for Windows can be downloaded here: https://github.com/luni64/VisualTeen...ses/tag/v0.4.1


  21. #21
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    VisualTeensy only genreates/updates a project skeleton containing the required files for vsCode and generates a makefile containing the specific teensy settings (board type, optimizer settings....) . If you want to complile an exisiting project you basically copy your files into the generated src folder and rename *.ino to*.cpp (don't forget to delete the autogenerated make.cpp first). Alternatively you can point VisualTeensy to an existing folder and it will generate the vsCode files in that folder. (again, don't forget to rename *.ino to *.cpp...)

    If you want to use libraries other then those included in the Teensyduino core you can simply copy them to the scr folder and they will be compiled without any change in the makefile (see here). I can generate an example containing some libraries if that helps understanding the workflow.

    I'm currently working on a library manager for VisualTeensy to make using libraries easier for those used to do it the Arduino way.

  22. #22
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,909
    Quote Originally Posted by luni View Post
    I'm currently working on a library manager for VisualTeensy to make using libraries easier for those used to do it the Arduino way.
    great, looking forward to it.
    BTW, is there a makefile template that one could customize? say only list of libraries, or special files to be used always?

  23. #23
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,909
    OK,
    I have some difficulties installing the system (better compiling)
    Windows 10
    sketch
    Code:
    #include "Arduino.h"
    
    //#include "core_pins.h" // this call also kinetis.h
    #include "Audio.h"
    
        AudioInputAnalog  acq(0);
        AudioRecordQueue  queue;
    
        AudioConnection     patchCord(acq, queue); 
    
    void setup()
    {
      AudioMemory (10);
    
      pinMode(LED_BUILTIN,OUTPUT);
    }
    
    void loop()
    {
    
      digitalWriteFast(LED_BUILTIN,!digitalReadFast(LED_BUILTIN));
      delay(100);
    }
    c_pp_properties.json
    Code:
    {
      "configurations": [
        {
          "name": "VisualTeensy",
          "includePath": [
            "${workspaceFolder}/src/**",
            "C:/Users/Walter/Documents/arduino-1.8.7/hardware/teensy/avr/cores/teensy3/**",
            "C:/Users/Walter/Documents/arduino-1.8.7/hardware/teensy/avr/library/audio/**"
          ],
          "defines": [
            "__MK66FX1M0__",
            "TEENSYDUINO=144",
            "F_CPU=180000000",
            "USB_SERIAL",
            "LAYOUT_US_ENGLISH"
          ],
          "compilerPath": "C:/Users/Walter/Documents/arduino-1.8.7/hardware/tools/arm/arm-none-eabi/bin/bin/arm-none-eabi-gcc.exe",
          "intelliSenseMode": "gcc-x64"
        }
      ],
      "version": 4
    }
    error
    Code:
    > Executing task: C:/Users/Walter/Desktop/Luni/make.exe all <
    
    [CC] CORE usb_serial.c
    /usr/bin/sh: -c: line 1: syntax error: unexpected end of file
    make: *** [makefile:120: bin\core/usb_serial.o] Error 258
    The terminal process terminated with exit code: 1

    the incriminating line is

    Code:
    @if not exist $(dir $@)  @mkdir "$(dir $@)"

    interesting, if I add as makefile target
    Code:
    test:
    	ls
    	dir
    I get
    Code:
    PS C:\Users\Walter\Documents\Arduino\Test_Code> make test
    ls
    bin  makefile  src
    dir
    process_begin: CreateProcess(NULL, dir, ...) failed.
    make (e=2): The system cannot find the file specified.
    make: *** [makefile:104: test] Error 2
    PS C:\Users\Walter\Documents\Arduino\Test_Code>
    that is only the Linux command ls is known to make but not the windows dir (both give on PS the same result)

  24. #24
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,222
    BTW, is there a makefile template that one could customize? say only list of libraries, or special files to be used always?
    Good idea. Currently I generate the makefile from a built in template. I could make that configurable, i.e. you could provide your own makefile instead of the build in one.

  25. #25
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,733
    This has evolved really well! Especially using TyCommander - by the way that was just updated to v0.8.10 yesterday. NICE fast parallel build times!

    I often run the same sketch on multiple of the Teensy's LC,3.1, 3.5, 3.6 from the same INO sketch. Would there be a way to have each build in it's 'own place'? With the IDE this takes multiple instances to have them active at the same time - it seems this would take duplicate 'project solution' areas with a unique make file?

Posting Permissions

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