Compiling Teensy Sketches with VisualCode (Win10)

Got the two EXE's: luni64/VisualTeensy/releases
Installed Ver 1.27 of visual studio code
Installed c/C++ extensions: ms-vscode.cpptools

Doing Expert setup - as my install is ZIP variety on Windows:
> I have my boards.txt: T:\arduino-1.8.7_144_TYC\hardware\teensy\avr
> Not sure what the :: 'Path to TeensyCore Library' is asking for? :: T:\arduino-1.8.7_144_TYC\hardware\teensy\avr\cores\teensy3
> And Compiler folder? :: T:\arduino-1.8.7_144_TYC\hardware\tools\arm

All it should need is the root of my IDE/TeensyDuino UnZip folder?

I got a build - but no upload with TyCommander? Does it use the GUI? How does it link to it? I get this error text:
> Executing task: T:/Programs/VisualTeensy/make.exe upload -j -Otarget <

process_begin: CreateProcess(NULL, \teensy_post_compile -test -file=BlinkMin -path=bin -tools= -board=TEENSY36 -reboot, ...) failed.
make (e=2): The system cannot find the file specified.
make: *** [makefile:104: upload] Error 2
The terminal process terminated with exit code: 1
 
Interesting, can you try the Quick setup first? All you should need to enter is "T:\arduino-1.8.7_144_TYC" in the Arduino folder field. The rest should be derived automatically. If you want to use TyCommander you need to enter the path to the TyTools folder in the setup Tab.
Can you give that a try and post the first lines of the makefile or a screenshot of VisualTeensy?


> I have my boards.txt: T:\arduino-1.8.7_144_TYC\hardware\teensy\avr
> Not sure what the :: 'Path to TeensyCore Library' is asking for? :: T:\arduino-1.8.7_144_TYC\hardware\teensy\avr\cores\teensy3
> And Compiler folder? :: T:\arduino-1.8.7_144_TYC\hardware\tools\arm
That looks all good. You probably didn't set the path to the teensy uploader in the setup tab correctly. That should be "T:\arduino-1.8.7_144_TYC\hardware\tools". Need to make a better desrciption...
 
Last edited:
The autoconf feature at the first startup does only look in C: for installed Arduino and TyCommander. Silly me. I'll extend that to all found volumes.
 
All Okay doing quick with "T:\arduino-1.8.7_144_TYC" worked to find the IDE install.

I missed understanding that apparently and then found the unvisited Setup Tab - it now knows where TyTools are located and works perfectly!

This looks good - except the 1,500+ INO files in my sketchbook directory are IDE INO Hacks not cpp.

And understanding how the sketchbook\libraries folder will get referenced for those needed files? Explicit path to #include "T:\tCode\libraries\debug_t3\debug_t3.h" ends in may "undefined reference to …" I'll need to resolve.

And then a new editor to learn - and this environment and the Multi_Teensy built noted above.
 
Glad that it works. Once you get used to intellisense, code completion and all the other stuff (have the cursor on e.g. digitalWriteFast(...) and press F12...) you'll not want to go back :).

Translating .ino to .cpp:
- make sure that the functions are defined before you use them. Arduino is doing that for you in the background. Usually it is enough to have loop() and setup() at the end of the sketch.
- Libraries can be tricky, for now the best is to copy the used lib to a subfolder of the src folder. I'll have a library manager soon. I can post an example showing how that works. Any "difficult" library you'd want to see?
 
Indeed back to 'c' rules with functions manually prototyped versus the INO way, took care of that.

I just got and paid for an awesome new editor SublimeText I'm getting used to - switching to a new one with alternate autocomplete and such will be a learning curve. I'll still use that { as I do now with IDE } as it supports global search across the WHOLE of Teensy installed libs!

I just put my debug_t3 library into "T:\Programs\VisualTeensy\Source\DebugMin\src" and then it builds with: #include "debug_t3\debug_t3.h"


I made a special Dir for T:\Programs\VisualTeensy on my SSD - where I do all my Teensy stuff. That DIR holds the make and VisualTeensy.exe's.

I put the Source folder there. If the libraries Folder were linked from there {in or above?} it would mirror the IDE's sketchbook directory layout. As it is even an explicit path is rooted to : 'src/debug_t3\debug_t3.h' and fails.

Having an independent copy of each library used in each source folder makes library updates tedious, how it is done for pulling Teensy Core libs is nice where they pull from a fixed update location.

I'll have to do more with it to figure out the makefile creation and process with VisualTeensy.exe.

But it works well and quickly from what I've tested so far. Two small sketches are consuming 8.6 MB in the Source folder compiled for just one T_3.6
 
@luni,
just realized that there is an Arduino for VSCode extension.
Any reason (apart for not touching VSCode) for not using that path?
 
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.

  • 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.

  • 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".

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.

Trying these steps - I renamed to mk_36, then edit mk to have unique bin, then edited the json entry - went to make a version for T_LC … and it wiped my json edits :(

Would it be possible to have the VisualTeensy.exe make these edits upfront for all or selected Teensy versions? Then VisualTeensy could be re-run without overwrite.

Let me know if you see a way to do a shared source for Libraries - I'll test it out.
 
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?
 
@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.
 
Trying these steps - I renamed to mk_36, then edit mk to have unique bin, then edited the json entry - went to make a version for T_LC … and it wiped my json edits :(
Would it be possible to have the VisualTeensy.exe make these edits upfront for all or selected Teensy versions? Then VisualTeensy could be re-run without overwrite.

Hm, that would be a solution for a very special use case and would be somehow confusing for normal users? I'll think of something to solve this but I want to do that library manager first.

Let me know if you see a way to do a shared source for Libraries - I'll test it out.
Yes, first version of the makefile is working already (no GUI yet) if you would like to test it (which I would appreciate very much), I can send you a beta later today.
 
@defragster:

here a quick improvement of the procedure to do mulitple target builds described in #20. Add a new makefile with the following contents, name it "makefile" and copy it to the root folder

Code:
all:
	@$(MAKE) -j -Otarget --no-print-directory -f ./makefile_32.mk
	@$(MAKE) -j -Otarget --no-print-directory -f ./makefile_36.mk

clean:
	@if exist bin32 rd /s/q bin32
	@if exist bin36 rd /s/q bin36


With this makefile you don't need to touch tasks.json at all. Just do a normal build and it will generate the firmware for all your target boards automatically. (Doesn't solve the overwrite problem of course)
 
Here: https://github.com/luni64/VisualTeensy/issues/1 you can download a first prototype of the library management functionality. Currently you have to manually enter a list of the used libraries in the autogenerated makefile. This will be done in the next step by the GUI of course. Any tests and bug reports very welcome.

libman.png
 
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)
 
Looks like make tries to use /usr/bin/sh as shell not the usual windows shell. Maybe you have some environment variables set which are evaluated by make so that it starts a linux shell? I'll have a closer look into that.
 
Can you check the value of the ComSpec and SHELL (if set) environment variables? (Just type SET in a command window)

EDIT:
can you add the lines

Code:
SHELL := cmd.exe
export SHELL

at the top of the makefile and see if it works then?

shell.PNG
 
Last edited:
Can you check the value of the ComSpec and SHELL (if set) environment variables? (Just type SET in a command window)

EDIT:
can you add the lines

Code:
SHELL := cmd.exe
export SHELL

at the top of the makefile and see if it works then?

Now it works.

Maybe previous problem is because I have ubuntu for windows (AKA windows subsystem for Linux (WSL)) installed?
 
Yes, that makes sense. I added the shell defnition to the autogenerated makefile already. Thanks for finding this one...


Above you wrote:
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?

I'll have a look at this. I assume it is for the built in RTC? Do you have any documentation or forum link on the feature?
 
Before searching info on rtc_localtime here another issue
compiling the audio library there is an include file missing issue
Code:
C:\Users\Walter\Documents\arduino-1.8.7\hardware\teensy\avr\libraries/Audio/analyze_fft1024.cpp:29:26: fatal error: sqrt_integer.h: No such file or directory
compilation terminated.
make: *** [makefile:163: bin/lib/Audio/analyze_fft1024.o] Error 1
The terminal process terminated with exit code: 1

Now, sqrt_integer.h file is in Audio/utility among other include files

strange enough, the cpp file has at lines 29/30
Code:
#include "sqrt_integer.h"
#include "utility/dspinst.h"

As this never was coming up as an error in all my previous compilations, maybe Arduino can handle this,
and it should be an issue for Paul, but I bring it up anyhow
 
VisualMicro Add-on recently had posts about adding in the localtime created at each compile- not sure if the details can be found from that perhaps
 
Last edited:
Back
Top