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

Thread: Compiling Teensy Sketches with VisualCode (Win10)

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

    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:	136 
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
    7,056
    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
    Junior Member
    Join Date
    Dec 2015
    Posts
    19
    nice work.

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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
    Junior Member
    Join Date
    Dec 2015
    Posts
    19
    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
    306
    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
    Junior Member
    Join Date
    Dec 2015
    Posts
    19
    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
    Apr 2014
    Location
    Germany
    Posts
    306
    That's a very valid point indeed. Looking forward to test it

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

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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.

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

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

    regards
    Cor

  12. #12
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306

    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:	21 
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.

  13. #13
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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:


  14. #14
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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


  15. #15
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,938
    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.

  16. #16
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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.

  17. #17
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,938
    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?

  18. #18
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    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.

  19. #19
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,056
    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?

  20. #20
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306

    Smile

    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?
    Sure, that can be done. Just tried it, works great. It needs a little manual tweaking of course:

    • Generate a project for say a T3.6. Then rename the generated makefile to makefile_36.mk (or any other name you prefer)
    • Go back to VisualTeensy, change the board to a Teensy 3.2 and update the project. Rename the newly generated makefile to makefile_32.mk.


    Click image for larger version. 

Name:	multimake.PNG 
Views:	9 
Size:	31.4 KB 
ID:	14785

    • To avoid the need for deleting all binaries and rebuilding for the new board whenever you switch boards, we let both makefiles generate their own seperated binaries. To achieve this you need to open the makefiles and adjust the BIN variable from BIN := bin to BIN := bin32 and to BIN = bin36 respectively. Now all binaries go into those folders instead of the standard ./bin folder.


    Click image for larger version. 

Name:	bin.PNG 
Views:	10 
Size:	42.6 KB 
ID:	14786

    • Last but not least we need two build commands. One for T3.2 and one for T3.6. So, lets open tasks.json and rename the build command to "Build T3.2" and add a "--file=.\\makefile_32.mk" to the args. After that, copy the complete command, rename it to "Build T3.6" and change the file argument to "--file=.\\makefile_36.mk".


    Click image for larger version. 

Name:	tasks.PNG 
Views:	11 
Size:	43.2 KB 
ID:	14788

    That's it!. You now have a project with 2 build commands one for the T3.2 build the other for the T3.1 build. Both commands build from the same source of course. The corresponding hex files live bin32 and bin36 respectively. This can be improved of course, but for a quick test it should be good enough. BTW: as always, it sounds much more complicated than it really is.

  21. #21
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,056
    Nice! { though would be cool if that naming was the default - the IDE seems to do that under the covers to some degree 'DebugMin.ino.TEENSY35.hex' } I don't have any of this started yet … does Post #1 still show the right links? That project is VS then links on github to VisualCode variant?

    If there is a desire for updates to replace Post#1 and you can post it - I'll migrate it to Post #1 - or update with a link to that new New Post and give it a try myself.

  22. #22
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    That project is VS then links on github to VisualCode variant?
    VisualTeensy is written using VisualStudio (C#). I don't see links to any VisualCode variant in #1?. VisualTeensy uses a stock visual code installation and does not change anything in that installation. Anyway #1 is not up to date anymore but I don't think that this is a problem, the links are still valid. Thanks for asking anyway.

  23. #23
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,056
    missing each other it seems. Yes, Post #1 is out of date and not the starting point to get VisualCode to build for Teensy.

    The proper place to start is? :: VisualCode projects for PJRC Teensy boards >> github::luni64/VisualTeensy

  24. #24
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    306
    Yes, thats true. Adding the link to #1 might be useful indeed.

  25. #25
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    7,056
    Check out addition to post #1 - Added above link and copied the open of the Readme with links.

Posting Permissions

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