PDA

View Full Version : Arduino IDE mod



duff
07-11-2013, 09:07 PM
so i built a couple of prototype boards for a project i'm doing currently which use all three of the hardware serial ports and becuase of my dyslexia:confused: i wired up the serial port that uses the xbee to different serial ports for the two prototypes i have. prototype1 uses serial3 and prototype2 uses serial2. I hacked the Libelium xbee library to use with the teensy and was having to manually modify the library to tell it which serial port was using the xbee which was a real pain. So i started looking into how i can do this more efficiently and came up with this arduino IDE mod that other might find useful in their projects.

Basically i added a new menu option to the "Tools" menu that allows me to send a #define macro when uploading, similar to setting the Keyboard layout, which is actually how i figured it out.

1. modify the board.txt file in the teensy core directory and add in the menu you want. then set menu options and set #define macro for each option. :Note this is just teensy 3 part of the board.txt file.


menu.usb=USB Type
menu.speed=CPU Speed
menu.keys=Keyboard Layout

######## New Menu ########
menu.serial_port=XBee Serial Port
#######################

teensy3.name=Teensy 3.0
teensy3.upload.protocol=halfkay
teensy3.upload.maximum_size=131072
teensy3.upload.maximum_ram_size=16384
teensy3.upload.speed=12000000
teensy3.upload.disable_flushing=true
teensy3.bootloader.path=undefined
teensy3.serial.restart_cmd=true
teensy3.serial.safe_baud_rates_only=true
teensy3.upload.avrdude_wrapper=teensy_reboot
teensy3.build.mcu=mk20dx128
teensy3.build.cpu=cortex-m4
teensy3.build.option1=-mthumb
teensy3.build.option2=-nostdlib
teensy3.build.option3=-D__MK20DX128__
#teensy3.build.option4=-DXBEE_SERIAL_PORT=2
teensy3.build.cppoption1=-fno-rtti
teensy3.build.linkoption1=-mthumb
teensy3.build.additionalobject1=-larm_cortexM4l_math
teensy3.build.linkscript=mk20dx128.ld
teensy3.build.architecture=arm-none-eabi
teensy3.build.command.gcc=arm-none-eabi-gcc
teensy3.build.command.g++=arm-none-eabi-g++
teensy3.build.command.ar=arm-none-eabi-ar
teensy3.build.command.objcopy=arm-none-eabi-objcopy
teensy3.build.command.objdump=arm-none-eabi-objdump
teensy3.build.command.size=arm-none-eabi-size
teensy3.build.core=teensy3
teensy3.build.noarchive=true
teensy3.build.elide_constructors=true
teensy3.build.gnu0x=true
teensy3.build.dependency=true
teensy3.build.time_t=true
#teensy3.build.linker_relaxation=true
teensy3.build.post_compile_script=teensy_post_comp ile
#teensy3.build.serial_number=true
teensy3.menu.usb.serial.name=Serial
teensy3.menu.usb.serial.build.define0=-DUSB_SERIAL
teensy3.menu.usb.hid.name=Keyboard + Mouse + Joystick
teensy3.menu.usb.hid.build.define0=-DUSB_HID
teensy3.menu.usb.hid.fake_serial=teensy_gateway
teensy3.menu.usb.serialhid.name=Serial + Keyboard + Mouse + Joystick
teensy3.menu.usb.serialhid.build.define0=-DUSB_SERIAL_HID
#teensy3.menu.usb.int_disk.name=Disk(Internal) + Keyboard
#teensy3.menu.usb.int_disk.build.define0=-DUSB_DISK
#teensy3.menu.usb.int_disk.fake_serial=teensy_gate way
#teensy3.menu.usb.int_disk.build.elfpatch=mktinyfa t
#teensy3.menu.usb.sd_disk.name=Disk(SD Card) + Keyboard
#teensy3.menu.usb.sd_disk.build.define0=-DUSB_DISK_SDFLASH
#teensy3.menu.usb.sd_disk.fake_serial=teensy_gatew ay
teensy3.menu.usb.midi.name=MIDI
teensy3.menu.usb.midi.build.define0=-DUSB_MIDI
teensy3.menu.usb.midi.fake_serial=teensy_gateway
teensy3.menu.usb.rawhid.name=Raw HID
teensy3.menu.usb.rawhid.build.define0=-DUSB_RAWHID
teensy3.menu.usb.rawhid.fake_serial=teensy_gateway
teensy3.menu.usb.flightsim.name=Flight Sim Controls
teensy3.menu.usb.flightsim.build.define0=-DUSB_FLIGHTSIM
teensy3.menu.usb.flightsim.fake_serial=teensy_gate way
teensy3.menu.speed.96.name=96 MHz (overclock)
teensy3.menu.speed.48.name=48 MHz
teensy3.menu.speed.24.name=24 MHz
teensy3.menu.speed.96.build.f_cpu=96000000
teensy3.menu.speed.48.build.f_cpu=48000000
teensy3.menu.speed.24.build.f_cpu=24000000
teensy3.menu.keys.en-us.name=US English
teensy3.menu.keys.en-us.build.define1=-DLAYOUT_US_ENGLISH
teensy3.menu.keys.fr-ca.name=Canadian French
teensy3.menu.keys.fr-ca.build.define1=-DLAYOUT_CANADIAN_FRENCH
teensy3.menu.keys.xx-ca.name=Canadian Multilingual
teensy3.menu.keys.xx-ca.build.define1=-DLAYOUT_CANADIAN_MULTILINGUAL
teensy3.menu.keys.da-da.name=Danish
teensy3.menu.keys.da-da.build.define1=-DLAYOUT_DANISH
teensy3.menu.keys.fi-fi.name=Finnish
teensy3.menu.keys.fi-fi.build.define1=-DLAYOUT_FINNISH
teensy3.menu.keys.fr-fr.name=French
teensy3.menu.keys.fr-fr.build.define1=-DLAYOUT_FRENCH
teensy3.menu.keys.fr-be.name=French Belgian
teensy3.menu.keys.fr-be.build.define1=-DLAYOUT_FRENCH_BELGIAN
teensy3.menu.keys.fr-ch.name=French Swiss
teensy3.menu.keys.fr-ch.build.define1=-DLAYOUT_FRENCH_SWISS
teensy3.menu.keys.de-de.name=German
teensy3.menu.keys.de-de.build.define1=-DLAYOUT_GERMAN
teensy3.menu.keys.de-dm.name=German (Mac)
teensy3.menu.keys.de-dm.build.define1=-DLAYOUT_GERMAN_MAC
teensy3.menu.keys.de-ch.name=German Swiss
teensy3.menu.keys.de-ch.build.define1=-DLAYOUT_GERMAN_SWISS
teensy3.menu.keys.is-is.name=Icelandic
teensy3.menu.keys.is-is.build.define1=-DLAYOUT_ICELANDIC
teensy3.menu.keys.en-ie.name=Irish
teensy3.menu.keys.en-ie.build.define1=-DLAYOUT_IRISH
teensy3.menu.keys.it-it.name=Italian
teensy3.menu.keys.it-it.build.define1=-DLAYOUT_ITALIAN
teensy3.menu.keys.no-no.name=Norwegian
teensy3.menu.keys.no-no.build.define1=-DLAYOUT_NORWEGIAN
teensy3.menu.keys.pt-pt.name=Portuguese
teensy3.menu.keys.pt-pt.build.define1=-DLAYOUT_PORTUGUESE
teensy3.menu.keys.pt-br.name=Portuguese Brazilian
teensy3.menu.keys.pt-br.build.define1=-DLAYOUT_PORTUGUESE_BRAZILIAN
teensy3.menu.keys.es-es.name=Spanish
teensy3.menu.keys.es-es.build.define1=-DLAYOUT_SPANISH
teensy3.menu.keys.es-mx.name=Spanish Latin America
teensy3.menu.keys.es-mx.build.define1=-DLAYOUT_SPANISH_LATIN_AMERICA
teensy3.menu.keys.sv-se.name=Swedish
teensy3.menu.keys.sv-se.build.define1=-DLAYOUT_SWEDISH
teensy3.menu.keys.tr-tr.name=Turkish (partial)
teensy3.menu.keys.tr-tr.build.define1=-DLAYOUT_TURKISH
teensy3.menu.keys.en-gb.name=United Kingdom
teensy3.menu.keys.en-gb.build.define1=-DLAYOUT_UNITED_KINGDOM
teensy3.menu.keys.usint.name=US International
teensy3.menu.keys.usint.build.define1=-DLAYOUT_US_INTERNATIONAL

######## Menu Options and Define Macro's #########
teensy3.menu.serial_port.1.name=Serial 1
teensy3.menu.serial_port.1.build.define2=-DXBEE_SERIAL1
teensy3.menu.serial_port.2.name=Serial 2
teensy3.menu.serial_port.2.build.define2=-DXBEE_SERIAL2
teensy3.menu.serial_port.3.name=Serial 3
teensy3.menu.serial_port.3.build.define2=-DXBEE_SERIAL3
######################################

2. use #ifdef macro in sketch or library.


void setup() {
Serial.begin(0);
while(!Serial);
delay(100);
#ifdef XBEE_SERIAL1
Serial1.begin(9600);
Serial.println("Serial 1 Configured");
#elif XBEE_SERIAL2
Serial2.begin(9600);
Serial.println("Serial 2 Configured");
#elif XBEE_SERIAL3
Serial3.begin(9600);
Serial.println("Serial 3 Configured");
#else
#error "Error, XBEE Serial port must be Serial 1, Serial 2 or Serial 3"
#endif
}

void loop() {
// do something?
}


while i'm sure there are many ways to do this I thought this was pretty cool, now i can easily setup different parameters in
the IDE for my programs!

duff