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
2432ESP32BootROMClass::ESP32BootROMClass (HardwareSerial& serial, int gpio0Pin, int resetnPin) :
@@ -30,7 +38,25 @@ ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int r
3038}
3139
3240int 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
215248int ESP32BootROMClass::response (int opcode, unsigned int timeout, void * body)
0 commit comments