Hacking.BuildProcess History

Show minor edits - Show changes to markup

November 20, 2012, at 11:19 PM by Roberto Guido - correction about headers, thanks to George Ganoe
Changed lines 15-16 from:

First, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.

to:

First, #include "Arduino.h", or for versions less than 1.0, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.

March 30, 2008, at 06:30 PM by David A. Mellis - updating for the changes in arduino 0011.
Changed lines 15-18 from:

First, any #include statements in the main sketch file are moved to the top of the code. Then #include "WProgram.h" is added to the above them. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.

Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to the top of your sketch. Note that these prototypes will appear before any type declarations or #include statements in your code, meaning that they cannot contain references to custom types.

to:

First, #include "WProgram.h" is added to the top of your sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.

Next, the environment searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted after any comments or pre-processor statements (#includes or #defines), but before any other statements (including type declarations). This means that if you want to use a custom type as a function argument, you should declare it within a separate header file. Also, this generation isn't perfect: it won't create prototypes for functions that have default argument values, or which are declared within a namespace or class.

December 21, 2007, at 04:46 PM by David A. Mellis -
Changed lines 23-24 from:

The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:

to:

The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:

December 21, 2007, at 04:45 PM by David A. Mellis -
Changed lines 15-18 from:

First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.

Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to your sketch.

to:

First, any #include statements in the main sketch file are moved to the top of the code. Then #include "WProgram.h" is added to the above them. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.

Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to the top of your sketch. Note that these prototypes will appear before any type declarations or #include statements in your code, meaning that they cannot contain references to custom types.

October 22, 2007, at 07:00 PM by David A. Mellis - updating for arduino 0010
Changed lines 15-16 from:

First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/lib/targets/<TARGET>/) includes all the header files needed for the standard Arduino core.

to:

First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the header files needed for the standard Arduino core.

Changed lines 19-20 from:

Finally, as of Arduino 0008, the contents of the current target's main.cxx file are appended to the bottom of your sketch.

to:

Finally, the contents of the current target's main.cxx file are appended to the bottom of your sketch.

Changed lines 23-24 from:

The Arduino environment supports multiple target boards with different chips (currently, only AVRs) or CPU speeds. To configure it for a target, you need to edit the main Arduino preferences file. Relevant variables include:

to:

The Arduino environment supports multiple target boards with different chips (currently, only AVRs), CPU speeds, or bootloaders. These are defined in a board preferences file. Relevant variables include:

<BOARD>.name: the name to display in the Boards menu

<BOARD>.build.mcu: the microcontroller on the board (normally "atmega8" or "atmega168").

<BOARD>.f_cpu: the clock speed at which the microcontroller operates (normally "16000000L", or, for an ATmega168 running on its internal clock, "8000000L").

<BOARD>.core: which sub-directory of the hardware/cores/ directory to link sketches against (normally "arduino").

Also useful is this setting in the main preferences.txt file:

Deleted lines 36-41:

build.target: a sub-directory of <ARDUINO>/lib/targets/ (e.g. "arduino") - sketches will be linked against all .c/.cpp/.o files in this directory.

build.mcu: the microcontroller (e.g. "atmega8").

build.f_cpu: the clock speed (e.g. "16000000L"). Used to define the F_CPU constant when compiling.

Changed lines 43-44 from:

The include path includes the sketch's directory, the target directory (<ARDUINO>/lib/targets/<TARGET>/) and the avr include directory (<ARDUINO>/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/lib/targets/libraries/) which contain a header file which is included by the main sketch file.

to:

The include path includes the sketch's directory, the target directory (<ARDUINO>/hardware/core/<CORE>/) and the avr include directory (<ARDUINO>/hardware/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/hardware/libraries/) which contain a header file which is included by the main sketch file.

Changed lines 49-50 from:

As of Arduino 0008, these .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.

to:

These .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.

Changed lines 55-56 from:

Sketches are uploaded by uisp. The upload process is also controlled by variables in the preferences file. These include:

to:

Sketches are uploaded by avrdude.

The upload process is also controlled by variables in the boards and main preferences files. Those in the boards file include:

<BOARD>.upload.protocol: the protocol that avrdude should use to talk to the board (typically "stk500").

<BOARD>.upload.speed: the speed (baud rate) avrdude should use when uploading sketches (typically "19200").

<BOARD>.upload.maximum_size: the maximum size for a sketch on the board (dependent on the chip and the size of the bootloader).

And in the main preferences file:

Deleted lines 67-84:

upload.programmer: the protocol used for upload. the bootloader on the Arduino board uses "stk500", but some external programmers may use others.

upload.erase: whether or not to erase the board before uploading. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.

upload.verify: whether or not to verify the success of the upload. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.

upload.maximum_size: the maximum size of the compiled sketch in bytes; anything bigger will result in an error when you attempt to upload. On the Arduino board, this is 7168 as the ATmega8 has 8 Kb of program space, with 1 Kb taken by the bootloader. If using another chip or an external programmer (and thus, no bootloader), you'll want to adjust this accordingly.

serial.download_rate: the baud rate at which programs are upload. Should be "19200" on current Arduino boards; some older boards use "9600". Should be "115200" for an external AVR-ISP.

The actual command line call to uisp might end up looking something like this:

tools/avr/bin/uisp -dpart=atmega8 -dprog=stk500 -dserial=/dev/cu.usbserial-A1000fKl -dspeed=19200 --upload if=/Users/dmellis/Documents/Arduino/led_blink/applet/led_blink.hex

Compiling straight .c or .cpp files

You'll need to create a blank target. Make a directory called "blank" in <ARDUINO>/lib/targets/. Create a blank file called "WProgram.h". You may need to put the .c or .cpp file in an auxilary tab of your sketch (leaving the primary tab blank). You won't be able to use any of the Arduino functions unless you copy the corresponding files from <ARDUINO>/lib/targets/arduino.

August 07, 2007, at 08:39 PM by David A. Mellis -
Changed lines 47-48 from:

The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or ... (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).

to:

The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or \Documents and Settings\<USER>\Local Settings\Temp (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).

August 07, 2007, at 08:33 PM by David A. Mellis -
Changed lines 47-48 from:

The .hex file is the final output of the compilation which is then uploaded to the board.

to:

The .hex file is the final output of the compilation which is then uploaded to the board. During a "Verify" the .hex file is written to /tmp (on Mac and Linux) or ... (on Windows). During upload, it's written to the applet sub-directory of the sketch directory (which you can open with the "Show Sketch Folder" item in the Sketch menu).

June 12, 2007, at 06:34 AM by David A. Mellis - updating for changes to arduino 0008
Added lines 19-20:

Finally, as of Arduino 0008, the contents of the current target's main.cxx file are appended to the bottom of your sketch.

Added lines 45-46:

As of Arduino 0008, these .o files are then linked together into a static library and the main sketch file is linked against this library. Only the parts of the library needed for your sketch are included in the final .hex file, reducing the size of most sketches.

January 27, 2007, at 02:55 PM by David A. Mellis -
Deleted lines 2-3:

Warning: this may all change in future releases of Arduino.

December 21, 2006, at 06:47 PM by David A. Mellis -
Added lines 25-26:

build.verbose: whether or not to print debugging messages while building a sketch (e.g. "false"). If true, will print the complete command line of each external command executed as part of the build process.

Added lines 51-52:

upload.verbose: whether or not to dump debugging messages while upload a sketch to a board (defaults to "false").

November 05, 2006, at 04:57 PM by David A. Mellis -
Changed lines 1-2 from:

Arduino build process

to:

Arduino Build Process

Changed lines 5-6 from:

Overview

to:

Overview

Changed lines 9-10 from:

Multi-file sketches

to:

Multi-file sketches

November 05, 2006, at 04:56 PM by David A. Mellis -
Added lines 1-65:

Arduino build process

Warning: this may all change in future releases of Arduino.

Overview

A number of things have to happen for your Arduino code to get onto the Arduino board. First, the Arduino environment performs some small transformations to make sure that the code is correct C or C++ (two common programming languages). It then gets passed to a compiler (avr-gcc), which turns the human readable code into machine readable instructions (or object files). Then, your code gets combined with (linked against), the standard Arduino libraries that provide basic functions like digitalWrite() or Serial.print(). The result is a single Intel hex file, which contains the specific bytes that need to be written to the program memory of the chip on the Arduino board. This file is then uploaded to the board: transmitted over the USB or serial connection via the bootloader already on the chip or with external programming hardware.

Multi-file sketches

A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the "main sketch file". Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using "double quotes" not <angle brackets>).

Transformations to the main sketch file

The Arduino environment performs a few transformations to your main sketch file (the concatenation of all the tabs in the sketch without extensions) before passing it to the avr-gcc compiler.

First, #include "WProgram.h" is added to the top of the sketch. This header file (found in <ARDUINO>/lib/targets/<TARGET>/) includes all the header files needed for the standard Arduino core.

Next, the environment searches for function definitions within your main sketch file and prepends declarations (prototypes) for them to your sketch.

Targets

The Arduino environment supports multiple target boards with different chips (currently, only AVRs) or CPU speeds. To configure it for a target, you need to edit the main Arduino preferences file. Relevant variables include:

build.target: a sub-directory of <ARDUINO>/lib/targets/ (e.g. "arduino") - sketches will be linked against all .c/.cpp/.o files in this directory.

build.mcu: the microcontroller (e.g. "atmega8").

build.f_cpu: the clock speed (e.g. "16000000L"). Used to define the F_CPU constant when compiling.

Note: that in Arduino 0004 and later, build.extension is unused - the main sketch file is always treated as a .cpp file.

Build process

Sketches are compiled by avr-gcc.

The include path includes the sketch's directory, the target directory (<ARDUINO>/lib/targets/<TARGET>/) and the avr include directory (<ARDUINO>/tools/avr/avr/include/), as well as any library directories (in <ARDUINO>/lib/targets/libraries/) which contain a header file which is included by the main sketch file.

When you verify a sketch, it is built in a temporary directory in the system temp directory (e.g. /tmp on the Mac). When you upload it, it is built in the applet/ subdirectory of the sketch's directory (which you can access with the "Show Sketch Folder" item in the "Sketch" menu).

The .c and .cpp files of the target are compiled and output with .o extensions to this directory, as is the main sketch file and any other .c or .cpp files in the sketch and any .c or .cpp files in any libraries which are #included in the sketch.

The .hex file is the final output of the compilation which is then uploaded to the board.

Upload process

Sketches are uploaded by uisp. The upload process is also controlled by variables in the preferences file. These include:

upload.programmer: the protocol used for upload. the bootloader on the Arduino board uses "stk500", but some external programmers may use others.

upload.erase: whether or not to erase the board before uploading. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.

upload.verify: whether or not to verify the success of the upload. Needs to be "false" when uploading normally with the bootloader, but can be set to "true" when using an external ISP.

upload.maximum_size: the maximum size of the compiled sketch in bytes; anything bigger will result in an error when you attempt to upload. On the Arduino board, this is 7168 as the ATmega8 has 8 Kb of program space, with 1 Kb taken by the bootloader. If using another chip or an external programmer (and thus, no bootloader), you'll want to adjust this accordingly.

serial.download_rate: the baud rate at which programs are upload. Should be "19200" on current Arduino boards; some older boards use "9600". Should be "115200" for an external AVR-ISP.

The actual command line call to uisp might end up looking something like this:

tools/avr/bin/uisp -dpart=atmega8 -dprog=stk500 -dserial=/dev/cu.usbserial-A1000fKl -dspeed=19200 --upload if=/Users/dmellis/Documents/Arduino/led_blink/applet/led_blink.hex

Compiling straight .c or .cpp files

You'll need to create a blank target. Make a directory called "blank" in <ARDUINO>/lib/targets/. Create a blank file called "WProgram.h". You may need to put the .c or .cpp file in an auxilary tab of your sketch (leaving the primary tab blank). You won't be able to use any of the Arduino functions unless you copy the corresponding files from <ARDUINO>/lib/targets/arduino.

Share