queezythegreat / arduino-cmake

Arduino CMake Build system
645 stars 216 forks source link

Teensyduino support #67

Closed spiderwebby closed 10 years ago

spiderwebby commented 10 years ago

Would it be possible to add support for the teensy boards?

queezythegreat commented 10 years ago

Hi, in theory yes, support should be already in the latest version of Arduino-CMake.

I'm not quite sure how Teensyduino differs from Arduino, but if it is done as a hardware platform you should be able use the Teensyduino. There is a special command called register_hardware_platform(), which should enable teensy support:

register_hardware_platform(${ARDUINO_SDK_PATH}/hardware/teensy/)

This should make the teensy boards available, but I haven't tested this if it works!!

Could you try this command out, and tell me if it worked for you? This feature was added in order to prepare for Arduino version 1.5 support, and being able to use extra hardware platforms. Internally I use this command to register the official arduino hardware platform (located in ${ARDUINO_SDK_PATH}/hardware/arduino).

spiderwebby commented 10 years ago

How/where should I use it?

queezythegreat commented 10 years ago

Hi, I don't have any free time now, but I will try to get Teensy working over the weekend. I will post my results.

But generally you should use this command before the project() or any generate_XXX() commands.

spiderwebby commented 10 years ago

I ended up with: webby@webby-vaio ~/Development/AVR/blink/build (git)-[master] % cmake .. CMake Error at CMakeLists.txt:7 (register_hardware_platform): Unknown CMake command "register_hardware_platform".

-- Configuring incomplete, errors occurred!

queezythegreat commented 10 years ago

Hi, you should add the register_... command after the project() command. I tried to get teensy installed on my machine but it fails, so I cannot test it out :(

spiderwebby commented 10 years ago

Progress! it's happy with the CMakeLists.txt, but throws a wobbley at the teensy hardware files:

/usr/share/arduino/hardware/teensy/cores/teensy/core_pins.h:1952:15: error: operator '==' has no left operand /usr/share/arduino/hardware/teensy/cores/teensy/core_pins.h:1956:15: error: operator '==' has no left operand ...etc

I'll have a go at it tomorrow

As for the teensy installer: it's a nightmare. I ended up extracting a copy of arduino from a .tar, pointing the teensy installer at it, then transferring the new libraries and whatnot into the distro's arduino install

spiderwebby commented 10 years ago

The error: operator '==' has no left operand is caused by: #if F_CPU == 16000000L

I've tried a few variants of set(ARDUINO_C_FLAGS "-DF_CPU=16000000L") to no avail.

queezythegreat commented 10 years ago

Hi, could you zip'up your Arduino directory and publish it somewhere (maybe Dropbox). I wasn't able to get Teensyduino installed so I cannot test anything...

spiderwebby commented 10 years ago

https://dl.dropboxusercontent.com/u/41398020/arduino.tar.gz

queezythegreat commented 10 years ago

Hi, I have good and bad news... In theory you could get a board built with Arduino-CMake, but if you add some additional cmake commands to emulate what the Teensyduino does...

The people that make Teensy have royally screwed up everything, changing the behavior of the standard Arduino SDK, which complicates everything.

The first problem you encountered was the missing F_CPU define, which is selectable in the GUI and not present in ${ARDUINO_CMAKE_SDK}/hardware/teensy/boards.txt (Arduino CMake relies on that file...). So to get that going you need to add the following before any generate_XXX() commands:

add_definitions(-DF_CPU=16000000L)

Next there are some keyboard layouts (don't quite now what that is), but you need to add another define:

add_defintions(-DLAYOUT_US_ENGLISH)

You can chose from the following list of layouts:

LAYOUT_US_ENGLISH
LAYOUT_US_INTERNATIONAL
LAYOUT_GERMAN
LAYOUT_GERMAN_MAC
LAYOUT_CANADIAN_FRENCH
LAYOUT_CANADIAN_MULTILINGUAL
LAYOUT_UNITED_KINGDOM
LAYOUT_FINNISH
LAYOUT_FRENCH
LAYOUT_DANISH
LAYOUT_NORWEGIAN
LAYOUT_SWEDISH
LAYOUT_SPANISH
LAYOUT_PORTUGUESE
LAYOUT_ITALIAN
LAYOUT_PORTUGUESE_BRAZILIAN
LAYOUT_FRENCH_BELGIAN
LAYOUT_GERMAN_SWISS
LAYOUT_FRENCH_SWISS
LAYOUT_SPANISH_LATIN_AMERICA
LAYOUT_IRISH
LAYOUT_ICELANDIC
LAYOUT_TURKISH

Then you have to select what USB type (I still don't quite know what this is) you are going to use for example:

add_definitions(-DUSB_SERIAL)

You can chose from this list:

USB_SERIAL
USB_HID
USB_SERIAL_HID
USB_DISK
USB_DISK_SDFLASH
USB_MIDI
USB_RAWHID
USB_FLIGHTSIM

Finally, based on the board type you have selected (teensy1, teensy2, etc), you need to add a extra board type define:

add_definition(-D__AVR_ATmega32U4__)

You can chose from the list below, although I do not know which is which right now:

__AVR_ATmega32U4__
__AVR_AT90USB162__
__AVR_AT90USB646__
__AVR_AT90USB1286__

I have also seen that there are some post compile scripts executed, this would require the use of some extra cmake commands to execute the required scripts right after build.

In short you can get Teensy built under Arduino-CMake, but you are going to have to work for it :( The guys that made Teensy really screwed this up, they did everything to break compatibility with the Arduino SDK.

I hope this information helps you a little bit, I don't have the time to delve into the details of Teensy right now.

PS: Arduino-CMake has to be modified a little bit, in order to get the F_CPU define working:

diff --git a/cmake/Platform/Arduino.cmake b/cmake/Platform/Arduino.cmake
index c14ea2d..8285ebe 100644
--- a/cmake/Platform/Arduino.cmake
+++ b/cmake/Platform/Arduino.cmake
@@ -789,7 +789,10 @@ function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID MANUAL)
         endif()

         # output
-        set(COMPILE_FLAGS "-DF_CPU=${${BOARD_ID}.build.f_cpu} -DARDUINO=${ARDUINO_VERSION_DEFINE} -mmcu=${${BOARD_ID}.build.mcu}")
+        set(COMPILE_FLAGS "-DARDUINO=${ARDUINO_VERSION_DEFINE} -mmcu=${${BOARD_ID}.build.mcu}")
+        if(DEFINED ${BOARD_ID}.build.f_cpu)
+            set(COMPILE_FLAGS "${COMPILE_FLAGS} -DF_CPU=${${BOARD_ID}.build.f_cpu}")
+        endif()
         if(DEFINED ${BOARD_ID}.build.vid)
             set(COMPILE_FLAGS "${COMPILE_FLAGS} -DUSB_VID=${${BOARD_ID}.build.vid}")
         endif()
queezythegreat commented 10 years ago

I'm closing this issue due to inactivity. You can reopen it if something changes.

d0ughb0y commented 7 years ago

The teensy 3 compiles just fine in Arduino IDE, so I don't know about the statement that it royally screwed up everything. I think it is arduino cmake, which is a non standard, not officially arduino supported, that is not compatible. Perhaps if the plugin can just invoke the build just like the arduino ide, then anything that works with the ide will work with the plugin.