firmware: v9 — fix watchdog ESP32 + mitigacion glitch motor OTA

ESP32-CAM:
- handshakeTask() corre ahora en tarea FreeRTOS separada.
  setup() termina de inmediato, el servidor web arranca sin bloqueos.
  El watchdog de hardware ya no puede dispararse (antes setup()
  bloqueaba hasta 30s con readStringUntil que no cedia el CPU).

ESP8266:
- Antes del flash OTA, fuerza ENA=ENB=0 e IN1-IN4=LOW para reducir
  el glitch de pines GPIO durante el proceso de escritura en flash.
  (La solucion definitiva es resistencias pull-down en ENA/ENB.)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Natxo1000
2026-06-02 14:35:15 +02:00
parent 7707953d4d
commit e02a805aa3
6 changed files with 28 additions and 17 deletions

View File

@@ -7,7 +7,7 @@
// ================================================================
// OTA CONFIG
// ================================================================
#define FW_VERSION 8
#define FW_VERSION 9
#define GITEA_HOST "https://git.nacho.myds.me"
#define GITEA_OWNER "Natxo"
#define GITEA_REPO "Arduino-Car"
@@ -86,6 +86,11 @@ static void checkOTA() {
}
delay(300);
// Fuerza pines de motor a LOW antes del flash para minimizar glitch de GPIO
analogWrite(ENA, 0); analogWrite(ENB, 0);
digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
BearSSL::WiFiClientSecure updateClient;
updateClient.setInsecure();
ESPhttpUpdate.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);

View File

@@ -10,7 +10,7 @@
// ================================================================
// OTA CONFIG
// ================================================================
#define FW_VERSION 8
#define FW_VERSION 9
#define GITEA_HOST "https://git.nacho.myds.me"
#define GITEA_OWNER "Natxo"
#define GITEA_REPO "Arduino-Car"
@@ -24,24 +24,30 @@ const char *password = "Suprak1llm1ndS23S";
void startCameraServer();
void setupLedFlash();
// ── Handshake bidireccional con ESP8266 ────────────────────────
// Envía "GO\n" cada 300ms hasta recibir "OK\n".
// Protege contra basura del bootloader ROM (115200 baud → bytes aleatorios).
static void handshakeEsp8266() {
unsigned long deadline = millis() + 30000UL; // máx 30s
// ── Handshake bidireccional — tarea FreeRTOS (no bloquea setup)
// Corre en paralelo con el servidor web. Envía "GO\n" cada 300ms
// hasta recibir "OK\n" o agotar 30s.
static void handshakeTask(void *) {
unsigned long deadline = millis() + 30000UL;
String buf = "";
while (millis() < deadline) {
Serial.print("GO\n");
unsigned long t = millis();
while (millis() - t < 300) {
if (Serial.available()) {
String resp = Serial.readStringUntil('\n');
resp.trim();
if (resp == "OK") return;
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
buf.trim();
if (buf == "OK") { vTaskDelete(NULL); return; }
buf = "";
} else if (c != '\r' && buf.length() < 8) {
buf += c;
}
}
delay(5);
vTaskDelay(pdMS_TO_TICKS(5));
}
}
// Timeout: continúa sin confirmación
vTaskDelete(NULL); // timeout
}
// ── OTA: comprueba si hay firmware nuevo y actualiza si hace falta ──
@@ -167,8 +173,8 @@ void setup() {
// ── Servidor cámara ───────────────────────────────────────────────
startCameraServer();
// Handshake bidireccional: espera ACK del ESP8266
handshakeEsp8266();
// Handshake en tarea separada — no bloquea setup() ni el watchdog
xTaskCreate(handshakeTask, "handshake", 4096, NULL, 1, NULL);
}
void loop() {

Binary file not shown.

View File

@@ -1 +1 @@
8
9

Binary file not shown.

View File

@@ -1 +1 @@
8
9