miniterm.py `udevserial -v ID_MODEL=Arduino_Due -v SUBSYSTEM=tty` 115200 --raw
esptool32 --port `udevserial -v ID_MODEL=Arduino_Due -v SUBSYSTEM=tty` --before no_reset --after no_reset --baud 115200 write_flash 0x10000 ./build/gatt_server_demos.bin
-
-
Save morganrallen/f37145543844cd7781f4f4654d3e5132 to your computer and use it in GitHub Desktop.
#include <OBD2.h> | |
#include <DueTimer.h> | |
#include "SamNonDuePin.h" | |
bool led = 0; | |
bool toggleBootMode = false; | |
bool passThrough = false; | |
bool pipe = false; | |
const int XB_nRST = X4; | |
const int XB_GPIO0 = 56; | |
const int LED_YELLOW = X0; | |
int doDelay = 0; | |
void setup() | |
{ | |
SerialUSB.begin(234000); | |
Serial.begin(115200); | |
SerialUSB.println(printf("System Reset")); | |
SerialUSB.println("> "); | |
pinModeNonDue(XB_nRST, OUTPUT); | |
pinModeNonDue(XB_GPIO0, OUTPUT); | |
digitalWriteNonDue(XB_nRST, HIGH); | |
digitalWriteNonDue(XB_GPIO0, HIGH); | |
pinModeNonDue(LED_YELLOW, OUTPUT); | |
digitalWriteNonDue(LED_YELLOW, LOW); | |
// reboot ESP32 on startup | |
digitalWriteNonDue(XB_nRST, LOW); | |
toggleBootMode = true; | |
doDelay = 500; | |
} | |
void loop() | |
{ | |
if(doDelay > 0) { | |
SerialUSB.print("Delay: "); | |
SerialUSB.print(doDelay); | |
delay(doDelay); | |
SerialUSB.print(".\n> "); | |
doDelay = 0; | |
} | |
if(toggleBootMode) { | |
digitalWriteNonDue(XB_nRST, HIGH); | |
toggleBootMode = false; | |
} | |
} | |
void serialEvent() { | |
// 'activity' light | |
digitalWriteNonDue(LED_YELLOW, led ? HIGH : LOW); | |
led = led ? 0 : 1; | |
// Serial data from XB_ can just be passed straight through | |
while(Serial.available()) { | |
SerialUSB.write((uint8_t)Serial.read()); | |
} | |
} | |
void serialEventUSB() { | |
// 'activity' light | |
digitalWriteNonDue(LED_YELLOW, led ? HIGH : LOW); | |
led = led ? 0 : 1; | |
while(SerialUSB.available()) { | |
uint8_t c = SerialUSB.read(); | |
if(pipe && c == 0x03) { | |
pipe = false; | |
SerialUSB.println("Ending pipe"); | |
return; | |
} | |
// if already in flash mode just write and stop | |
if(pipe || passThrough) { | |
Serial.write(c); | |
return; | |
} | |
// proper data coming back from ESP32 can be passed back | |
SerialUSB.write(c); | |
// simple command set | |
// b: enter boot mode | |
// r: reset | |
// both b and r lower nRST | |
// and toggle bootmode (back up in 500ms) | |
if(c == 'b' || c == 'r') { | |
SerialUSB.println("\n\nReseting ESP32"); | |
digitalWriteNonDue(XB_nRST, LOW); | |
toggleBootMode = true; | |
doDelay = 500; | |
} | |
// b also lowers GPIO0 and enables pass-through | |
if(c == 'b') { | |
Serial.begin(234000); | |
digitalWriteNonDue(XB_GPIO0, LOW); | |
passThrough = true; | |
} else if(c == 'p') { | |
SerialUSB.println("\nPiping data to ESP32"); | |
pipe = true; | |
} else if(c == '\n') { | |
SerialUSB.print("> "); | |
} | |
} | |
} |
Flashing the ESP32 was the first thing needing attention. I wanted to be able to flash the device without removing it from the socket.
The plan. Put the ESP32 into flashmode via nRST
GPIO0
toggling. Bring
both LOW
then bring nRST
back up. Then esptool32
can be coerced into
flashing the chip. There is still a bit of manual intervention but I got
it working.
Using mac32.ino
send b
over the USB serial port to enter bootmode.
> b
Reseting ESP32
Delay: 500.
> ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x3 (DOWNLOAD_BOOT(UART0/UART1/SDIO_REI_REO_V2))
waiting for download
If using a serial terminal disconnect, there is nothing else to be done without resetting the M2.
Now you can start flashing the ESP32 with esptool32
.
The differences from normal use are the inclusion of --before no_reset
and --after no_reset
. You have to reset and re-enter bootmode for
each file being flashed, this is a shortcoming in the code at the moment.