I don't want to attack the great work you guys do, but I simply prefer coding with TextMate rather than the Arduino IDE. Getting syntax highlighting was very easy with the help of the keywords.txt file. Right now I'm using AppleScripts from within TextMate to Run & Upload using the Arduino IDE. But this means the IDE has to be open and comes front most. Moreover, the actions take more time. I was wondering, is there any documentation about the build process? What would one do to achieve the same results the IDE does when you compile the code but from within a terminal? The IDE seems to be linking and building all the libraries on the fly. I take it if I were to manually link to the libraries a single avr-gcc command would build everything. Is this right? Apart from that, what else does it do? How does it create the .hex, .rom and .elf files? Uploading seems pretty straight forward though.
Thanks a lot ^.^
P.S. Let me know if you're interested in the bundle, I could put it up on svn or something!
My bad, I missed the readily available Makefile. :-[
Works nicely ^-^ however it only seems to work with 0007, or at least not with 0009 (haven't tested 0008). What would be needed to make it work with 0009?
A TextMate bundle would be awesome. Please post it when you think it's ready. BTW, there's more information on the build process here: http://www.arduino.cc/en/Hacking/BuildProcess. There have been a couple of requests for a command line version of the Arduino software (e.g. a Java .jar) that could do things like the preprocessing of sketch code and uploading of sketches. Would that be useful for this? (No promises, though.)
It would be very useful as the bundle wouldn't need to be updated (much at least) when a new version is released. It would also mean that you could edit from either TM or the IDE without needing to add all the prototypes and linking. Maybe the program could accept a config file for setting the type of uC and board or just as parameters?
That would also mean the bundle could possibly be compatible with the E-TextEditor.
I would vote for a command line script that can be invoked from BBEdit … on the Mac
cheers … BBR
theres' something better than BBedit? Will it work in my cave? I only have a few batteries left in here. :)
Is there a "generic" way of getting the Arduino development environment to build a sketch to binary form from the command line? That would solve this "problem", right?
This is pretty much was David was proposing.
When working on pure avr-gcc projects (off arduino goodness), I simply hit Comand-R (r like in run) and textmate starts executing the makefile which is living in the same folder.
David once also released a makfile for arduino! See http://www.arduino.cc/en/Hacking/CommandLine
EDIT: @xSmurf: oops! I just see you allready found the makfile... I missed your edit in the second post. I leave the link here as a reference.
But somewhere on the forum I think I've read, the arduino makefile is now somehow out of date ....
I haven't tested it since the 0007 release. I only know that within the current arduino IDE there's no makefile beeing used besides java to compile everything.
a comandline preprocessing java for arduino code would be gorgeous. Could you still keep the actuall compiling step in a makefile? I think it's a nice standard.
As everything is still avr-gcc/libc compatible so far, it would be just convenient to stay compatible with a standardised compiling scheme. Have you heard of www.cmake.org? It looks like they try to avoid plattform specific issues like you reported with make in first arduino releases.
A textmate bundle could just issue the java preprocessing comand with a dedicated preferences.txt and then start (c)make...
last edited: [timestamp=1188259247]
I tried using the makefile from 0009 and I modified the path and it built without any issue as far as I could see. As for upload, I modified the avrdude command a little and I get this
/Users/mlalonde/Applications/Development/Arduino/arduino-0009/tools/avr/bin/avrdude -C /Users/mlalonde/Applications/Development/Arduino/arduino-0009/tools/avr/etc/avrdude.conf -F -p atmega168 -P /dev/tty.usbserial* -c stk500 -b 19200 -U flash:w:ntsc.hex
avrdude: stk500_getsync(): not in sync: resp=0x30
avrdude: stk500_2_ReceiveMessage(): timeout
If the Makefiles become a reliable way of building outside the IDE, I'm not sure there is a real need for a command line tool.
Ok, forgett what I said about cmake. It’s just another beast as automake/autoconfig…
xSmurf, your’ right. We actualy don’t need a java comand line when a proper makefile exists.
Last night I decided not to sleep and came up with this:
- An improved makefile, which features the same auto reset feature which the arduino IDE does on Diecimila boards. I found out, that avrdude supports to toggle the DTR line…
- The Makefile also allows to compile and work with standard .pde files directly. I does automatic preprocessing by simple shell commands. No additions to standard .pde files are needed… at least with led_blink works like a charm!
- I made a small addition to textmate’s standard Makefile Bundle. You have now command-R for compiling and command-U for upload. Just as in the Arduino IDE.
- I upgraded an old Arduino Extreme V2 (atmega8 board) to auto-reset itself from the serial port, just like Diecimila boards can. It’s very easy but usefull and described in the makefile.
But there are also some things that need additional work and thoughts:
- As I compile and “preprocess” (this word is really to much for what happens in the makefile the .pde into a .cpp file, errors that arouse from compiling do refer to that new file. So if you click on an error in the nice Textmate info window, you will be redirected to this file, instead of your .pde file, where you actually wan’t to code.
- The Textmate info windows show output of compiling and uploading only at the end of each process. It would be nice to see everything right when it happens…
- I couldn’t test to include additional .c files. Should it be enough to have .h header files included at the top in the .pde (just like in the Arduino IDE)? Or does the makefile need extra knowledge. Probably putting the extra .c files in $SRC?
- things I missed so far…
Here’s the makefile and the extended TextMate Bundle:
I hope some find this usefull. I enjoy using it! Esp. with auto-reset, the programming is so amazing fast.
Regarding TextMate shortcut keys: Besides CMD-U and CMD-R remember CMD-W to close the compile and upload info windows. Also CMD-< and CMD-> is handy to cycle between all open TextMate windows.
Wow, very nice.
I had no idea that avrdude supported the reset automatically either (right now I'm doing it manually before calling avrdude). That's awesome, I'll have to try to incorporate it into the next version.
Do you mind if I include this, or a variant of it, in the next Arduino release?
Also, there is one more preprocessing step that the Arduino environment does, which is to automatically generate prototypes for your functions. It's a small thing, but it might sketches slightly incompatible between the Makefile and environment.
of corse you can do with it what you want. It's anyway just a patchwork between different makfiles I found.
You mean, there could be a problem if people don't create a protoype of a self written function before calling their function? I'm shure there is some regular expression for this... how do you filter the protoypes in java? Do you compare against a list of core funcions?
BTW: I think there is an error in the original makefile in targets/arduino:
I think the line that starts with "$(TARGET).elf:" should also depend on $(TARGET).cpp (in my Makefile it is
$(TARGET).pde). Othwerise it didn't recompile on my system if I changed something in $(TAGET).cpp.
Re: avrdude reset. This was a funny discovery. I saw the reset definition for serial bitbangers and thought "hmmm, wait a minute..." ;). The reset line is held low during the whole upload process. Thats OK, when we use a capacitor for the connection just as in the Diecimila boards.
I tested is also with another - rather unusual - usb-serial converter from Silabs (CP2102). It works niceley! So this shouldn't depend on FDTI or other converters.
The automatic prototype generation works with a simple regular expression to try to detect function definitions, and then just ignores setup() and loop(). It doesn't work all that well (it gets confused if your return type is multiple words like "unsigned int" or is on a different line than the rest of your function header). Still, it's been okay for most things.
In fact, here it is:
There is cproto (http://cproto.sourceforge.net/) which will generate prototypes for you.
I guess you COULD create a makefile that would do all that the arduino program does. You'd have rules like:
cproto %.cpp >%.cpph
%.elf: %.cpp %.cpph
$(GCC) -I$(ARDUINOINC)/prefix.h -I%.cpph %.cpp ...
(that's probably WAY wrong. I HATE makefiles. make is a lovely example of a 1970s program that should have been replaced long ago instead of patching it to handle modern circumstances. A good percentage of Arduinos goodness probably comes from letting the user never have to deal with makefiles!)
Well i'm not after a substitution of the current java compile with a makefile. I just like to keep an alternative, when not working with the IDE.
It's not that I like makefiles, but for microcontroller programming is still not too hard to use it - IMHO.
Although I frequently forget important makefile knowledge... :-)
Speaking of it, i think there is a dependency erro in my makefile. Did anybody try it?
Cproto is interesting, thanks! Maybe mellis will use it in the IDE?
But as long as it's not a standard install on unix systems I wouldn't want to use it in a makefile.
On the other hand I think using a makefile, even if it's only in the background of an IDE, is a better standard than doing some custom java-based compile process in the IDE, like it's now. Esp. for maintainance between different IDE versions a certain compile standard could be better...
Of coruse, I agree that the Ardunio goodness comes with the current software and IDE!
But I think it's also good, that the Ardunio IDE doesn't allow too much simplification of C code.
I think the current state of preprocessing is a perfect compromise.
I hope it won't walk away any further from standard avr-gcc C code. Incorporating an alternative language than C, though, would be again a different question. E.g. ruby arduino developement: http://rad.rubyforge.org/
Using Makefiles as a backend from the IDE sounds good, but it was a nightmare in practice (we did it in the original versions of Arduino). Especially on Windows, it was impossible to get working consistently - some machines seemed to want / as the path separator, some wanted \ and some wanted \. We had to maintain multiple slightly different makefile version.
It was also difficult for people to make changes to the build process, because they'd get thrown by the common Makefile problem (like using spaces instead of tabs, etc.) Now, with the preferences file, there aren't many things you can change, but they are relatively easy. We could just pass all the variables on to the makefiles, but at this point there are some decisions being made that we be a pain to replicate in makefiles.
I kind of like the idea that the IDE does it's own thing, but we also provide a Makefile for people who want one.
It would be good to have a better way to generate function prototypes, but it's also a hassle to include another program, and so far, the current method seems to be "good enough".
Of course, these are all interesting ideas, and I appreciate the discussion.
I fully understand this. Maybe cmake is worth a try... Though cmake would add many more MBs.
I forgot one thing that's really great about using a makefile now:
You can have your preferences saved with the projects.
E.g. on some boards you prefer to use the bootloader while with others you're setup requires an AVRISP MKII - in any case you just set it once. Esp. ATmega8 vs. ATmega168 switching becomes obsolete! I guess some catch this problem often nowadays when having diecimila and older boards around at the same time. Also you can have different clock speeds and baudrates without changing preferences everytime you switch projects etc...
Yes, this is rather advanced stuff, but it's nice beeing still able to do it with a makefile - just as you said, david. I agree, as long as prototype creation works most of the time, better don't touch it...