Skip to content

Instantly share code, notes, and snippets.

@rocketjosh
Forked from morganrallen/history.md
Last active March 7, 2017 01:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rocketjosh/ca4e664fbbca3a8afff995a9c91f2f8f to your computer and use it in GitHub Desktop.
Macchina M2-B Hacking Notes

cli history

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 ~/devel/ESP32/esp-idf/examples/bluetooth/gatt_server/build/gatt_server_demos.bin
#include <OBD2.h>
#include <DueTimer.h>
#include "SamNonDuePin.h"
const int XB_nRST = X4;
const int XB_GPIO0 = 29; // GPIO0 is on Pin 7 of XBee header and to PD6 of micro and mapped to pin 29
const int LED_YELLOW = X0;
void setup()
{
SerialUSB.begin(234000);
Serial.begin(115200);
SerialUSB.println(printf("System Reset"));
SerialUSB.println("> ");
pinModeNonDue(XB_nRST, OUTPUT);
pinMode(XB_GPIO0, OUTPUT);
digitalWriteNonDue(XB_nRST, HIGH);
digitalWrite(XB_GPIO0, HIGH);
pinModeNonDue(LED_YELLOW, OUTPUT);
digitalWriteNonDue(LED_YELLOW, LOW);
}
int doDelay = 0;
bool toggleBootMode = false;
bool passThrough = false;
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;
}
}
bool led = 0;
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 already in flash mode just write and stop
if(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);
digitalWrite(XB_GPIO0, LOW);
passThrough = true;
} else if(c == '\n') {
SerialUSB.print("> ");
}
}
}

ESP32

Flashing the ESP32 was the first thing needing attention. I wanted to be able to flash the device without removing it from the socket.

Pass-through flashing

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.

Steps

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment