Skip to content

Commit 7ef28a8

Browse files
Write sketch commands (#2)
* import sketches from https://github.com/arduino-libraries/WiFiNINA/tree/master/examples/Tools * create a single sketch * add compiled `.bin` files --------- Co-authored-by: Umberto Baldi <[email protected]>
1 parent 3d3e3a9 commit 7ef28a8

File tree

8 files changed

+184
-0
lines changed

8 files changed

+184
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,10 @@ venv
4242
# Delve debugger binary file
4343
__debug_bin
4444

45+
# build sketches files
46+
/sketches/commands/build/**/*.elf
47+
/sketches/commands/build/**/*.hex
48+
/sketches/commands/build/**/*.map
49+
/sketches/commands/build/**/*.uf2
50+
/sketches/commands/build/**/*.eep
51+
/sketches/commands/build/**/*bootloader.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

sketches/commands/commands.ino

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// This file is part of nina-fwuploader-plugin.
2+
//
3+
// Copyright (c) 2023 Arduino LLC. All right reserved.
4+
//
5+
// This program is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Affero General Public License as published
7+
// by the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// This program is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Affero General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Affero General Public License
16+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
18+
// To generate the binaries run:
19+
// arduino-cli compile -e --profile <profile_name>
20+
21+
#include <SPI.h>
22+
#include <WiFiNINA.h>
23+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
24+
#include <VidorPeripherals.h>
25+
26+
unsigned long baud = 119400;
27+
#else
28+
unsigned long baud = 115200;
29+
#endif
30+
31+
int rts = -1;
32+
int dtr = -1;
33+
34+
void setup(){
35+
Serial.begin(baud);
36+
SerialNina.begin(baud);
37+
38+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
39+
FPGA.begin();
40+
#endif
41+
42+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
43+
FPGA.pinMode(FPGA_NINA_GPIO0, OUTPUT);
44+
FPGA.pinMode(FPGA_SPIWIFI_RESET, OUTPUT);
45+
#else
46+
pinMode(NINA_GPIO0, OUTPUT);
47+
pinMode(NINA_RESETN, OUTPUT);
48+
#endif
49+
while(true) {
50+
if (Serial.available()){
51+
char choice = Serial.read();
52+
switch (choice){
53+
case 'r':
54+
restartPassthrough();
55+
return;
56+
case 'v':
57+
version();
58+
return;
59+
default:
60+
return;
61+
}
62+
}
63+
}
64+
}
65+
66+
void restartPassthrough(){
67+
#ifdef ARDUINO_AVR_UNO_WIFI_REV2
68+
// manually put the NINA in upload mode
69+
digitalWrite(NINA_GPIO0, LOW);
70+
digitalWrite(NINA_RESETN, LOW);
71+
delay(100);
72+
digitalWrite(NINA_RESETN, HIGH);
73+
delay(100);
74+
digitalWrite(NINA_RESETN, LOW);
75+
#endif
76+
while (true) {
77+
#ifndef ARDUINO_AVR_UNO_WIFI_REV2
78+
if (rts != Serial.rts()) {
79+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
80+
FPGA.digitalWrite(FPGA_SPIWIFI_RESET, (Serial.rts() == 1) ? LOW : HIGH);
81+
#elif defined(ARDUINO_SAMD_NANO_33_IOT)
82+
digitalWrite(NINA_RESETN, Serial.rts() ? LOW : HIGH);
83+
#else
84+
digitalWrite(NINA_RESETN, Serial.rts());
85+
#endif
86+
rts = Serial.rts();
87+
}
88+
89+
if (dtr != Serial.dtr()) {
90+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
91+
FPGA.digitalWrite(FPGA_NINA_GPIO0, (Serial.dtr() == 1) ? HIGH : LOW);
92+
#else
93+
digitalWrite(NINA_GPIO0, (Serial.dtr() == 0) ? HIGH : LOW);
94+
#endif
95+
dtr = Serial.dtr();
96+
}
97+
#endif
98+
99+
if (Serial.available()){
100+
SerialNina.write(Serial.read());
101+
}
102+
103+
if (SerialNina.available()) {
104+
Serial.write(SerialNina.read());
105+
}
106+
107+
#ifndef ARDUINO_AVR_UNO_WIFI_REV2
108+
// check if the USB virtual serial wants a new baud rate
109+
if (Serial.baud() != baud) {
110+
rts = -1;
111+
dtr = -1;
112+
113+
baud = Serial.baud();
114+
#ifndef ARDUINO_SAMD_MKRVIDOR4000
115+
SerialNina.begin(baud);
116+
#endif
117+
}
118+
#endif
119+
}
120+
}
121+
122+
void version(){
123+
// Print a welcome message
124+
Serial.println("WiFiNINA firmware check.");
125+
Serial.println();
126+
127+
// check for the WiFi module:
128+
if (WiFi.status() == WL_NO_MODULE) {
129+
Serial.println("Communication with WiFi module failed!");
130+
// don't continue
131+
while (true);
132+
}
133+
134+
// Print firmware version on the module
135+
String fv = WiFi.firmwareVersion();
136+
Serial.print("Firmware version installed: ");
137+
Serial.println(fv);
138+
}
139+
140+
void loop() {
141+
}

sketches/commands/sketch.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
profiles:
2+
mkrwifi1010:
3+
fqbn: arduino:samd:mkrwifi1010
4+
platforms:
5+
- platform: arduino:samd (1.8.13)
6+
libraries:
7+
- WiFiNINA (1.8.14)
8+
9+
nano_33_iot:
10+
fqbn: arduino:samd:nano_33_iot
11+
platforms:
12+
- platform: arduino:samd (1.8.13)
13+
libraries:
14+
- WiFiNINA (1.8.14)
15+
16+
mkrvidor4000:
17+
fqbn: arduino:samd:mkrvidor4000
18+
platforms:
19+
- platform: arduino:samd (1.8.13)
20+
libraries:
21+
- WiFiNINA (1.8.14)
22+
- VidorPeripherals (1.1.0)
23+
24+
uno2018:
25+
fqbn: arduino:megaavr:uno2018
26+
platforms:
27+
- platform: arduino:megaavr (1.8.8)
28+
libraries:
29+
- WiFiNINA (1.8.14)
30+
31+
nanorp2040connect:
32+
fqbn: arduino:mbed_nano:nanorp2040connect
33+
platforms:
34+
- platform: arduino:mbed_nano (4.0.4)
35+
libraries:
36+
- WiFiNINA (1.8.14)

0 commit comments

Comments
 (0)