-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathESP32programmer.ino
64 lines (55 loc) · 1.9 KB
/
ESP32programmer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "ESPSerialFlasher.h"//my fork https://github.com/krdarrah/ESPSerialFlasher
#include <SPI.h>
#include "SD.h"
const int SD_CS_pin = 25;
const int startProgramming_pin = 21;
const int En3VPin = 14;
unsigned long greenLEDstartTime;
//the 4 files we're looking for must contain these keywords in the title
const char bootKey[] = "boot_app";
const char bootloaderKey[] = "bootloader";
const char partitionsKey[] = "partitions";
const char firmwareKey[] = ".ino.bin";//when you flash over USB, it looks like this
const char firmwareSecondKey[] = "esp32.bin";//when you export compiled binary, this is the file it generates
const char SPIFFSKey[] = "spiffs.bin";///Users/kevindarrah/Library/Arduino15/packages/esp32/tools/esptool_py/3.0.0/esptool --chip esp32 --port /dev/cu.usbserial-DA00XJ7V --baud 230400 read_flash 0x3D0000 0x30000 spiffs.bin
boolean flashSPIFFS = false;//that way we only flash if present on card
const char hiddenFileKey[] = "/._";//on mac, we may find duplicates that start with this, so we filter out
//these title names will be stored here
char bootName[100] = {NULL};
char bootloaderName[100] = {NULL};
char partitionsName[100] = {NULL};
char firmwareName[100] = {NULL};
char spiffsName[100] = {NULL};
SPIClass spiSD(VSPI);
void initSDcard();
bool startFlashing();
void getFileNames();
void setup() {
Serial.begin(115200);
delay(2000);
redLED(true);
initSDcard();
pinMode(startProgramming_pin, INPUT_PULLUP);
pinMode(En3VPin, OUTPUT);
digitalWrite(En3VPin, HIGH);
redLED(false);
}
void loop() {
if (millis() - greenLEDstartTime > 500) {
greenLEDstartTime = millis();
greenLEDflash();
}
if (!digitalRead(startProgramming_pin)) {
if (!startFlashing()) {
digitalWrite(En3VPin, LOW);
while (1) {
greenLED(false);
yelLED(false);
redLED(true);
}
}
digitalWrite(En3VPin, LOW);
delay(1000);
digitalWrite(En3VPin, HIGH);
}
}