Explorar o código

Further IST register fix

Benjamin Harris hai 1 mes
pai
achega
b3784e6a1d
Modificáronse 3 ficheiros con 36 adicións e 13 borrados
  1. 4 4
      DSPWriter.cpp
  2. 28 7
      ModulosDSP_101.ino
  3. 4 2
      index_html.h

+ 4 - 4
DSPWriter.cpp

@@ -3,6 +3,10 @@
 #include <Wire.h>
 #include "DataConversion.h"
 
+static uint8_t s_safeload_count   = 0;
+static uint8_t s_coreRegCache[2]  = {0x00, 0x00};
+static constexpr uint8_t IST_MASK = 0x3C;
+
 DSPWriter::DSPWriter() {}
 DSPWriter::~DSPWriter() {}
 
@@ -75,10 +79,6 @@ void DSPWriter::writeRegister(uint16_t memoryAddress, uint8_t length, const uint
 // instances, but exposed via resetSafeload() so the TCP bridge
 // can flush and reset cleanly on session start and disconnect.
 // ---------------------------------------------------------------
-static uint8_t s_safeload_count   = 0;
-static uint8_t s_coreRegCache[2]  = {0x00, 0x00}; // last value written to CoreRegister
-static constexpr uint8_t IST_MASK = 0x3C;          // bits to OR in to trigger safeload IST
-
 void DSPWriter::resetSafeload()
 {
     // If the session ended mid-safeload, the DSP still has its own internal

+ 28 - 7
ModulosDSP_101.ino

@@ -355,6 +355,7 @@ static volatile bool     uploadVerify = false;
 static volatile bool     uploadFailed = false;
 static volatile uint32_t uploadBytes  = 0;
 static volatile uint32_t uploadCrc    = 0;
+static char              uploadErrorMsg[80] = "";
 
 //=============================================================
 // HTTP handlers
@@ -399,7 +400,9 @@ static void handleRoot() {
 
 static void handleUploadDone() {
   if (uploadFailed) {
-    httpServer.send(500, "application/json", "{\"ok\":false}");
+    char buf[128];
+    snprintf(buf, sizeof(buf), "{\"ok\":false,\"error\":\"%s\"}", uploadErrorMsg);
+    httpServer.send(500, "application/json", buf);
     return;
   }
   char buf[80];
@@ -415,19 +418,29 @@ static void handleUploadStream() {
 
   if (up.status == UPLOAD_FILE_START) {
     uploadActive = true; uploadFailed = false; uploadBytes = 0; uploadCrc = 0;
+    uploadErrorMsg[0] = '\0';
     uploadVerify = httpServer.hasArg("verify");
     Serial.println(); Serial.print("HTTP upload start: "); Serial.println(up.filename);
     Serial.print("Verify: "); Serial.println(uploadVerify ? "yes" : "no");
     Wire.beginTransmission(EEPROM_7BIT);
-    Serial.print("EEPROM probe err: "); Serial.println(Wire.endTransmission());
+    uint8_t probeErr = Wire.endTransmission();
+    Serial.print("EEPROM probe err: "); Serial.println(probeErr);
+    if (probeErr != 0) {
+      snprintf(uploadErrorMsg, sizeof(uploadErrorMsg), "EEPROM not found (I2C err %u)", probeErr);
+      uploadFailed = true;
+    }
   }
   else if (up.status == UPLOAD_FILE_WRITE) {
     if (uploadFailed) return;
     if ((uploadBytes + up.currentSize) > EEPROM_SIZE_BYTES) {
-      Serial.println("Upload too large for 24C256"); uploadFailed = true; return;
+      snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
+               "File too large: %u bytes (max 32768)", uploadBytes + up.currentSize);
+      Serial.println(uploadErrorMsg); uploadFailed = true; return;
     }
     if (!eepromWriteBlock((uint16_t)uploadBytes, up.buf, (uint16_t)up.currentSize)) {
-      Serial.println("EEPROM write failed"); uploadFailed = true; return;
+      snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
+               "EEPROM I2C write failed at offset %u", (uint32_t)uploadBytes);
+      Serial.println(uploadErrorMsg); uploadFailed = true; return;
     }
     uploadCrc = esp_rom_crc32_le(uploadCrc, up.buf, up.currentSize);
     uploadBytes += up.currentSize;
@@ -442,12 +455,20 @@ static void handleUploadStream() {
       uint32_t remaining = uploadBytes; uint16_t addr = 0;
       while (remaining) {
         uint16_t n = remaining > sizeof(tmp) ? sizeof(tmp) : (uint16_t)remaining;
-        if (!i2cReadBlock(EEPROM_7BIT, addr, tmp, n)) { Serial.println("EEPROM read failed"); uploadFailed = true; break; }
+        if (!i2cReadBlock(EEPROM_7BIT, addr, tmp, n)) {
+          snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
+                   "EEPROM read failed at offset %u", (uint32_t)addr);
+          Serial.println(uploadErrorMsg); uploadFailed = true; break;
+        }
         crc = esp_rom_crc32_le(crc, tmp, n);
         addr += n; remaining -= n; delay(0);
       }
-      Serial.print("Verify CRC32: 0x"); Serial.println(crc, HEX);
-      if (!uploadFailed && crc != uploadCrc) { Serial.println("CRC mismatch"); uploadFailed = true; }
+      Serial.printf("Verify CRC32: wrote=0x%08X read=0x%08X\n", (uint32_t)uploadCrc, crc);
+      if (!uploadFailed && crc != uploadCrc) {
+        snprintf(uploadErrorMsg, sizeof(uploadErrorMsg),
+                 "CRC mismatch: wrote 0x%08X, read 0x%08X", (uint32_t)uploadCrc, crc);
+        Serial.println(uploadErrorMsg); uploadFailed = true;
+      }
     }
     uploadActive = false; ledOff();
     Serial.println(uploadFailed ? "HTTP upload result: FAIL" : "HTTP upload result: OK");

+ 4 - 2
index_html.h

@@ -395,10 +395,12 @@ function doUpload(blob, name) {
         div.innerHTML = '<div class="alert alert-success mb-0"><i class="fa fa-check-circle"></i> Upload complete.</div>';
       }
     } else {
+      var reason = '';
+      try { var d = JSON.parse(xhr.responseText); if (d.error) reason = d.error; } catch(e) {}
       div.innerHTML =
         '<div class="alert alert-danger mb-0">' +
-        '<strong><i class="fa fa-times-circle"></i> Upload failed</strong><br>' +
-        '<span class="small text-muted">Check the Serial monitor for details.</span>' +
+        '<strong><i class="fa fa-times-circle"></i> Upload failed</strong>' +
+        (reason ? '<br><span class="small"><code>' + reason + '</code></span>' : '') +
         '</div>';
     }
   };