Go Down

Topic: [SOLVED] Is there any way to attach -D from within arduino IDE (Read 2325 times) previous topic - next topic

liudr

Dec 28, 2012, 06:20 am Last Edit: Dec 28, 2012, 07:26 pm by liudr Reason: 1
I am trying to attach a -Ddisable_simple_fns option to the compiler command that arduino IDE generates automatically. Is there a way to do it? Thanks. It would be nice to have this hack "custom def" in arduino IDE although I don't know how to.

[Edit]: The solution appears to require either visual studio plugin or arduino 1.5 and creating new board def in boards.txt with a "board_name.build.extra_flags=-Dsomething=value".

Coding Badly

#1
Dec 28, 2012, 07:17 am Last Edit: Dec 28, 2012, 08:59 am by Coding Badly Reason: 1

I believe IDE 1.5 reads the command-lines from platform.txt.


Edit: Remove plural.

liudr

Thanks. I will put IDE upgrade on my agenda once I'm done with work at hand. I am using 1.0 right now.

pYro_65

#3
Dec 28, 2012, 08:24 am Last Edit: Dec 28, 2012, 08:26 am by pYro_65 Reason: 1


I believe IDE 1.5 reads the command-lines from platforms.txt.


Hey, i'm using 1.5.1r2 I cannot find a 'platforms.txt',
I also had a browse through the IDE preferences ( C:\Users\Chris\AppData\Roaming\Arduino ) but no luck. Would be very nice if I could change the optimisation levels.

Any locations I should be looking in?

EDIT: windows search is blind ( the machine's fault not the user  :P ), it was in "D:\arduino-1.5.1r2\hardware\arduino\avr"

Coding Badly

#4
Dec 28, 2012, 08:57 am Last Edit: Dec 28, 2012, 08:59 am by Coding Badly Reason: 1

Sorry about that.  The filename is[font=Courier New] platform.txt [/font](singular; not plural).

Visual Micro

#5
Dec 28, 2012, 02:56 pm Last Edit: Dec 28, 2012, 04:22 pm by Visual Micro Reason: 1
It's in the exeFolder/hardware/arduino/avr and can work in conjunction with the new properties in the 1.5 boards.txt

Alternatively if you want it to work with 1.0.x formats then the visual studio plugin allows any number of -D defines via the project property "Defines - Project"

But 1.5 might be the simplest route unless you also want intellisense etc and are using windows.
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

liudr


Visual Micro

Download via the main site here

You need a copy of Visual Studio Pro. This page shows how to get a copy for free

If you have any questions or want the serial debugger upgrade then register for the forum
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

liudr


It's in the exeFolder/hardware/arduino/avr and can work in conjunction with the new properties in the 1.5 boards.txt


Is it only possible to modify boards.txt to add another def in 1.5?

Thanks for the visual studio link.

Visual Micro

#9
Dec 28, 2012, 05:34 pm Last Edit: Dec 28, 2012, 07:32 pm by Visual Micro Reason: 1
I've only recently started with 1.5 so can't recall exactly but I think you can add your own overrides and "recipe" patterns directly to the boards.txt. You will find the default settings and recipe patterns in the platform.txt. Example:-

Code: [Select]
recipe.cpp.o.pattern=

So this would mean you could copy a board def in the boards.txt, change the name to whatever you want and add your own recipe specifically for your new board definition. This would allow you to optionally invoke your additional compiler defines just by switching board. (I hope this info is correct)

If you have vs installed then it is certainly easier to achieve this with the vs plugin, which also allows us to set a -D list on a per configuration basis. This means, for example, that we can have a -D list for "My Normal Compile" and a list for "My Special Compile" etc.

EDIT: How to copy a board def - Example

Below is the def for the Uno
Code: [Select]
##############################################################

uno.name=Arduino Uno
uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200

uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0x05
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex

uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard


Below is a duplicate called Arduino Uno 2. Notice that each property for the board starts with a unique id, in this case "uno2". So to copy a def you only need to set the .name property and ensure that each entry starts with a unique id of your choice.
Code: [Select]
##############################################################

uno2.name=Arduino Uno 2
uno2.upload.tool=avrdude
uno2.upload.protocol=arduino
uno2.upload.maximum_size=32256
uno2.upload.speed=115200

uno2.bootloader.tool=avrdude
uno2.bootloader.low_fuses=0xFF
uno2.bootloader.high_fuses=0xDE
uno2.bootloader.extended_fuses=0x05
uno2.bootloader.unlock_bits=0x3F
uno2.bootloader.lock_bits=0x0F
uno2.bootloader.file=optiboot/optiboot_atmega328.hex

uno2.build.mcu=atmega328p
uno2.build.f_cpu=16000000L
uno2.build.core=arduino
uno2.build.variant=standard
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

liudr


I've only recently started with 1.5 so can't recall exactly but I think you can add your own "recipe" pattern directly to the boards.txt. You will find the default "recipe" patterns in the paltform.txt

Code: [Select]
recipe.cpp.o.pattern=

So this would mean you could copy a board def in the boards.txt, change the name to whatever you want and add your own recipe specifically for your new board definition. This would allow you to optionally invoke your additional compiler defines just by switching board. (I hope this info is correct)

It's certainly easier to achieve this with the vs plugin which also allows you to set a -D list on a per configuration basis. Hence you can have a -D list for "My Normal Compile" and a list for "My Special Compile" etc.


Thanks. I added a new line phi_panel.build.extra_flags=-Ddisable_simple_fns to a new board def I copied and changed and it did the trick, according to the verbose output. I wonder if I can do phi_panel.build.extra_flags=-DXX=10 with the defined number instead of just defining a name. Will try later.

Code: [Select]
##############################################################

phi_panel.name=Phi panel
phi_panel.upload.tool=avrdude
phi_panel.upload.protocol=arduino
phi_panel.upload.maximum_size=32256
phi_panel.upload.speed=115200

phi_panel.bootloader.tool=avrdude
phi_panel.bootloader.low_fuses=0xFF
phi_panel.bootloader.high_fuses=0xDE
phi_panel.bootloader.extended_fuses=0x05
phi_panel.bootloader.unlock_bits=0x3F
phi_panel.bootloader.lock_bits=0x0F
phi_panel.bootloader.file=optiboot/optiboot_atmega328.hex

phi_panel.build.mcu=atmega328p
phi_panel.build.f_cpu=16000000L
phi_panel.build.core=arduino
phi_panel.build.variant=standard
phi_panel.build.extra_flags=-Ddisable_simple_fns

## recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -mmcu={build.mcu} -Ddisable_simple_fns -DF_CPU={build.f_cpu} -D{software}={runtime.ide.version} {build.extra_flags} {includes} "{source_file}" -o "{object_file}"

Visual Micro

Great. I don't see why you can't do that. The extra flags are just passed to the compile statement without change, so should work fine.
Arduino for Microsoft Visual Studio Pro and Atmel Studio 6.1 http://www.visualmicro.com
Arduino Debugger http://www.visualmicro.com/post/2012/05/05/Debug-Arduino-Overview.aspx

liudr

Yep, everything I typed in there gets appended to the compiler options. Thanks for helping me through! Karma for you!

Go Up