I have a Teensy 3.1 and a Teensy CLI. My first project was to create KVM port switcher. My existing KVM will not recognize the hot key sequences from my wireless keyboard (logitech K800) and the KVBM is hidden so using the port switches is not easy. I created a 4 button circuit that lets me switch directly to any port. Both boards work perfectly the code and the wiring were very easy to do. I had to use the Arduino IDE in conjunction with Teensyduino. However I don't like using the IDE I prefer to use a simple editor and compile and upload from the CLI. I have been doing this for all of my Arduino projects for a while. So I am trying this with the same code for the KVM switcher. I am getting close but kinda stuck now and I am sure it's some simple tweaks.
I pulled the Makefile from hardware/teensy/avr/cores/teensy3/Makefile
when I run it I get the following error.
beta:Keybrd kardacian$ make
make: *** No rule to make target `mk20dx256.ld', needed by `Keybrd.elf'. Stop.
Here is the code that I am trying to compile and upload. Keep in mind this codes work fine when I compile and upload via teensyduino.
//Sketch to switch iogear KVM active port
void SendIt(int Port);
const int ledPin = 13;
//****************************************************************************************
// Setup - Runs Once
//****************************************************************************************
void setup() {
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
Keyboard.begin() ;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
//****************************************************************************************
// Loop - RUns constantly
//****************************************************************************************
void loop() {
if ( digitalRead( 9 ) == LOW ) { SendIt(1); }
if ( digitalRead( 10 ) == LOW ) { SendIt(2); }
if ( digitalRead( 11 ) == LOW ) { SendIt(4); }
if ( digitalRead( 12 ) == LOW ) { SendIt(3); }
}
//****************************************************************************************
// Sendit Function to send keystrokes to KVM based which button is pushed
//****************************************************************************************
void SendIt(int Port) {
digitalWrite(ledPin, LOW);
Keyboard.press( MODIFIERKEY_CTRL ) ;
Keyboard.releaseAll() ;
delay(300);
Keyboard.press( MODIFIERKEY_CTRL ) ;
Keyboard.releaseAll() ;
delay(600);
Keyboard.print( Port ); // holds the value of the button that was pushed
delay(600);
Keyboard.press( KEY_ENTER ) ;
Keyboard.releaseAll() ;
digitalWrite(ledPin, HIGH);
}
Here is the unedited makefile from the teensy 3.1 install
# The name of your project (used to name the compiled .hex file)
TARGET = main
# Path to your arduino installation
ARDUINOPATH ?= ../../../../..
#ARDUINOPATH ?= ../../../..
# configurable options
OPTIONS = -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE
# options needed by many Arduino libraries to configure for Teensy 3.0
OPTIONS += -D__MK20DX256__ -DARDUINO=10600 -DTEENSYDUINO=121
# Other Makefiles and project templates for Teensy 3.x:
#
# 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.
#************************************************************************
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
TOOLSPATH = $(ARDUINOPATH)/hardware/tools # on Linux
# path location for Arduino libraries (currently not used)
LIBRARYPATH = $(ARDUINOPATH)/libraries
# path location for the arm-none-eabi compiler
COMPILERPATH = $(ARDUINOPATH)/hardware/tools/arm/bin
#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************
# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD $(OPTIONS) -I.
# compiler options for C++ only
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti
# compiler options for C only
CFLAGS =
# linker options
LDFLAGS = -Os -Wl,--gc-sections,--defsym=__rtc_localtime=0 --specs=nano.specs -mcpu=cortex-m4 -mthumb -Tmk20dx256.ld
# additional libraries to link
LIBS = -lm
# names for the compiler programs
CC = $(abspath $(COMPILERPATH))/arm-none-eabi-gcc
CXX = $(abspath $(COMPILERPATH))/arm-none-eabi-g++
OBJCOPY = $(abspath $(COMPILERPATH))/arm-none-eabi-objcopy
SIZE = $(abspath $(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) mk20dx256.ld
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
%.hex: %.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(abspath $(TOOLSPATH))/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(abspath $(TOOLSPATH))
-$(abspath $(TOOLSPATH))/teensy_reboot
# compiler generated dependency info
-include $(OBJS:.o=.d)
clean:
rm -f *.o *.d $(TARGET).elf $(TARGET).hex
I pulled the Makefile from hardware/teensy/avr/cores/teensy3/Makefile
when I run it I get the following error.
beta:Keybrd kardacian$ make
make: *** No rule to make target `mk20dx256.ld', needed by `Keybrd.elf'. Stop.
Here is the code that I am trying to compile and upload. Keep in mind this codes work fine when I compile and upload via teensyduino.
//Sketch to switch iogear KVM active port
void SendIt(int Port);
const int ledPin = 13;
//****************************************************************************************
// Setup - Runs Once
//****************************************************************************************
void setup() {
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
Keyboard.begin() ;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
//****************************************************************************************
// Loop - RUns constantly
//****************************************************************************************
void loop() {
if ( digitalRead( 9 ) == LOW ) { SendIt(1); }
if ( digitalRead( 10 ) == LOW ) { SendIt(2); }
if ( digitalRead( 11 ) == LOW ) { SendIt(4); }
if ( digitalRead( 12 ) == LOW ) { SendIt(3); }
}
//****************************************************************************************
// Sendit Function to send keystrokes to KVM based which button is pushed
//****************************************************************************************
void SendIt(int Port) {
digitalWrite(ledPin, LOW);
Keyboard.press( MODIFIERKEY_CTRL ) ;
Keyboard.releaseAll() ;
delay(300);
Keyboard.press( MODIFIERKEY_CTRL ) ;
Keyboard.releaseAll() ;
delay(600);
Keyboard.print( Port ); // holds the value of the button that was pushed
delay(600);
Keyboard.press( KEY_ENTER ) ;
Keyboard.releaseAll() ;
digitalWrite(ledPin, HIGH);
}
Here is the unedited makefile from the teensy 3.1 install
# The name of your project (used to name the compiled .hex file)
TARGET = main
# Path to your arduino installation
ARDUINOPATH ?= ../../../../..
#ARDUINOPATH ?= ../../../..
# configurable options
OPTIONS = -DF_CPU=48000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH -DUSING_MAKEFILE
# options needed by many Arduino libraries to configure for Teensy 3.0
OPTIONS += -D__MK20DX256__ -DARDUINO=10600 -DTEENSYDUINO=121
# Other Makefiles and project templates for Teensy 3.x:
#
# 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.
#************************************************************************
# path location for Teensy Loader, teensy_post_compile and teensy_reboot
TOOLSPATH = $(ARDUINOPATH)/hardware/tools # on Linux
# path location for Arduino libraries (currently not used)
LIBRARYPATH = $(ARDUINOPATH)/libraries
# path location for the arm-none-eabi compiler
COMPILERPATH = $(ARDUINOPATH)/hardware/tools/arm/bin
#************************************************************************
# Settings below this point usually do not need to be edited
#************************************************************************
# CPPFLAGS = compiler options for C and C++
CPPFLAGS = -Wall -g -Os -mcpu=cortex-m4 -mthumb -nostdlib -MMD $(OPTIONS) -I.
# compiler options for C++ only
CXXFLAGS = -std=gnu++0x -felide-constructors -fno-exceptions -fno-rtti
# compiler options for C only
CFLAGS =
# linker options
LDFLAGS = -Os -Wl,--gc-sections,--defsym=__rtc_localtime=0 --specs=nano.specs -mcpu=cortex-m4 -mthumb -Tmk20dx256.ld
# additional libraries to link
LIBS = -lm
# names for the compiler programs
CC = $(abspath $(COMPILERPATH))/arm-none-eabi-gcc
CXX = $(abspath $(COMPILERPATH))/arm-none-eabi-g++
OBJCOPY = $(abspath $(COMPILERPATH))/arm-none-eabi-objcopy
SIZE = $(abspath $(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) mk20dx256.ld
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
%.hex: %.elf
$(SIZE) $<
$(OBJCOPY) -O ihex -R .eeprom $< $@
$(abspath $(TOOLSPATH))/teensy_post_compile -file=$(basename $@) -path=$(shell pwd) -tools=$(abspath $(TOOLSPATH))
-$(abspath $(TOOLSPATH))/teensy_reboot
# compiler generated dependency info
-include $(OBJS:.o=.d)
clean:
rm -f *.o *.d $(TARGET).elf $(TARGET).hex