From 7ae56c57469c6347cf82e21675e272dd946486c5 Mon Sep 17 00:00:00 2001 From: Robson Martins Date: Wed, 24 Jan 2024 17:22:21 -0300 Subject: [PATCH] 0.2.rev.A. Fix program routine --- firmware/usbflashprog/modules/runner.cpp | 56 ++++++++++--------- .../backend/devices/parallel/eprom.cpp | 2 + .../backend/devices/parallel/pdevice.cpp | 23 +++++--- software/usbflashprog/backend/runner.cpp | 1 + software/usbflashprog/ui/mainwindow.ui | 6 +- 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/firmware/usbflashprog/modules/runner.cpp b/firmware/usbflashprog/modules/runner.cpp index 9b471a9a..eb81abd2 100644 --- a/firmware/usbflashprog/modules/runner.cpp +++ b/firmware/usbflashprog/modules/runner.cpp @@ -157,17 +157,17 @@ void Runner::runVddCommand_(uint8_t opcode) { TByteArray response; switch (opcode) { case kCmdVddCtrl: + serial_.putChar(kCmdResponseOk, true); if (getParamAsBool_()) { vgen_.vdd.on(); } else { vgen_.vdd.off(); } - serial_.putChar(kCmdResponseOk); break; case kCmdVddSetV: + serial_.putChar(kCmdResponseOk, true); v = getParamAsFloat_(); vgen_.vdd.setV(v); - serial_.putChar(kCmdResponseOk); break; case kCmdVddGetV: v = vgen_.vdd.getV(); @@ -191,20 +191,20 @@ void Runner::runVddCommand_(uint8_t opcode) { serial_.putBuf(response.data(), response.size()); break; case kCmdVddInitCal: + serial_.putChar(kCmdResponseOk, true); vgen_.vdd.initCalibration(); - serial_.putChar(kCmdResponseOk); break; case kCmdVddSaveCal: - v = getParamAsFloat_(); serial_.putChar(kCmdResponseOk, true); + v = getParamAsFloat_(); vgen_.vdd.saveCalibration(v); vgen_.vdd.setV(kVddInitial); sleep_ms(1); // 1 ms break; case kCmdVddOnVpp: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vdd.onVpp(b); - serial_.putChar(kCmdResponseOk); break; default: break; @@ -217,17 +217,17 @@ void Runner::runVppCommand_(uint8_t opcode) { TByteArray response; switch (opcode) { case kCmdVppCtrl: + serial_.putChar(kCmdResponseOk, true); if (getParamAsBool_()) { vgen_.vpp.on(); } else { vgen_.vpp.off(); } - serial_.putChar(kCmdResponseOk); break; case kCmdVppSetV: + serial_.putChar(kCmdResponseOk, true); v = getParamAsFloat_(); vgen_.vpp.setV(v); - serial_.putChar(kCmdResponseOk); break; case kCmdVppGetV: v = vgen_.vpp.getV(); @@ -251,40 +251,40 @@ void Runner::runVppCommand_(uint8_t opcode) { serial_.putBuf(response.data(), response.size()); break; case kCmdVppInitCal: + serial_.putChar(kCmdResponseOk, true); vgen_.vpp.initCalibration(); - serial_.putChar(kCmdResponseOk); break; case kCmdVppSaveCal: - v = getParamAsFloat_(); serial_.putChar(kCmdResponseOk, true); + v = getParamAsFloat_(); vgen_.vpp.saveCalibration(v); vgen_.vpp.setV(kVppInitial); sleep_ms(1); // 1 ms break; case kCmdVppOnA9: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vpp.onA9(b); - serial_.putChar(kCmdResponseOk); break; case kCmdVppOnA18: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vpp.onA18(b); - serial_.putChar(kCmdResponseOk); break; case kCmdVppOnCE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vpp.onCE(b); - serial_.putChar(kCmdResponseOk); break; case kCmdVppOnOE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vpp.onOE(b); - serial_.putChar(kCmdResponseOk); break; case kCmdVppOnWE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); vgen_.vpp.onWE(b); - serial_.putChar(kCmdResponseOk); break; default: break; @@ -295,19 +295,19 @@ void Runner::runCtrlBusCommand_(uint8_t opcode) { bool b; switch (opcode) { case kCmdBusCE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); ctrlBus_.setCE(b); - serial_.putChar(kCmdResponseOk); break; case kCmdBusOE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); ctrlBus_.setOE(b); - serial_.putChar(kCmdResponseOk); break; case kCmdBusWE: + serial_.putChar(kCmdResponseOk, true); b = getParamAsBool_(); ctrlBus_.setWE(b); - serial_.putChar(kCmdResponseOk); break; default: break; @@ -410,16 +410,17 @@ void Runner::runDeviceSettingsCommand_(uint8_t opcode) { uint32_t dw; switch (opcode) { case kCmdDeviceSetTwp: + serial_.putChar(kCmdResponseOk, true); dw = getParamAsDWord_(); settings_.twp = dw; - serial_.putChar(kCmdResponseOk); break; case kCmdDeviceSetTwc: + serial_.putChar(kCmdResponseOk, true); dw = getParamAsDWord_(); settings_.twc = dw; - serial_.putChar(kCmdResponseOk); break; case kCmdDeviceSetFlags: + serial_.putChar(kCmdResponseOk, true); dw = getParamAsByte_(); // 0 = Skip Write 0xFF // 1 = Prog with VPP on @@ -433,7 +434,6 @@ void Runner::runDeviceSettingsCommand_(uint8_t opcode) { settings_.pgmCePin = (dw & 0x08) != 0; settings_.pgmPositive = (dw & 0x10) != 0; // clang-format on - serial_.putChar(kCmdResponseOk); break; case kCmdDeviceSetupBus: dw = getParamAsByte_(); @@ -583,7 +583,6 @@ bool Runner::deviceWrite_(uint16_t &data, bool is16bit) { // VPP on vgen_.vdd.onVpp(false); vgen_.vpp.on(); - sleep_us(kStabilizationTime); } // Set DataBus if (is16bit) { @@ -611,7 +610,6 @@ bool Runner::deviceWrite_(uint16_t &data, bool is16bit) { // VPP off vgen_.vpp.off(); vgen_.vdd.onVpp(true); - sleep_us(kStabilizationTime); } return success; } @@ -644,7 +642,7 @@ bool Runner::deviceWriteAndVerify_(uint16_t &data, bool is16bit) { emptyData = (wr == 0xFFFF); } else { wr = getParamAsByte_(); - emptyData = (wr & 0xFF == 0xFF); + emptyData = ((wr & 0xFF) == 0xFF); } // write if (!settings_.skipFF || !emptyData) { @@ -654,11 +652,13 @@ bool Runner::deviceWriteAndVerify_(uint16_t &data, bool is16bit) { if (settings_.pgmCePin) ctrlBus_.setWE(true); // read deviceRead_(rd, is16bit); + // PGM/~CE is HI + if (settings_.pgmCePin) ctrlBus_.setWE(false); + // verify if (!is16bit) { wr &= 0xFF; rd &= 0xFF; } - // verify if (rd == wr) data = rd; return (rd == wr); } @@ -712,6 +712,10 @@ bool Runner::deviceSetupBus_(uint8_t operation) { case kCmdDeviceOperationProg: // VDD Wr on vgen_.vdd.on(); + if (settings_.vppOePin) { + // VDD Wr on VPP + vgen_.vdd.onVpp(true); + } if (settings_.pgmPositive) { // PGM is LO ctrlBus_.setWE(true); @@ -769,10 +773,12 @@ bool Runner::deviceGetId_(uint16_t &data) { uint16_t rd1 = 0xFF, rd2 = 0xFF; // Set Address 0x200 (A9 bit on) if (!addrBus_.writeDWord(0x200)) success = false; - // Check if equals data at address 0x200/0x201 + // Read Data at Address 0x200 deviceRead_(rd1, false); + // Read Data at Address 0x201 if (!addrBus_.increment()) success = false; deviceRead_(rd2, false); + // Check if equals data at address 0x200/0x201 if ((rd1 & 0xFF) == manufacturer && (rd2 & 0xFF) == device) success = false; // If success, return data diff --git a/software/usbflashprog/backend/devices/parallel/eprom.cpp b/software/usbflashprog/backend/devices/parallel/eprom.cpp index 5ec8defa..2a2ec881 100644 --- a/software/usbflashprog/backend/devices/parallel/eprom.cpp +++ b/software/usbflashprog/backend/devices/parallel/eprom.cpp @@ -141,6 +141,8 @@ EPROM27C16Bit::~EPROM27C16Bit() {} EPROM27E::EPROM27E(QObject *parent) : EPROM27C(parent) { info_.name = "EPROM W27C/27E/27SF"; info_.capability.hasErase = true; + info_.capability.hasFastProg = true; + fastProg_ = true; twp_ = 100; twc_ = 15; vddRd_ = 5.0f; diff --git a/software/usbflashprog/backend/devices/parallel/pdevice.cpp b/software/usbflashprog/backend/devices/parallel/pdevice.cpp index 10aa2a5a..24ca21f8 100644 --- a/software/usbflashprog/backend/devices/parallel/pdevice.cpp +++ b/software/usbflashprog/backend/devices/parallel/pdevice.cpp @@ -340,6 +340,8 @@ bool ParDevice::eraseDevice() { bool success = true; if (!runner_.deviceErase()) success = false; for (current = 0; current < total; current++) { + if (current % 0x100 == 0) emit onProgress(current, total); + runner_.processEvents(); if (canceling_) { emit onProgress(current, total, true, false, true); DEBUG << QString("Erase canceled at 0x%1 of 0x%2") @@ -347,20 +349,23 @@ bool ParDevice::eraseDevice() { .arg(total, 6, 16, QChar('0')); return false; } - // Verify data - if (success && !verifyData_(empty)) { - success = false; + // Verify data, if not in Fast Erase mode + if (!fastProg_) { + if (success && !verifyData_(empty)) { + success = false; + } } if (success && runner_.hasError()) success = false; + if (fastProg_ && success) break; if (!success && j == maxAttemptsProg_) { // Error emit onProgress(current, total, true, false); - WARNING - << QString( - "Erase error at 0x%1 of 0x%2. Expected data 0x%3") - .arg(current, 6, 16, QChar('0')) - .arg(total, 6, 16, QChar('0')) - .arg(empty, is16bit_ ? 4 : 2, 16, QChar('0')); + WARNING << QString( + "Erase error at 0x%1 of 0x%2. Expected data " + "0x%3") + .arg(current, 6, 16, QChar('0')) + .arg(total, 6, 16, QChar('0')) + .arg(empty, is16bit_ ? 4 : 2, 16, QChar('0')); return false; } if (!success) break; diff --git a/software/usbflashprog/backend/runner.cpp b/software/usbflashprog/backend/runner.cpp index 7985c7c8..b4282c71 100644 --- a/software/usbflashprog/backend/runner.cpp +++ b/software/usbflashprog/backend/runner.cpp @@ -529,6 +529,7 @@ bool Runner::deviceSetupBus(kCmdDeviceOperationEnum operation) { TRunnerCommand cmd; cmd.setByte(kCmdDeviceSetupBus, operation); if (!sendCommand_(cmd)) return false; + address_ = 0; return true; } diff --git a/software/usbflashprog/ui/mainwindow.ui b/software/usbflashprog/ui/mainwindow.ui index 6d77e9da..0c8f58d7 100644 --- a/software/usbflashprog/ui/mainwindow.ui +++ b/software/usbflashprog/ui/mainwindow.ui @@ -4212,13 +4212,13 @@ Wr - EPROM W27x256 + EPROM W27x256/257 - EPROM W27x256 + EPROM W27x256/257 - EPROM W27x256 + EPROM W27x256/257