How do I use the example Teensy 4.0 Makefile with latest Arduino 1.8.9?

Status
Not open for further replies.

ardnew

Member
I have the latest official Arduino version 1.8.9 and Teensyduino 1.47 installed, and I'm able to successfully compile and flash my new Teensy 4.0 directly from Arduino.

I'm having trouble trying to compile the example Blink source, using the provided teensy4 Makefile template (i.e., https://github.com/PaulStoffregen/cores/blob/master/teensy4/Makefile).

Using the Arduino IDE compilation output as reference, I've tried updating the Makefile as follows:

Code:
CPUARCH = cortex-m7
DEFS = -D__IMXRT1062__ -DTEENSYDUINO=147 -DARDUINO=10809 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH
SECTIONS = -ffunction-sections -fdata-sections
DBGFLAGS = -g
CPPFLAGS = $(DBGFLAGS) -Wall -O2 $(SECTIONS) -mcpu=$(CPUARCH) -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -I. $(DEFS)
CXXFLAGS = -std=gnu++14 -felide-constructors -fno-exceptions -fpermissive -fno-threadsafe-statics -fno-rtti -Wno-error=narrowing
LDFLAGS = -Wl,--gc-sections,--relax,--print-memory-usage -Timxrt1062.ld -larm_cortexM7lfsp_math -lm -lstdc++ -nostdlib --specs=nano.specs

C_FILES := $(wildcard *.c)
CPP_FILES := $(wildcard *.cpp)

OBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o)

ARDUINOPATH = /home/andrew/.bin/arduino-1.8.9
COMPILERPATH = $(abspath $(ARDUINOPATH)/hardware/tools/arm/bin)
CC = $(COMPILERPATH)/arm-none-eabi-gcc
CXX = $(COMPILERPATH)/arm-none-eabi-g++
OBJCOPY = $(COMPILERPATH)/arm-none-eabi-objcopy
OBJDUMP = $(COMPILERPATH)/arm-none-eabi-objdump
SIZE = $(COMPILERPATH)/arm-none-eabi-size
AR = $(COMPILERPATH)/arm-none-eabi-gcc-ar

all: Blink.elf

Blink.elf: Blink.o core.a
        $(CC) $(CPPFLAGS) $(LDFLAGS) -o $@ $^
        $(OBJDUMP) -d -S -C $@ > Blink.lst
        $(OBJDUMP) -t -C $@ > Blink.sym
        $(OBJCOPY) -O ihex -R .eeprom $@ Blink.hex
        $(SIZE) $@

core.a: $(OBJS)
        $(AR) rcs core.a $(OBJS)

clean:
        rm -f *.o *.d core.a *.elf *.lst *.sym *.hex

The code compiles fine, prints the memory usage table, and then bails when linking the startup stuff:

Code:
...
/home/andrew/.bin/arduino-1.8.9/hardware/tools/arm/bin/arm-none-eabi-gcc-ar rcs core.a usb_serial.o usb_desc.o rtc.o keylayouts.o nonstd.o digital.o pwm.o interrupt.o bootdata.o tempmon.o analog.o delay.o eeprom.o usb.o clockspeed.o startup.o debugprintf.o HardwareSerial6.o Tone.o WString.o DMAChannel.o EventResponder.o HardwareSerial1.o WMath.o HardwareSerial8.o Print.o usb_inst.o IntervalTimer.o HardwareSerial7.o Stream.o IPAddress.o HardwareSerial2.o HardwareSerial4.o new.o AudioStream.o HardwareSerial3.o yield.o HardwareSerial5.o HardwareSerial.o
/home/andrew/.bin/arduino-1.8.9/hardware/tools/arm/bin/arm-none-eabi-gcc -g -Wall -O2 -ffunction-sections -fdata-sections -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -I. -D__IMXRT1062__ -DTEENSYDUINO=147 -DARDUINO=10809 -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -Wl,--gc-sections,--relax,--print-memory-usage -Timxrt1062.ld -larm_cortexM7lfsp_math -lm -lstdc++ -nostdlib --specs=nano.specs -o Blink.elf Blink.o core.a
Memory region         Used Size  Region Size  %age Used
            ITCM:        5200 B       512 KB      0.99%
            DTCM:       12960 B       512 KB      2.47%
             RAM:          0 GB       512 KB      0.00%
           FLASH:       11744 B      1984 KB      0.58%
core.a(startup.o): In function `ResetHandler':
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/startup.c:116: undefined reference to `__libc_init_array'
core.a(usb.o): In function `usb_init':
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/usb.c:171: undefined reference to `memset'
core.a(usb.o): In function `usb_endpoint_config':
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/usb.c:548: undefined reference to `memset'
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/usb.c:548: undefined reference to `memset'
core.a(usb_serial.o): In function `usb_serial_configure':
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/usb_serial.c:92: undefined reference to `memset'
/home/andrew/.bin/arduino-1.8.9/hardware/teensy/avr/cores/teensy4/usb_serial.c:95: undefined reference to `memset'
collect2: error: ld returned 1 exit status
Makefile:27: recipe for target 'Blink.elf' failed
make: *** [Blink.elf] Error 1

What else do I need to change?
 
I am having the same problem, using Arduino-IDE is too restrictive for me, but the makefile does not seem to work.

Any update on the issue?
 
I am having the same problem, using Arduino-IDE is too restrictive for me, but the makefile does not seem to work.

Any update on the issue?

When I wanted to understand how Arduino compiles I simply make the IDE verbose, check the output and note the different compile and link options.
Only after that I modify the make file.

If you wanted someone else to do the work for you, you are lucky, search the forum for VisualTeensy.
 
In case you are running under Windows you can have a look at VisualTeensy . It generates makefiles and all the required *.json files to use vsCode as an IDE. If you don't want to use vsCode you should still be able to use the generated makefile as a stating point. If you are under Linux you will need to change the OS specific things (shell, copy, remove etc).

Alternatively @Defragster maintains a build-script which simply calls the Arduino builder. It should be possible to call that script from any decent editor. You'll find info here in the forum.

Here a quick youtube video (click on the youtube logo to get a full screen view)


Edit: Ups, cross post with WMXZ.....
 
Last edited:
When I wanted to understand how Arduino compiles I simply make the IDE verbose, check the output and note the different compile and link options.
Only after that I modify the make file.

If you wanted someone else to do the work for you, you are lucky, search the forum for VisualTeensy.

Ouch. As I stated, I'm using the Arduino IDE verbose compilation output as reference for changes made to the provided teensy4 example Makefile. I can post a diff between the provided Makefile and my already-posted changes to it if that will help.

The problem is that `make` will dynamically construct the compilation commands using the implicit target rule patterns defined, so there's some magic under the hood that I'm not sure how to cast in order to generate compiler/linker invocations identical to the Arduino IDE.

Also I do not own a Windows PC for VisualTeensy.
 
In case you are running under Windows you can have a look at VisualTeensy . It generates makefiles and all the required *.json files to use vsCode as an IDE. If you don't want to use vsCode you should still be able to use the generated makefile as a stating point. If you are under Linux you will need to change the OS specific things (shell, copy, remove etc).

I also do not have access to a Windows PC. I would love if someone could provide one of these generated Makefiles from VisualTeensy. I'd try that as a starting point.

Alternatively @Defragster maintains a build-script which simply calls the Arduino builder. It should be possible to call that script from any decent editor. You'll find info here in the forum.

Thanks! This seems like the better option instead of an independent Makefile. That way I'd be able to automatically use any updates made to the Arduino toolchain and available libs/boards. Will give this a try.
 
Last edited:
Here a link to defragsters script https://github.com/Defragster/Tset

I would love if someone could provide one of these generated Makefiles from VisualTeensy.

Here you are:

Code:
#******************************************************************************
# Generated by VisualTeensy (https://github.com/luni64/VisualTeensy)
#
# Board              Teensy 4.0
# USB Type           Serial
# CPU Speed          
# Optimize           Faster
# Keyboard Layout    US English
#
# 22.08.2019 18:07
#******************************************************************************
SHELL            := cmd.exe
export SHELL

TARGET_NAME      := newProject(2)
BOARD_ID         := TEENSY40

MCU              := imxrt1062

LIBS_SHARED_BASE := C:\Users\lutz\Documents\Arduino\libraries
LIBS_SHARED      := Encoder 

LIBS_LOCAL_BASE  := lib
LIBS_LOCAL       := 

CORE_BASE        := C:\Arduino\arduino-1.8.5\hardware\teensy\avr\cores\teensy4
GCC_BASE         := C:\Arduino\arduino-1.8.5\hardware\tools\arm\bin
UPL_PJRC_B       := C:\Arduino\arduino-1.8.5\hardware\tools
UPL_TYCMD_B      := C:\toolchain\TyTools

#******************************************************************************
# Flags and Defines
#******************************************************************************
FLAGS_CPU   := -mthumb -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16
FLAGS_OPT   := -O2
FLAGS_COM   := -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD
FLAGS_LSP   := 

FLAGS_CPP   := -std=gnu++14 -fno-exceptions -fpermissive -fno-rtti -fno-threadsafe-statics -felide-constructors -Wno-error=narrowing
FLAGS_C     := 
FLAGS_S     := -x assembler-with-cpp
FLAGS_LD    := -Wl,--gc-sections,--relax,--defsym=__rtc_localtime=$(shell powershell [int](Get-Date -UFormat +%s)[0]) -T$(CORE_BASE)/imxrt1062.ld

LIBS        := -larm_cortexM7lfsp_math -lm -lstdc++

DEFINES     := -D__IMXRT1062__ -DTEENSYDUINO=147 -DARDUINO=10807
DEFINES     += -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH

CPP_FLAGS   := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_CPP)
C_FLAGS     := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_C)
S_FLAGS     := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_COM) $(DEFINES) $(FLAGS_S)
LD_FLAGS    := $(FLAGS_CPU) $(FLAGS_OPT) $(FLAGS_LSP) $(FLAGS_LD)
AR_FLAGS    := rcs

#******************************************************************************
# Colors
#******************************************************************************
COL_CORE    := 
COL_LIB     := 
COL_SRC     := 
COL_LINK    := 
COL_ERR     := 
COL_OK      := 
COL_RESET   := 

#******************************************************************************
# Folders and Files
#******************************************************************************
USR_SRC     := src
LIB_SRC     := lib
CORE_SRC    := $(CORE_BASE)

BIN         := .vsteensy/build
USR_BIN     := $(BIN)/src
CORE_BIN    := $(BIN)/core
LIB_BIN     := $(BIN)/lib
CORE_LIB    := $(BIN)/core.a
TARGET_HEX  := $(BIN)/$(TARGET_NAME).hex
TARGET_ELF  := $(BIN)/$(TARGET_NAME).elf
TARGET_LST  := $(BIN)/$(TARGET_NAME).lst

#******************************************************************************
# BINARIES
#******************************************************************************
CC          := $(GCC_BASE)/arm-none-eabi-gcc
CXX         := $(GCC_BASE)/arm-none-eabi-g++
AR          := $(GCC_BASE)/arm-none-eabi-gcc-ar
OBJCOPY     := $(GCC_BASE)/arm-none-eabi-objcopy
SIZE        := $(GCC_BASE)/arm-none-eabi-size
OBJDUMP     := $(GCC_BASE)/arm-none-eabi-objdump
UPL_PJRC    := "$(UPL_PJRC_B)/teensy_post_compile" -test -file=$(TARGET_NAME) -path=$(BIN) -tools="$(UPL_PJRC_B)" -board=$(BOARD_ID) -reboot
UPL_TYCMD   := $(UPL_TYCMD_B)/tyCommanderC upload $(TARGET_HEX) --autostart --wait --multi
UPL_CLICMD  := $(UPL_CLICMD_B)/teensy_loader_cli -mmcu=$(MCU) -v $(TARGET_HEX)
UPL_JLINK   := $(UPL_JLINK_B)/jlink -commanderscript .vsteensy/flash.jlink

#******************************************************************************
# Source and Include Files
#******************************************************************************
# Recursively create list of source and object files in USR_SRC and CORE_SRC
# and corresponding subdirectories.
# The function rwildcard is taken from http://stackoverflow.com/a/12959694)

rwildcard =$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

#User Sources -----------------------------------------------------------------
USR_C_FILES    := $(call rwildcard,$(USR_SRC)/,*.c)
USR_CPP_FILES  := $(call rwildcard,$(USR_SRC)/,*.cpp)
USR_S_FILES    := $(call rwildcard,$(USR_SRC)/,*.S)
USR_OBJ        := $(USR_S_FILES:$(USR_SRC)/%.S=$(USR_BIN)/%.o) $(USR_C_FILES:$(USR_SRC)/%.c=$(USR_BIN)/%.o) $(USR_CPP_FILES:$(USR_SRC)/%.cpp=$(USR_BIN)/%.o)

# Core library sources --------------------------------------------------------
CORE_CPP_FILES := $(call rwildcard,$(CORE_SRC)/,*.cpp)
CORE_C_FILES   := $(call rwildcard,$(CORE_SRC)/,*.c)
CORE_S_FILES   := $(call rwildcard,$(CORE_SRC)/,*.S)
CORE_OBJ       := $(CORE_S_FILES:$(CORE_SRC)/%.S=$(CORE_BIN)/%.o) $(CORE_C_FILES:$(CORE_SRC)/%.c=$(CORE_BIN)/%.o) $(CORE_CPP_FILES:$(CORE_SRC)/%.cpp=$(CORE_BIN)/%.o)


# User library sources  (see) https://github.com/arduino/arduino/wiki/arduino-ide-1.5:-library-specification
LIB_DIRS_SHARED  := $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/ $(LIBS_SHARED_BASE)/$d/utility/)  # base and /utility
LIB_DIRS_SHARED  += $(foreach d, $(LIBS_SHARED), $(LIBS_SHARED_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_SHARED_BASE)/$d/src/,*/.)))                           # src and all subdirs of base

LIB_DIRS_LOCAL   := $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/ $(LIBS_LOCAL_BASE)/$d/utility/ )    # base and /utility
LIB_DIRS_LOCAL   += $(foreach d, $(LIBS_LOCAL), $(LIBS_LOCAL_BASE)/$d/src/ $(dir $(call rwildcard,$(LIBS_LOCAL_BASE)/$d/src/,*/.)))                             # src and all subdirs of base

LIB_CPP_SHARED  := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.cpp))
LIB_C_SHARED    := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.c))
LIB_S_SHARED    := $(foreach d, $(LIB_DIRS_SHARED),$(call wildcard,$d*.S))

LIB_CPP_LOCAL   := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.cpp))
LIB_C_LOCAL     := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.c))
LIB_S_LOCAL     := $(foreach d, $(LIB_DIRS_LOCAL),$(call wildcard,$d/*.S))

LIB_OBJ         := $(LIB_CPP_SHARED:$(LIBS_SHARED_BASE)/%.cpp=$(LIB_BIN)/%.o)  $(LIB_CPP_LOCAL:$(LIBS_LOCAL_BASE)/%.cpp=$(LIB_BIN)/%.o)
LIB_OBJ         += $(LIB_C_SHARED:$(LIBS_SHARED_BASE)/%.c=$(LIB_BIN)/%.o)  $(LIB_C_LOCAL:$(LIBS_LOCAL_BASE)/%.c=$(LIB_BIN)/%.o)
LIB_OBJ         += $(LIB_S_SHARED:$(LIBS_SHARED_BASE)/%.S=$(LIB_BIN)/%.o)  $(LIB_S_LOCAL:$(LIBS_LOCAL_BASE)/%.S=$(LIB_BIN)/%.o)

# Includes -------------------------------------------------------------
INCLUDE        := -I./$(USR_SRC) -I$(CORE_SRC)
INCLUDE        += $(foreach d, $(LIB_DIRS_SHARED), -I$d)
INCLUDE        += $(foreach d, $(LIB_DIRS_LOCAL), -I$d)

# Generate directories --------------------------------------------------------
DIRECTORIES :=  $(sort $(dir $(CORE_OBJ) $(USR_OBJ) $(LIB_OBJ)))
generateDirs := $(foreach d, $(DIRECTORIES), $(shell if not exist "$d" mkdir "$d"))

#$(info dirs: $(DIRECTORIES))

$(info$(COL_RESET))

#******************************************************************************
# Rules:
#******************************************************************************

.PHONY: directories all rebuild upload uploadTy uploadCLI clean cleanUser cleanCore


all:  $(TARGET_LST) $(TARGET_HEX)

rebuild: cleanUser all

clean:   cleanUser cleanCore cleanLib
	@echo $(COL_OK)cleaning done$(COL_RESET)

upload: all
	@$(UPL_PJRC)

uploadTy: all
	@$(UPL_TYCMD)

uploadCLI: all
	@$(UPL_CLICMD)

uploadJLink: all
	@$(UPL_JLINK)


# Core library ----------------------------------------------------------------
$(CORE_BIN)/%.o: $(CORE_SRC)/%.S
	@echo $(COL_CORE)CORE [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_BIN)/%.o: $(CORE_SRC)/%.c
	@echo $(COL_CORE)CORE [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_BIN)/%.o: $(CORE_SRC)/%.cpp
	@echo $(COL_CORE)CORE [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(CORE_LIB) : $(CORE_OBJ)
	@echo $(COL_LINK)CORE [AR]  $@ $(COL_ERR)
	@$(AR) $(AR_FLAGS) $@ $^
	@echo $(COL_OK)Teensy core built successfully &&echo. 

# Shared Libraries ------------------------------------------------------------
$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.S
	@echo $(COL_LIB)LIB  [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.cpp
	@echo $(COL_LIB)LIB  [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_SHARED_BASE)/%.c
	@echo $(COL_LIB)LIB  [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

# Local Libraries -------------------------------------------------------------
$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.S
	@echo $(COL_LIB)LIB  [ASM] $(notdir $<) $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.cpp
	@echo $(COL_LIB)LIB  [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o $@ -c $<

$(LIB_BIN)/%.o: $(LIBS_LOCAL_BASE)/%.c
	@echo $(COL_LIB)LIB  [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o $@ -c $<

# Handle user sources ---------------------------------------------------------
$(USR_BIN)/%.o: $(USR_SRC)/%.S
	@echo $(COL_SRC)USER [ASM] $< $(COL_ERR)
	@"$(CC)" $(S_FLAGS) $(INCLUDE) -o $@ -c $< 

$(USR_BIN)/%.o: $(USR_SRC)/%.c
	@echo $(COL_SRC)USER [CC]  $(notdir $<) $(COL_ERR)
	@"$(CC)" $(C_FLAGS) $(INCLUDE) -o "$@" -c $<

$(USR_BIN)/%.o: $(USR_SRC)/%.cpp
	@echo $(COL_SRC)USER [CPP] $(notdir $<) $(COL_ERR)
	@"$(CXX)" $(CPP_FLAGS) $(INCLUDE) -o "$@" -c $<

# Linking ---------------------------------------------------------------------
$(TARGET_ELF): $(CORE_LIB) $(LIB_OBJ) $(USR_OBJ)
	@echo $(COL_LINK)
	@echo [LD]  $@ $(COL_ERR)
	@$(CC) $(LD_FLAGS) -o "$@" $(USR_OBJ) $(LIB_OBJ) $(CORE_LIB) $(LIBS)
	@echo $(COL_OK)User code built and linked to libraries &&echo.

%.lst: %.elf
	@echo $(COL_LINK)
	@echo [LST] $@ $(COL_ERR)
	@$(OBJDUMP) -d -S --demangle --no-show-raw-insn --syms "$<"  > "$@"	
	@echo $(COL_OK)Sucessfully built project$(COL_RESET) &&echo.

%.hex: %.elf
	@echo $(COL_LINK)[HEX] $@ 
	@$(SIZE) "$<"
	@$(OBJCOPY) -O ihex -R.eeprom "$<" "$@"
	
	
# Cleaning --------------------------------------------------------------------
cleanUser:
	@echo $(COL_LINK)Cleaning user binaries...$(COL_RESET)
	@if exist $(USR_BIN) rd /s/q "$(USR_BIN)"
	@if exist "$(TARGET_LST)" del $(subst /,\,$(TARGET_LST))

cleanCore:
	@echo $(COL_LINK)Cleaning core binaries...$(COL_RESET)
	@if exist $(CORE_BIN) rd /s/q "$(CORE_BIN)"
	@if exist $(CORE_LIB) del  $(subst /,\,$(CORE_LIB))	

cleanLib:
	@echo $(COL_LINK)Cleaning user library binaries...$(COL_RESET)
	@if exist $(LIB_BIN) rd /s/q "$(LIB_BIN)"

# compiler generated dependency info ------------------------------------------
-include $(CORE_OBJ:.o=.d)
-include $(USR_OBJ:.o=.d)
-include $(LIB_OBJ:.o=.d)
 
Here a link to defragsters script https://github.com/Defragster/Tset

...

That is the mods I made to FrankB's decoding of how command line can execute the Arduino Builder - combined with TyCommander and an editor like SublimeText I have a great system I like.

Problem is it is WINDOWS ONLY - TyCommander compiles for Linux.

But the Compile.CMD itself uses Windows CMD shell operations to make it work. And the TSet extensions likewise use CMD shell prompts and steps to help assemble a BOARD specific version of that on demand.

Give it a look - I assume Linux script should be able to complete the same tasks …

Here is a Teensy 4 Compile.cmd script:
Code:
@echo off
SETLOCAL DisableDelayedExpansion EnableExtensions
rem *******************************
[U]rem Frank Bösing 11/2018
rem Windows Batch to compile Arduino sketches[/U]

rem Usage:
rem compile.cmd 0 : compile sketch
rem compile.cmd 1 : compile & upload sketch
rem compile.cmd 2 : rebuild & upload sketch
rem - Attention: Place compile.cmd in Sketch folder!
rem
rem Edit these paths:

set arduino=T:\arduino-1.8.9t4
set TyTools=T:\TyComm
set libs=T:\tCode\libraries
set tools=T:\Programs\TSet

rem *******************************
rem Set Teensy-specific variables here:
rem


[B]REM defragster was here 

set model=teensy40
set speed=396000000
set opt=o2std
set usb=serial[/B]
cd.

rem set keys=de-de
set keys=en-us

rem *******************************
rem Don't edit below this line
rem *******************************

for %%i in (*.ino) do set sketchname=%%i
if "%sketchname%"=="" (
  echo No Arduino Sketch found!
  exit 1
)

set myfolder=.\
set ino="%myfolder%%sketchname%"
set temp1="%temp%\\arduino_build_%sketchname%"
set temp2="%temp%\\arduino_cache_%sketchname%"
set fqbn=teensy:avr:%model%:usb=%usb%,speed=%speed%,opt=%opt%,keys=%keys%

if "%1"=="2" (
  echo Temp: %temp1%
  echo Temp: %temp2%
  del /s /q %temp1%>NUL
  del /s /q %temp2%>NUL
  echo Temporary files deleted.
)

if not exist %temp1% mkdir %temp1%
if not exist %temp2% mkdir %temp2%

[B]echo Building Sketch: %ino%
"%arduino%\arduino-builder" -verbose=1 -warnings=more -compile -logger=human -hardware "%arduino%\hardware" -hardware "%LOCALAPPDATA%\Arduino15\packages" -tools "%arduino%\tools-builder" -tools "%arduino%\hardware\tools\avr" -tools "%LOCALAPPDATA%\Arduino15\packages" -built-in-libraries "%arduino%\libraries" -libraries "%libs%" -fqbn=%fqbn% -build-path %temp1% -build-cache "%temp2%"  %ino%[/B]

if not "%1"=="0" (
  if "%errorlevel%"=="0" "%TyTools%\TyCommanderC.exe" upload --autostart --wait --multi "%temp1%\%sketchname%.%model%.hex"
  REM 1052 "%arduino%\hardware\tools\arm\bin\arm-none-eabi-gcc-nm.exe" "%temp1%\%sketchname%.elf" -n | "T:\Programs\TSet\imxrt-size.exe"
  "%arduino%\hardware\tools\arm\bin\arm-none-eabi-gcc-nm.exe" -n "%temp1%\%sketchname%.elf" | "%tools%\imxrt_size.exe"
)

exit %errorlevel%
 
maybe
Code:
-lstdc++ -nostdlib
is the source of your problem?
why linking to standard c++ library if you then say no std library

Also, are you by chance using a newer gcc version than Teensyduino?
 
Might be wrong. but to me it looks like the OP makefile does not handle the *.S files?
 
If anyone's still watching this old thread, I recently updated the sample Makefile in Teensy 4.0's core library.

https://github.com/PaulStoffregen/cores/blob/master/teensy4/Makefile

Yes, watching. I tried out this makefile and got the following error:-
make
/home/peter/Downloads/arduino-1.8.11/hardware/tools/arm/bin/arm-none-eabi-gcc -Os -Wl,--gc-sections,--relax -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb -Timxrt1062.ld -o Blink.ino.elf -larm_cortexM7lfsp_math -lm -lstdc++
/home/peter/Downloads/arduino-1.8.11/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: cannot open linker script file imxrt1062.ld: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [Makefile:127: Blink.ino.elf] Error 1

The makefile can't find imxrt1062.ld
It is located here
/home/peter/Downloads/arduino-1.8.11/hardware/teensy/avr/cores/teensy4/imxrt1062.ld

What am I doing wrong?
The modified makefile is below
Code:
# set your MCU type here, or make command line `make MCU=IMXRT1062`
MCU=IMXRT1062

# The name of your project (used to name the compiled .hex file)
TARGET = Blink.ino

# configurable options
OPTIONS = -DF_CPU=600000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE

# options needed by many Arduino libraries to configure for Teensy 4.0
OPTIONS += -D__$(MCU)__ -DARDUINO=10810 -DTEENSYDUINO=149 -DARDUINO_TEENSY40

# for Cortex M7 with single & double precision FPU
CPUOPTIONS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb

# use this for a smaller, no-float printf
#SPECS = --specs=nano.specs

# Other Makefiles and project templates for Teensy
#
# https://forum.pjrc.com/threads/57251?p=213332&viewfull=1#post213332
# https://github.com/apmorton/teensy-template
# https://github.com/xxxajk/Arduino_Makefile_master
# https://github.com/JonHylands/uCee


#************************************************************************
# Location of Teensyduino utilities, Toolchain, and Arduino Libraries.
# To use this makefile without Arduino, copy the resources from these
# locations and edit the pathnames.  The rest of Arduino is not needed.
#************************************************************************

# Those that specify a NO_ARDUINO environment variable will
# be able to use this Makefile with no Arduino dependency.
# Please note that if ARDUINOPATH was set, it will override
# the NO_ARDUINO behaviour.
ifndef NO_ARDUINO
# Path to your arduino installation
ARDUINOPATH = /home/peter/Downloads/arduino-1.8.11
endif

ifdef ARDUINOPATH

# path location for Teensy Loader, teensy_post_compile and teensy_reboot (on Linux)
TOOLSPATH = $(abspath $(ARDUINOPATH)/hardware/tools)

# path location for Arduino libraries (currently not used)
LIBRARYPATH = $(abspath $(ARDUINOPATH)/libraries)

# path location for the arm-none-eabi compiler
COMPILERPATH = $(abspath $(ARDUINOPATH)/hardware/tools/arm/bin)

else
# Default to the normal GNU/Linux compiler path if NO_ARDUINO
# and ARDUINOPATH was not set.
COMPILERPATH = /usr/bin

endif

#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************

# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -O2 $(CPUOPTIONS) -MMD $(OPTIONS) -I. -ffunction-sections -fdata-sections

# compiler options for C++ only
CXXFLAGS = -std=gnu++14 -felide-constructors -fno-exceptions -fpermissive -fno-rtti -Wno-error=narrowing

# compiler options for C only
CFLAGS =

# linker options
LDFLAGS = -Os -Wl,--gc-sections,--relax $(SPECS) $(CPUOPTIONS) -T$(MCU_LD)

# additional libraries to link
LIBS = -larm_cortexM7lfsp_math -lm -lstdc++


# names for the compiler programs
CC = $(COMPILERPATH)/arm-none-eabi-gcc
CXX = $(COMPILERPATH)/arm-none-eabi-g++
OBJCOPY = $(COMPILERPATH)/arm-none-eabi-objcopy
SIZE = $(COMPILERPATH)/arm-none-eabi-size

# automatically create lists of the sources and objects
# TODO: this does not handle Arduino libraries yet...
C_FILES := $(wildcard *.c)
CPP_FILES := $(wildcard *.cpp)
OBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o)


# the actual makefile rules (all .o files built by GNU make's default implicit rules)

all: $(TARGET).hex

$(TARGET).elf: $(OBJS) $(MCU_LD)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

%.hex: %.elf
	$(SIZE) $<
	$(OBJCOPY) -O ihex -R .eeprom $< $@
ifneq (,$(wildcard $(TOOLSPATH)))
	$(TOOLSPATH)/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(TOOLSPATH)
	-$(TOOLSPATH)/teensy_reboot
endif

# compiler generated dependency info
-include $(OBJS:.o=.d)

# make "MCU" lower case
LOWER_MCU := $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(MCU)))))))))))))))))))))))))))
MCU_LD = $(LOWER_MCU).ld

clean:
	rm -f *.o *.d $(TARGET).elf $(TARGET).hex
 
You'll want to set the path to that linker script with the MCU_LD variable already defined at the bottom of your Makefile. Or copy the script to the same directory as your working directory
 
You'll want to set the path to that linker script with the MCU_LD variable already defined at the bottom of your Makefile. Or copy the script to the same directory as your working directory

Thanks, that did the job.
 
Status
Not open for further replies.
Back
Top