Skip to content

Commit

Permalink
0.2.rev.A. Fix program routine
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonsmartins committed Jan 25, 2024
1 parent 0567017 commit 0d69c75
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 37 deletions.
56 changes: 31 additions & 25 deletions firmware/usbflashprog/modules/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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_();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions software/usbflashprog/backend/devices/parallel/eprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 14 additions & 9 deletions software/usbflashprog/backend/devices/parallel/pdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,27 +340,32 @@ 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")
.arg(current, 6, 16, QChar('0'))
.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;
Expand Down
1 change: 1 addition & 0 deletions software/usbflashprog/backend/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ bool Runner::deviceSetupBus(kCmdDeviceOperationEnum operation) {
TRunnerCommand cmd;
cmd.setByte(kCmdDeviceSetupBus, operation);
if (!sendCommand_(cmd)) return false;
address_ = 0;
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions software/usbflashprog/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -4212,13 +4212,13 @@ Wr</string>
</action>
<action name="actionEPROMW27_32KB">
<property name="text">
<string notr="true">EPROM W27x256</string>
<string notr="true">EPROM W27x256/257</string>
</property>
<property name="iconText">
<string notr="true">EPROM W27x256</string>
<string notr="true">EPROM W27x256/257</string>
</property>
<property name="toolTip">
<string notr="true">EPROM W27x256</string>
<string notr="true">EPROM W27x256/257</string>
</property>
</action>
<action name="actionEPROMW27_64KB">
Expand Down

0 comments on commit 0d69c75

Please sign in to comment.