Răsfoiți Sursa

EEPROM verify improvments

Benjamin Harris 1 lună în urmă
părinte
comite
12eaea5b96
1 a modificat fișierele cu 3 adăugiri și 17 ștergeri
  1. 3 17
      ModulosDSP_101.ino

+ 3 - 17
ModulosDSP_101.ino

@@ -13,6 +13,7 @@
 #include <LittleFS.h>
 #include <Update.h>
 #include <ESPmDNS.h>
+#include "esp_rom_crc.h"
 
 //=============================================================
 // WiFi / UI
@@ -119,21 +120,6 @@ static constexpr uint32_t EEPROM_SIZE_BYTES   = 32768;
 static constexpr uint16_t EEPROM_PAGE_SIZE    = 64;
 static constexpr uint8_t  I2C_MAX_DATA_PER_TX = 28;
 
-//=============================================================
-// CRC32
-//=============================================================
-static uint32_t crc32_update(uint32_t crc, const uint8_t* data, size_t len)
-{
-  crc = ~crc;
-  for (size_t i = 0; i < len; i++) {
-    crc ^= data[i];
-    for (int b = 0; b < 8; b++) {
-      uint32_t mask = -(crc & 1u);
-      crc = (crc >> 1) ^ (0xEDB88320u & mask);
-    }
-  }
-  return ~crc;
-}
 
 //=============================================================
 // Helpers
@@ -448,7 +434,7 @@ static void handleUploadStream() {
     if (!eepromWriteBlock((uint16_t)uploadBytes, up.buf, (uint16_t)up.currentSize)) {
       Serial.println("EEPROM write failed"); uploadFailed = true; return;
     }
-    uploadCrc = crc32_update(uploadCrc, up.buf, up.currentSize);
+    uploadCrc = esp_rom_crc32_le(uploadCrc, up.buf, up.currentSize);
     uploadBytes += up.currentSize;
     ledMagenta();
   }
@@ -462,7 +448,7 @@ static void handleUploadStream() {
       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; }
-        crc = crc32_update(crc, tmp, n);
+        crc = esp_rom_crc32_le(crc, tmp, n);
         addr += n; remaining -= n; delay(0);
       }
       Serial.print("Verify CRC32: 0x"); Serial.println(crc, HEX);