Skip to content

Commit 28ffe07

Browse files
committed
Try different build strategy
1 parent 28b575e commit 28ffe07

File tree

17 files changed

+496
-16
lines changed

17 files changed

+496
-16
lines changed

builder/main.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,25 +226,18 @@ def generate_uf2(target, source, env):
226226
)
227227

228228
is_arduino_pico_build = env.BoardConfig().get("build.core", "arduino") == "earlephilhower" and "arduino" in env.get("PIOFRAMEWORK")
229-
target_gen_header = None
230229
if is_arduino_pico_build:
231230
pubkey = join(env.subst("$PROJECT_SRC_DIR"), "public.key")
232231
if isfile(pubkey):
233232
header_file = join(env.subst("$BUILD_DIR"), "core", "Updater_Signing.h")
234-
env.Prepend(CFLAGS=['-I"%s"' % join("$BUILD_DIR", "core")])
235-
signing_header_cmd = env.Command(
236-
join("$BUILD_DIR", "core", "Updater_Signing.h"), # $TARGET
237-
join("$PROJECT_SRC_DIR", "public.key"), # $SOURCE
238-
env.VerboseAction(" ".join([
233+
env.Prepend(CCFLAGS=['-I"%s"' % join("$BUILD_DIR", "core")])
234+
env.Execute(" ".join([
239235
'"$PYTHONEXE" "%s"' % join(
240236
platform.get_package_dir("framework-arduinopico"), "tools", "signing.py"),
241237
"--mode", "header",
242-
"--publickey", '"$SOURCE"',
243-
"--out", "$TARGET"
244-
]), "Generating $TARGET")
245-
)
246-
target_gen_header = env.Alias("gen_header", signing_header_cmd)
247-
AlwaysBuild(target_gen_header)
238+
"--publickey", '"%s"' % join("$PROJECT_SRC_DIR", "public.key"),
239+
"--out", '"%s"' % join("$BUILD_DIR", "core", "Updater_Signing.h")
240+
]))
248241

249242
#
250243
# Target: Build executable and linkable firmware
@@ -526,7 +519,4 @@ def _jlink_cmd_script(env, source):
526519
#
527520
# Default targets
528521
#
529-
if target_gen_header is not None:
530-
Default([target_gen_header, target_buildprog, target_size])
531-
else:
532-
Default([target_buildprog, target_size])
522+
Default([target_buildprog, target_size])

examples/arduino-ota/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.pio

examples/arduino-ota/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
How to build PlatformIO based project
2+
=====================================
3+
4+
1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html)
5+
2. Download [development platform with examples](https://github.com/platformio/platform-raspberrypi/archive/develop.zip)
6+
3. Extract ZIP archive
7+
4. Run these commands:
8+
9+
```shell
10+
# Change directory to example
11+
$ cd platform-raspberrypi/examples/arduino-blink
12+
13+
# Build project
14+
$ pio run
15+
16+
# Upload firmware
17+
$ pio run --target upload
18+
19+
# Clean build files
20+
$ pio run --target clean
21+
```
22+
23+
## Notes
24+
25+
For Raspberry Pi Pico devices, two Arduino cores exist:
26+
* https://github.com/arduino/ArduinoCore-mbed
27+
* https://github.com/earlephilhower/arduino-pico
28+
29+
This examples showcases how to use both of these cores in the `platformio.ini`.

examples/arduino-ota/include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

examples/arduino-ota/lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

examples/arduino-ota/platformio.ini

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter, extra scripting
4+
; Upload options: custom port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
;
7+
; Please visit documentation for the other options and examples
8+
; https://docs.platformio.org/page/projectconf.html
9+
10+
[env]
11+
platform = raspberrypi
12+
framework = arduino
13+
14+
; upload via USB
15+
[env:rpipicow_via_usb]
16+
board = rpipicow
17+
upload_protocol = mbed
18+
19+
; upload via OTA (change IP)
20+
[env:rpipicow_via_ota]
21+
board = rpipicow
22+
upload_protocol = espota
23+
upload_port = 192.168.0.206

examples/arduino-ota/src/main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <ESP8266WiFi.h>
2+
#include <ESP8266mDNS.h>
3+
#include <WiFiUdp.h>
4+
#include <ArduinoOTA.h>
5+
#include "Updater_Signing.h"
6+
7+
#ifndef STASSID
8+
#define STASSID "YourSSID"
9+
#define STAPSK "YourPassword"
10+
#endif
11+
12+
const char* ssid = STASSID;
13+
const char* password = STAPSK;
14+
15+
void setup() {
16+
Serial.begin(115200);
17+
Serial.println("Booting");
18+
WiFi.mode(WIFI_STA);
19+
WiFi.begin(ssid, password);
20+
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
21+
Serial.println("Connection Failed! Rebooting...");
22+
delay(5000);
23+
rp2040.restart();
24+
}
25+
26+
// Port defaults to 8266
27+
// ArduinoOTA.setPort(8266);
28+
29+
// Hostname defaults to esp8266-[ChipID]
30+
// ArduinoOTA.setHostname("myesp8266");
31+
32+
// No authentication by default
33+
// ArduinoOTA.setPassword("admin");
34+
35+
// Password can be set with it's md5 value as well
36+
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
37+
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
38+
39+
ArduinoOTA.onStart([]() {
40+
String type;
41+
if (ArduinoOTA.getCommand() == U_FLASH) {
42+
type = "sketch";
43+
} else { // U_FS
44+
type = "filesystem";
45+
}
46+
47+
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
48+
Serial.println("Start updating " + type);
49+
});
50+
ArduinoOTA.onEnd([]() {
51+
Serial.println("\nEnd");
52+
});
53+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
54+
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
55+
});
56+
ArduinoOTA.onError([](ota_error_t error) {
57+
Serial.printf("Error[%u]: ", error);
58+
if (error == OTA_AUTH_ERROR) {
59+
Serial.println("Auth Failed");
60+
} else if (error == OTA_BEGIN_ERROR) {
61+
Serial.println("Begin Failed");
62+
} else if (error == OTA_CONNECT_ERROR) {
63+
Serial.println("Connect Failed");
64+
} else if (error == OTA_RECEIVE_ERROR) {
65+
Serial.println("Receive Failed");
66+
} else if (error == OTA_END_ERROR) {
67+
Serial.println("End Failed");
68+
}
69+
});
70+
ArduinoOTA.begin();
71+
Serial.println("Ready");
72+
Serial.print("IP address: ");
73+
Serial.println(WiFi.localIP());
74+
}
75+
76+
void loop() {
77+
ArduinoOTA.handle();
78+
}

examples/arduino-ota/test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.pio

examples/arduino-signed-ota/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
How to build PlatformIO based project
2+
=====================================
3+
4+
1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html)
5+
2. Download [development platform with examples](https://github.com/platformio/platform-raspberrypi/archive/develop.zip)
6+
3. Extract ZIP archive
7+
4. Run these commands:
8+
9+
```shell
10+
# Change directory to example
11+
$ cd platform-raspberrypi/examples/arduino-blink
12+
13+
# Build project
14+
$ pio run
15+
16+
# Upload firmware
17+
$ pio run --target upload
18+
19+
# Clean build files
20+
$ pio run --target clean
21+
```
22+
23+
## Notes
24+
25+
For Raspberry Pi Pico devices, two Arduino cores exist:
26+
* https://github.com/arduino/ArduinoCore-mbed
27+
* https://github.com/earlephilhower/arduino-pico
28+
29+
This examples showcases how to use both of these cores in the `platformio.ini`.

0 commit comments

Comments
 (0)