Skip to content

Commit 6c68810

Browse files
committed
accept .pde and .ino files as input for Arduino.mk
1 parent 4ffdced commit 6c68810

3 files changed

Lines changed: 102 additions & 2 deletions

File tree

docs/usage/build-cli.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.

docs/usage/build-ide.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Building with the Arduino IDE
2+
3+
Sduino now blends in smoothly with the Arduino IDE. Just choose a matching
4+
board type from the list of supported boards at Tools->Board and work as
5+
usual.
6+
7+
8+
- Open the Boards list at Tools->Board:...
9+
- You should find a new entry "STM8S Boards".
10+
- Choose *STM8S103F3 Breakout Board* from the list
11+
- Open the standard Blink example from File->Examples->01. Basics->Blink
12+
- Compile it by clickin 'Verify'
13+
- Or upload it to the connected board by clicking 'Upload'
14+
15+
Done! Your first STM8 based project is up and running!
16+
17+
But keep in mind that it still based on plain C and not 100% Arduino syntax.
18+
It is close enough, that even some of the stock example sketches work right
19+
out of the box, but others will require small modifications.
20+
21+
FIXME: How to access the Sduino adopted example sketches
22+

sduino/Arduino.mk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,16 @@ $(OBJDIR)/%.s.$(OBJSUFFIX): %.s $(COMMON_DEPS) | $(OBJDIR)
12621262
# the pde -> o file
12631263
$(OBJDIR)/%.pde.$(OBJSUFFIX): %.pde $(COMMON_DEPS) | $(OBJDIR)
12641264
@$(MKDIR) $(dir $@)
1265-
$(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
1265+
(echo '#include <Arduino.h>\n#line 1 "$<"'; cat $<) > "$(patsubst %.$(OBJSUFFIX),%.c,$@)"
1266+
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) "$(patsubst %.$(OBJSUFFIX),%.c,$@)" -o $@
1267+
# $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
12661268

12671269
# the ino -> o file
12681270
$(OBJDIR)/%.ino.$(OBJSUFFIX): %.ino $(COMMON_DEPS) | $(OBJDIR)
12691271
@$(MKDIR) $(dir $@)
1270-
$(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
1272+
(echo '#include <Arduino.h>\n#line 1 "$<"'; cat $<) > "$(patsubst %.$(OBJSUFFIX),%.c,$@)"
1273+
$(CC) "-Wp-MMD $(patsubst %.$(OBJSUFFIX),%.d,$@)" -c $(CPPFLAGS) $(CFLAGS) "$(patsubst %.$(OBJSUFFIX),%.c,$@)" -o $@
1274+
# $(CXX) -x c++ -include $(ARDUINO_HEADER) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
12711275

12721276
# generated assembly
12731277
$(OBJDIR)/%.s: %.pde $(COMMON_DEPS) | $(OBJDIR)

0 commit comments

Comments
 (0)