Building with the Makefile
A preconfigured IDE is a great way to start, but sooner or later you will want more control and flexibility.
The manual install of Sduino comes with an easy-to-use powerful Makefile based on the amazing Arduino.mk makefile by Sudar.
Let's blink an LED using the Blink example from Arduino:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
#include <Arduino.h>
// Pin 13 has an LED connected on most Arduino boards.
// Pin 3 for the STM8S103 break out board
// give it a name:
int led = LED_BUILTIN;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
All we need for a full build is this very basic Makefile
(adopt the path
of the include statement for your situation):
BOARD_TAG = stm8sblue
include ../../sduino/sduino.mk
Compile and upload it:
make upload
Done! Your first STM8 based project is up and running!
Differences to using the IDE
The Arduino IDE saves sketches as .ino or .pde files. These are basically
C++ files, but without the need to #include "Arduino.h"
and without the
need to declare function prototypes. These elements are auto-generated by
the arduino-builder
tool at compile time.
The Makefile has only very limited support of these features. If compiling a
.pde or .ino file it prepends the source file with an #include "Arduino.h"
line and tries to compile it as a C file. This is only useful, if your
sketch is actually written in C. It doesn't magically converts C++ to C.
The main purpose of this simple conversion is to allow compiling the same source file either with the Makefile or with the IDE as the IDE requires the main file to have an .ino extention.