Skip to content

Commit 473bd7f

Browse files
committed
Add support for MKR VIdor 4000
1 parent 6fc3ebc commit 473bd7f

File tree

2 files changed

+88
-18
lines changed

2 files changed

+88
-18
lines changed

examples/Tools/FirmwareUpdater/ESP32BootROM.cpp

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
/*
2-
ESP32BootROM - part of the Firmware Updater for the
2+
ESP32BootROM - part of the Firmware Updater for the
33
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
4-
4+
55
Copyright (c) 2018 Arduino SA. All rights reserved.
6-
6+
77
This library is free software; you can redistribute it and/or
88
modify it under the terms of the GNU Lesser General Public
99
License as published by the Free Software Foundation; either
1010
version 2.1 of the License, or (at your option) any later version.
11-
11+
1212
This library is distributed in the hope that it will be useful,
1313
but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1515
Lesser General Public License for more details.
16-
16+
1717
You should have received a copy of the GNU Lesser General Public
1818
License along with this library; if not, write to the Free Software
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
23+
#include <VidorPeripherals.h>
24+
25+
#define NINA_GPIO0 FPGA_NINA_GPIO0
26+
#define NINA_RESETN FPGA_SPIWIFI_RESET
27+
#endif
28+
29+
2230
#include "ESP32BootROM.h"
2331

2432
ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int resetnPin) :
@@ -30,7 +38,25 @@ ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int r
3038
}
3139

3240
int ESP32BootROMClass::begin(unsigned long baudrate)
33-
{ pinMode(_gpio0Pin, OUTPUT);
41+
{
42+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
43+
FPGA.begin();
44+
45+
_serial->begin(119400);
46+
47+
FPGA.pinMode(_gpio0Pin, OUTPUT);
48+
FPGA.pinMode(_resetnPin, OUTPUT);
49+
50+
FPGA.digitalWrite(_gpio0Pin, LOW);
51+
52+
FPGA.digitalWrite(_resetnPin, LOW);
53+
delay(10);
54+
FPGA.digitalWrite(_resetnPin, HIGH);
55+
delay(100);
56+
#else
57+
_serial->begin(115200);
58+
59+
pinMode(_gpio0Pin, OUTPUT);
3460
pinMode(_resetnPin, OUTPUT);
3561

3662
digitalWrite(_gpio0Pin, LOW);
@@ -39,8 +65,7 @@ int ESP32BootROMClass::begin(unsigned long baudrate)
3965
delay(10);
4066
digitalWrite(_resetnPin, LOW);
4167
delay(100);
42-
43-
_serial->begin(115200);
68+
#endif
4469

4570
int synced = 0;
4671

@@ -52,6 +77,9 @@ int ESP32BootROMClass::begin(unsigned long baudrate)
5277
return 0;
5378
}
5479

80+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
81+
(void)baudrate;
82+
#else
5583
if (baudrate != 115200) {
5684
if (!changeBaudrate(baudrate)) {
5785
return 0;
@@ -62,6 +90,7 @@ int ESP32BootROMClass::begin(unsigned long baudrate)
6290
_serial->end();
6391
_serial->begin(baudrate);
6492
}
93+
#endif
6594

6695
if (!spiAttach()) {
6796
return 0;
@@ -209,7 +238,11 @@ void ESP32BootROMClass::command(int opcode, const void* data, uint16_t length)
209238
writeEscapedBytes((uint8_t*)&checksum, sizeof(checksum));
210239
writeEscapedBytes((uint8_t*)data, length);
211240
_serial->write(0xc0);
241+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
242+
// _serial->flush(); // doesn't work!
243+
#else
212244
_serial->flush();
245+
#endif
213246
}
214247

215248
int ESP32BootROMClass::response(int opcode, unsigned int timeout, void* body)
Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
SerialNINAPassthrough - Use esptool to flash the u-blox NINA (ESP32) module
33
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
4-
4+
55
Copyright (c) 2018 Arduino SA. All rights reserved.
66
77
This library is free software; you can redistribute it and/or
@@ -19,33 +19,70 @@
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
*/
2121

22+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
23+
#include <VidorPeripherals.h>
24+
25+
unsigned long baud = 119400;
26+
#else
2227
unsigned long baud = 115200;
28+
#endif
29+
30+
int rts = -1;
31+
int dtr = -1;
2332

2433
void setup() {
2534
SerialUSB.begin(baud);
35+
36+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
37+
FPGA.begin();
38+
#endif
39+
2640
SerialNina.begin(baud);
27-
41+
42+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
43+
FPGA.pinMode(FPGA_NINA_GPIO0, OUTPUT);
44+
FPGA.pinMode(FPGA_SPIWIFI_RESET, OUTPUT);
45+
#else
2846
pinMode(NINA_GPIO0, OUTPUT);
2947
pinMode(NINA_RESETN, OUTPUT);
48+
#endif
3049
}
3150

3251
void loop() {
33-
digitalWrite(NINA_RESETN, SerialUSB.rts());
34-
digitalWrite(NINA_GPIO0, (SerialUSB.dtr() == 0) ? HIGH : LOW);
52+
if (rts != SerialUSB.rts()) {
53+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
54+
FPGA.digitalWrite(FPGA_SPIWIFI_RESET, (SerialUSB.rts() == 1) ? LOW : HIGH);
55+
#else
56+
digitalWrite(NINA_RESETN, SerialUSB.rts());
57+
#endif
58+
rts = SerialUSB.rts();
59+
}
3560

36-
while (SerialUSB.available()) {
37-
uint8_t c = SerialUSB.read();
38-
SerialNina.write(c);
61+
if (dtr != SerialUSB.dtr()) {
62+
#ifdef ARDUINO_SAMD_MKRVIDOR4000
63+
FPGA.digitalWrite(FPGA_NINA_GPIO0, (SerialUSB.dtr() == 1) ? HIGH : LOW);
64+
#else
65+
digitalWrite(NINA_GPIO0, (SerialUSB.dtr() == 0) ? HIGH : LOW);
66+
#endif
67+
dtr = SerialUSB.dtr();
3968
}
4069

41-
while (SerialNina.available()) {
42-
uint8_t c = SerialNina.read();
43-
SerialUSB.write(c);
70+
if (SerialUSB.available()) {
71+
SerialNina.write(SerialUSB.read());
72+
}
73+
74+
if (SerialNina.available()) {
75+
SerialUSB.write(SerialNina.read());
4476
}
4577

4678
// check if the USB virtual serial wants a new baud rate
4779
if (SerialUSB.baud() != baud) {
80+
rts = -1;
81+
dtr = -1;
82+
4883
baud = SerialUSB.baud();
84+
#ifndef ARDUINO_SAMD_MKRVIDOR4000
4985
SerialNina.begin(baud);
86+
#endif
5087
}
5188
}

0 commit comments

Comments
 (0)