Dumb questions about Arduino/Teensyduino IDE

Status
Not open for further replies.

TelephoneBill

Well-known member
I have used the Arduino IDE a number of times, but some aspects of it are puzzling. Maybe a few DUMB questions or statements (probably misguided) can shed some light? Paul is very occupied at this time, so any other expert comment would be much appreciated...

1) It seems that the code that is actually downloaded to Teensy boards is a bit more than just the "Sketch Source Code" which I write with the editor. So I'm guessing that some "Pre-amble Code" is added to my sketch automatically before being downloaded? If true then exactly how does this work? Let me assume this to be so...

2) Before I start writing "Sketch Source Code", I have to select items from the drop down menus (Tools) etc, such as the actual board that I'm using, the CPU speed and maybe some more stuff. How does this influence the "Pre-amble Code"? My guess here is that before the compiler runs, some additional .h header files are added to my source code - but these are not visible to me as a user on screen. Is this what happens?

3) If I were compiling in a DOS window environment, then a number of "Switches" would be included in the command line that I would type. Maybe this is how some of the "choices" from the menus are actioned? Perhaps the Arduino IDE GUI is really building a "command line" for me, and parsing my choices to include in the final "command line" that actually is submitted "under the hood"?

4) The most comprehensive way to prepare "Sketch Source Code" for compilation would be to automatically create a MAKE FILE, which I know is just a text file, but contains everything that I would have typed anyway. Perhaps the Arduino IDE GUI is another way to automatically create a MAKE FILE for me?

===

5) Looking at the Sketch Source Code I can write, there are a number of "register names" (are these called literals?) that I can use without defining these myself e.g. PORTC_PCR5. The compiler never objects (well usually never) and I know that these are all defined in a file that Paul publishes (and updates regularly for new boards) on GitHub called "Kinetis.h". So my guess is that this file is one of the .h header files that is automatically added to my source code. Is this correct?

6) The Kinetis.h file has an opening comment "Teensy Core Library". So are these the same thing (these terms interchangeable) - or is there more to the "core library" than just this one file?

7) I notice that some define statements in "Kinetis.h" refer to other "literals" not defined in that file, e.g. F_CPU. This is used as a test (if (F_CPU == 240000000)) so it tells me this is the speed of the CPU (F = frequency), which is one of the other selections from the Tools drop down menu. My guess here is that by making the speed choice from the menu, then another .h header is created, which is probably very small and precedes the Kinetis.h file when/if the MAKE file is created ???

===

Last query/puzzle...

8) There are lots of library files available for Teensy boards. I can download these from the PJRC website - or even make my own. I can put these files into any folder I choose on the PC, providing the PATH is specified, but is there a "standard folder" within the Arduino IDE where I should put these? Can I then just refer to these by name in my sketch rather than having to specify the PATH?

Thanks in advance for any guidance.
 
I will take a shot at some of these.

First maybe read up some in places like: https://www.arduino.cc/en/Hacking/BuildProcess

Don't know what system you are installing on. But example windows. On my machine current Arduino is installed at: C:\arduino-1.6.11
So when Teenysduino installs, most of the files go into C:\arduino-1.6.11\hardware\teensy. All of the main code for Teensy 3 goes into: C:\arduino-1.6.11\hardware\teensy\avr\cores\teensy3

The Arduino environment, takes all of the .ino files that are part of your sketch and more or less messages them into a standard C/C++ file. Note Arduino is already more or less standard c++, but it tries to take care of things like forward references and setting up your main. In fact the code for the standard main is at: C:\arduino-1.6.11\hardware\teensy\avr\cores\teensy3\main.cpp

In there you will find:
Code:
#include "WProgram.h"

extern "C" int main(void)
{

	// Arduino's main() function just calls setup() and loop()....
	setup();
	while (1) {
		loop();
		yield();
	}
}
Note I removed some stuff out of #ifdef, to show that main simply calls the setup function you define in your main INO file and then loops calling your loop() function from the INO. It also includes WProgram.h, which is where your program picks up all of the #defines that are used.

2) Selecting the board, influences lots of things, including what compiler and the like that will be used. The Arduino IDE software takes the information out of the files, to generate the list as well as grab the appropriate information. For the Teensy, most of the information is in the files boards.txt and platform.txt that is located at: C:\arduino-1.6.11\hardware\teensy\avr

3) When you actually do a build (verify or download), the Arduino control program does run the appropriate compiler and yes passes a lot of the options through command line options.
If you wish to get an idea of what all goes onto the command line. Go into the Arduino ide. Go to file menu and choose preferences menu item. Then click on the box labeled something like:
Show verbose output during compilation and OK out. Now try a simple build:

You will now see what all gets built. It will include the stuff from your INO file(s), plus any .cpp files you include into your sketch, plus it will compile all of the .c/cpp files in the Teensy Core3 directory, plus any source files associated with any libraries that you have included into your program.

4) The Arduino system has it's own stuff to control the build.

5) As I mentioned, the main above include "WProgram.h", which brings in tons of other include files. If you have any other source files either as part of your sketch or any library you include, they all typically now include <Arduino.h> which is the new name for WProrgram.h. This is again where most of the stuff is brought in. Obviously any library files you bring in, also have their header files, which bring in more stuff.

7) Some of these things get passed in to the command line, which reflect the options that you choose, like CPU speed, how you are using USB, ... Example of one compiled file:
Code:
"C:\arduino-1.6.11\hardware\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O -g -Wall -ffunction-sections -fdata-sections -nostdlib -MMD -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=130 -DARDUINO=10611 -DF_CPU=180000000 -DUSB_SERIAL -DLAYOUT_US_ENGLISH "-IC:\arduino-1.6.11\hardware\teensy\avr\cores\teensy3" "C:\arduino-1.6.11\hardware\teensy\avr\cores\teensy3\HardwareSerial5.cpp" -o "C:\Users\Kurt\AppData\Local\Temp\build59d318034a256da89fd52fbf7f26a1be.tmp\core\HardwareSerial5.cpp.o"

8) Include files - Big topic. There are rules on where Arduino will look for libraries. Lots of details out there including:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification

By default: you put your libraries into where your sketch folder is defined in a sub directory libraries. So on my windows machine there are at: C:\Users\Kurt\Documents\Arduino\libraries

The Arduino ide when it launches will scan this folder (as well as others that are part of the IDE or part of the hardware, in my cases for Teensy, places like:
C:\arduino-1.6.11\libraries
C:\arduino-1.6.11\hardware\teensy\avr\libraries

There are some rules on if a library that has the same header file name is found in multiple locations, which one will be used. These rules have been changing. I believe current rule is the ones that are in your sketch folder win... Maybe depending on some other things...

When you include a library into your sketch, like: #include <ili9341_t3.h>
When you build, the build process will do a pass through the appropriate library folders to locate this header file and will add that location to the include search path. In earlier versions of the IDE, if that library needed some other library like SPI, your main program also had to know to include SPI: #include <SPI.h>
But I believe the current builds 1.6.10 and 11 now can pick up these dependencies and add those locations as well to the include search path.
...

Hope that helps
 
There is a set of Makefiles that emulate the Arduino IDE build process (Teensy is supported). That may be helpful in understanding what's going on behind the scenes:
https://github.com/sudar/Arduino-Makefile

The Arduino IDE doesn't use some standard build system. It directly invokes the compiler, linker, ...
 
A big thankyou for your responses. Plenty of meat to dig into... my start thread was even dumber than I originally thought... yes, I use a Win7 environment.

I think this info is going to be useful to other Arduino/Teensyduino newcomers too. Cheers.
 
Status
Not open for further replies.
Back
Top