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
+ }
0 commit comments