|
| 1 | +# Building with the Makefile |
| 2 | + |
| 3 | +A preconfigured IDE is a great way to start, but sooner or later you will |
| 4 | +want more control and flexibility. |
| 5 | + |
| 6 | +The [manual install](manual-install.md) of Sduino comes with an easy-to-use powerful |
| 7 | +Makefile based on the amazing [Arduino.mk |
| 8 | +makefile](https://github.com/sudar/Arduino-Makefile) by |
| 9 | +[Sudar](http://sudarmuthu.com>). |
| 10 | + |
| 11 | +Let's blink an LED using the Blink example from Arduino: |
| 12 | + |
| 13 | +```c |
| 14 | +/* |
| 15 | + Blink |
| 16 | + Turns on an LED on for one second, then off for one second, repeatedly. |
| 17 | +
|
| 18 | + This example code is in the public domain. |
| 19 | +*/ |
| 20 | + |
| 21 | +#include <Arduino.h> |
| 22 | + |
| 23 | +// Pin 13 has an LED connected on most Arduino boards. |
| 24 | +// Pin 3 for the STM8S103 break out board |
| 25 | +// give it a name: |
| 26 | +int led = LED_BUILTIN; |
| 27 | + |
| 28 | +// the setup routine runs once when you press reset: |
| 29 | +void setup() { |
| 30 | + // initialize the digital pin as an output. |
| 31 | + pinMode(led, OUTPUT); |
| 32 | +} |
| 33 | + |
| 34 | +// the loop routine runs over and over again forever: |
| 35 | +void loop() { |
| 36 | + digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) |
| 37 | + delay(1000); // wait for a second |
| 38 | + digitalWrite(led, LOW); // turn the LED off by making the voltage LOW |
| 39 | + delay(1000); // wait for a second |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +All we need for a full build is this very basic `Makefile` (adopt the path |
| 44 | +of the include statement for your situation): |
| 45 | + |
| 46 | +```make |
| 47 | +BOARD_TAG = stm8sblue |
| 48 | + |
| 49 | +include ../../sduino/sduino.mk |
| 50 | +``` |
| 51 | + |
| 52 | +Compile and upload it: |
| 53 | + |
| 54 | + make upload |
| 55 | + |
| 56 | +Done! Your first STM8 based project is up and running! |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +## Differences to using the IDE |
| 61 | + |
| 62 | +The Arduino IDE saves sketches as .ino or .pde files. These are basically |
| 63 | +C++ files, but without the need to `#include "Arduino.h"` and without the |
| 64 | +need to declare function prototypes. These elements are auto-generated by |
| 65 | +the `arduino-builder` tool at compile time. |
| 66 | + |
| 67 | +The Makefile has only very limited support of these features. If compiling a |
| 68 | +.pde or .ino file it prepends the source file with an `#include "Arduino.h"` |
| 69 | +line and tries to compile it as a C file. This is only useful, if your |
| 70 | +sketch is actually written in C. It doesn't magically converts C++ to C. |
| 71 | + |
| 72 | +The main purpose of this simple conversion is to allow compiling the same |
| 73 | +source file either with the Makefile or with the IDE as the IDE requires the |
| 74 | +main file to have an .ino extention. |
0 commit comments