Command line compiling for Teensy 4,1

FLL-Freak

Member
I am confused. I very quickly found the limitation with Arduino in how they build projects. They copy your source to a temp folder to do the compiling. This prevents me from having a directory structure with my code spread out. A solution might be to consolidate the code to one folder, but that would be a serious nuisance for me. My project consists of Linux, and embedded (Teensy 4.x) code that share various files.

I am trying to shed the Arduino IDE and just compile using my favorite Linux/vi/make development environment. (yes, I am an old fart).

My problem is that the various description on how to do this were written for Teensy 1 to 2.
I followed the instructions to install avr and download the blinky sample.
After fixing some errors in the code, I got it to compile but it would not load using the Teensy-Loader as the code was compiled for 2.0 and I have a 4.1.
I looked at the Makefile and found the MCU entry but my options are for 1 to 2. Googling I found that I might try TEENSY41, imxrt1062, or IMXRT1062.
All of these provided compile time failures as it is looking for "device-specs" that do not exist.

Amy hints would be welcome.
 
Lots of residual Teensy 2 pages - not clear the source of confusion there? Which 'various'?
> maybe this pjrc.com/teensy/gcc.html
That links to :: pjrc.com/teensy/td_download.html

This page seems to ref cmdline though T_4.1 ... though nothing yet for Teensy MicroMod that was announced days ago ")

pjrc.com/teensy/loader_cli.html

Installed with TeensyInstaller is :: {local install}\hardware\teensy\avr\cores\teensy4\Makefile

Code:
...

# Use these lines for Teensy 4.0
MCU = IMXRT1062
MCU_LD = imxrt1062.ld
MCU_DEF = ARDUINO_TEENSY40

# Use these lines for Teensy 4.1
#MCU = IMXRT1062
#MCU_LD = imxrt1062_t41.ld
#MCU_DEF = ARDUINO_TEENSY41


...
 
So I am here to answer my own question. The links that defragster posted did not reduce my confusion.
So my solution was to create a dirt simple sketch and using the verbose mode, compile it in the Arduino IDE.
I then took the output from the log area and used that as the start of a Makefile.
An hour of editing later, I was able to compile the test application and have it run on the board.
There was likely a simpler way (a makefile template for teensy 4.x?) , but it was not obvious to me.
The main editing that had to be done was to remove all the pre and post processing that Arduino does to move your files to a temp folder to compile.
I just compiled everything in place. I still have to clean up my Makefile and to add the dependency files back in but I seem out of the woods.
 
It can be a lot of work to do what the IDE does ... as it does it ... a different way.

Not bothered with makefiles - there are IDE's that work and VisualTeensy by @luni that gets the build for VSCode following the IDE in some fashion. But none of them are CmdLine, or using a hand edited makefile. PJRC install does include the indicated makefile that must work ...

Personally like you - watching the verbose console output you can see how to trigger it. @Frank B made the first step at that (3 years ago) and then this was built on that : github.com/Defragster/Tset to allow editor of choice that can execute CmdLine commands to trigger the IDE to do what it does, without having to open the IDE. There are options and all the pieces are there for options.

As for the case in post #1 the answer to the IDE doing it might have been to build 'libraries' out of sections of the shared code for inclusion from their separate directories.
 
Hi FLL-Freak,
I'm an old fart too, can't stand the Arduino IDE and would dearly like to circumvent it. Did the work you did on creating your own makefile come to fruition? If so I'd be really interested to see what that looks like.
Thanks, Ian.
 
Arduino have available a command line interface here: https://arduino.github.io/arduino-cli/
Direct link here: https://downloads.arduino.cc/arduino-cli/arduino-cli_latest_Windows_64bit.zip

Example:
Compile for a Teensy 4.1 use this command : arduino-cli.exe compile -b teensy:avr:teensy41 antplus\antplus.ino
Verify : arduino-cli.exe compile -t -b teensy:avr:teensy41 antplus\antplus.ino
Upload : arduino-cli.exe compile -u -b teensy:avr:teensy41 antplus\antplus.ino

Previously with Arduino 1.8, one could something such as: arduino.exe --pref build.path=M:\temp\teensy --board teensy:avr:teensy36:speed=180 --preserve-temp-files --port COM31 --upload K:\code\Teensy\antplus\antplus.ino
 
Hi Michael,

Thank you.

I feel as if I should have found that myself but, being new to all things Arduino/Teensy, I'm really not sure what I'm doing yet. At first look, the documentation looks good, which is a relief.

I'm on Linux, by the way, so needed to make a few changes to your suggestions. As a first attempt, I'm finding that:

~/local/bin/arduino-cli compile -u -b teensy:avr:teensyLC -p /dev/ttyACM0 <source file>.ino

both compiles and uploads a 'sketch' (awful terminology) to my teensy board.

A couple of things remain: the first is that as far as I can see the command is using the teensy avr files that were installed while setting up the Arduino IDE (for teensy boards). I hope I can find a cleaner way of getting those files onto my machine. The whole IDE installation business - the general 'scatter gun' approach of creating directory structures where the installer thinks best without bothering to consult or even inform the user - is not to my taste. I like to decide myself where to put things. The other thing, which is just an annoyance really, is that using this command still opens the little 'teensy loader' window. I'll look for a way to suppress that because it feels a bit like being back in infant school.

But this is already a great improvement, so thank you again for pointing it out to me.

Best, Ian.
 
The whole IDE installation business - the general 'scatter gun' approach of creating directory structures where the installer thinks best without bothering to consult or even inform the user - is not to my taste.
You can explicitly state the address of libraries as in #include "C:\Arduino Programs\HomeHeatingManagement\HHMVars.h" which I use in one of my programs.
 
Back
Top